Thursday, June 27, 2013

Version Control

I'm a developer of yea old ways and old days. Most of my work is in embedded systems that involve no OS at all, or contain  nothing more than a framework to start work from. To make things a bit more chaotic, a lot of my work also involves designing hardware as well as writing appropriate firmware for the hardware that has been designed.
My firmware workflow is more or less set, if the firmware is being written from scratch. It basically involves writing hardware test modules, then laying down the final applications's foundation and then to integrate low level code in the foundation.
Once the low level code starts living together, it boils down to writing higher up interfaces to correctly implement the required functionality. Now, when I am writing so much of code (smallest project being a few hundred lines of assembly code, largest one being few thousand lines of C code) there was always a need of keeping a track of what I have done and when code broke, be able to revert back to the older working version.
In my initiate days (like 15 years ago), I had set up a simple system for backing up my code and maintaining a proper track of changes made etc. Since I was a lone developer on every one of my project modules, this way worked very well, and I never felt real need to start learning any of the fancier VCS implementations like SVN or CVS etc.
However, for the last few years or so, my projects are becoming bigger and there is now need to follow/track/revert/etc. changes made to my hardware designs as well as to my firmware. And to top it off, I have learnt to program in Python and WxPython and now some of my works also involve GUI/Non-GUI applications written in Python. And of course my simple system started showing cracks. Some of these cracks were simply my laziness (:P) and some of them were simply because I am not a thinker with lot of foresight (Hmmmm, maybe I shouldn't admit this in writing!)

So I finally put up SVN (TortoiseSVN, on Windows, because most of my other, software was on Windows). Unfortunately, probably because of my lack of clarity of concepts, I failed to make SVN fit to my workflow! That is when I came across an article by Joel Spolsky (
introducing Mercurial.
And in two days time, I was able to wrap almost all (95%) of my workflow in Mercurial. And on top of that I found out that I was able to wrap the remaining workflow (5%) around Mercurial. Today I am a happy user of the excellent tool. I use TortoiseHg ( on Windows 7, and am able to track/revert/follow everything that I do. Including my hardware designs, todos and code!
This is not going to be a Hg tutorial, because there are more than few resources that teach Hg to even a log! The resources that were useful to me were:

Tri-State!D-Uh, what's that?

During the last ten years or so, I've interfaced with literally thousands of students, usually in their last year of engineering or Master's degree program in some college and other, usually in electronics or instrumentation.
What I found surprising was that more than 80% of these students simply had no concrete idea about what Tri-State is about. I think, that I have a reasonable idea about what tri-state is, and I'll get some of my thoughts across.

To begin with let us talk about digital logic. By definition digital logic devices (gates,flip flops etc.) will give only one of the two voltage levels as output. A Logic Zero (Usually within few millivolts of the GND reference terminal, dependent upon how much current is being sunk into the output), and a Logic One (Usually within few millivolts of the VDD reference terminal, dependent upon how much current is being pulled from it).

A typical logic output structure (TTL) looks like the figure 1. TTL stands for Transistor-Transistor Logic and usually is run from a 5V (+/- 5%) supply voltage. This figure of course does not depict a full TTL stage but is good enough for our discussion.

When the output is Logic One, the upper transistor is On, presenting a low resistance path to +5V, and when output is Logic Zero, the lower transistor is On, presenting a low resistance to GND. The logic block driving the transistors makes sure that both transistors NEVER turn on simultaneously. If they were to turn on together the +5V supply would effectively be shorted to ground through a small resistance, and the resulting current would destroy the output stage.

Figure 1

Now, if an additional transistor were added, like in the Figure 2, and if both inputs to the output stage were

pulled low by turning on the extra transistor added at the bottom, then both the output stage transistors will be in the OFF state, irrespective of the inputs presented to the logic block.
Since both transistors are in the OFF state, they would end up presenting a very large resistance (impedance!) to both ground as well as the supply rail. Under this circumstance, if an external voltage (0 < Vext < Vsupply) were inserted on the Vout pin, it would not matter.
Under this condition the output of our logic device is in a high impedance state. This is called tri-state.

A practical application of tri-state is that it allows many logic gate outputs to be connected to the same bus, and then by enabling only one gate at a time, keeping other outputs in tri-state, it is possible to poll many outputs. Read up on 74LS125 to get an idea. The same technique is used to tri-state data bus outputs in many parallel interface chips (e.g. the 74xx245 bus driver or 64256 like SRAM chips, LCDs etc.)

A quick way to check tri-state is to measure the voltage at output of a logic gate with a simple DMM. The high impedance of the transistors will effectively form a voltage divider (loaded to a small extent by the DMM's input impedance) and would end up showing a voltage approximately half of supply voltage.
This test can fail sometimes, if there are leakage paths available on the board. The leakage paths will end up providing enough current to either pull-up or pull-down the output of the gate. Under these circumstances, simply touch the DMM probe (the one that is put on the Vout node) with your finger. If the voltage changes then the output is almost guaranteed to be in tri-state.
This trick will NOT work very well if there are low value (< 10k) pull up resistors connected on the pins, or if there are other devices connected to the same output that might drive the output to some specific voltage.

If you find any obvious mistakes in what I have written here please do get back and bite, so I can correct those mistakes.

Eh! Back me am!

Hopefully, I will be able to keep my promise of blogging more, this time around! Let's see what has happened with me in the last year and half (since my last blog)! In a chronologically random order :P and obviously not complete!

1) I delivered some training kits to CCOEW.
    USB powered, 8051, Parallel ADC/DAC, LCD, 7 segment, Serial ADC/DAC/EEPROM/RTC,
    Keyboard, a test program in assembly that made me feel good about myself.
2) I had to restart programming on lower end PIC micro-controllers (Yuck)
    How can a company manufacture a 8 pin micro-controller that costs @50/- per unit, and NOT give it at
    least one hardware PWM channel, is beyond me!
3) Read Inferno by Dan Brown.
    Another Robert Langdon novel with a storyline similar to Arun Shari's old novel in Marathi (from like
   1975) but with a very unexpected and welcome twist at the end. Loved it. After reading through trash like
   Digital Fortress and Deception Point (Both by Dan Brown) felt good to know that he can still write pretty

Oh my god! I am boring people with random bits and pieces of my life. That is sick. Yuck.
Next thing you know I will be detailing about what colour shirts I am wearing and asking for opinions!

Maybe people will be more interested in technical stuff that I do sometimes?

I recently  completed testing a spark arc based ozone generator. Uses a Tiny44 controller to drive a small 12V compressor and a HV spark gap drive mechanism (18kV output into a 10mm gap) that generates a continuous spark in a glass tube. The compressor drives air over the spark allowing ozone generation by the UV generated in the spark. Let's see if I can somehow make this into a more commercial product.

Also worked on a LVDT drive circuit recently, that used a completely analog solution, for generating the sine wave (using a Wein bridge oscillator) at 1kHz and synchronous rectification and phase detection that eventually generated 0 to 2V for a 2mm stroke length. The guy who was into manufacturing the circuit had major temperature related issues in the oscillator (sudden shutdowns, frequency drifts, changes in distortion levels and so on so forth).
We tried to temperature stabilize the oscillator gain with a appropriate temperature varying resistive element in the feedback (a tungsten lamp :P). The idea did work, but then there were start-up problems and peak oscillator output related issues.
So I ventured ahead with a simple sine-pwm scheme that used a ATTiny45, running it's output PWM at 100kHz, at 8 bit resolution (Yep, the controller does do that with it's internal PLL etc. etc.) generated a looked up pwm to get a nice low distortion sine wave. And since the person in question has not come back screaming after selling a number of units, I think it is still working. I'll put up all the relevant details soon.

I used LibreOffice Calc to generate the lookup table. Dumped the generated file to a CSV output file. And then generated the output include file (C format, avr-gcc) using a small Python script that used the csv file as input. The Python script was used primarily to arrange the file in a readable form and to make it look nice, put commas and brackets at required places, insert newlines and few comments as seemed appropriate.
Python was an overkill frankly, because the same same task can be done equally well in AWK and in fact even in SeD. But I know both AWK and SeD pretty well, I don't know Python that well and was trying to learn it.

Anyway, now I am working on a KiCAD tutorial as part of the presentation I am to give in my drive to Corrupt Young Minds (with ideas like design your own PCBs instead of paying enormous sums to outsiders, draw neat schematics instead of hand drawn scrawls and similar stuff). I will be posting the tutorial here on the blog as well by end of July first week, sometime.

Sunday, November 7, 2010

Thank god I don't blog to earn money, I'd be piss poor by now. Jokes apart, I really should stick to my threats and blog more.
Today for some reason or other, I feel like gushing on and on about various technical things that I do, tools that I use. Instead of overloading myself by writing about everything in one go, I'll start a step by step description of various tools that I use. Usually, as an electronics design engineer, involved in both analog as well as digital designs (no DSP for me, though) I require good schematic editing and PCB designing tools.
Since I ain't rich and have to pay for all the tools I use from my own pocket, my inclination is towards using good and free to use tools that provide open file formats (preferred not mandatory), frequent updates and those which are functionally stable for at least six months or more.
The tools that I have found invaluable till now are:
  • KiCAD : Schematic and PCB (Linux and Windows)
  • PCB : PCB design (Linux and Windows)
  • AVRGCC : C tool chain for AVR micro-controllers (Linux and Windows)
  • SDCC : C compiler for MCS-51 series micro-controllers (Linux and Windows)
  • SimAVR : AVR Simulator (Linux)
  • AVR Studio : AVR tools from Atmel (Windows)
  • MSPGCC : C tool chain for MSP430 family of controllers (Linux and Windows)
  • QCAD : A reasonably priced, well featured 2D CAD software (Linux and Windows)
  • Programmer's Notepad : Good IDE for small projects (Windows)
  • CodeBlocks : A full featured IDE for (everything?, Linux and Windows)
  • ASM51 : MCS-51 family assembler (DOS)
  • GAVRASM : AVR Assembler (Linux and Windows)
  • ASEM : MCS-51 Assembler (Linux)
  • OpenOffice Draw : I use it for drawing flowcharts
  • AVRDude and AVR-Burn-O-Mat : AVR ISP programming
  • Flashmagic : ISP software for NXP controllers (Windows only)
  • FLIP : ISP Software for Atmel controllers (Linux and Windows)
Well, the list above looks rather mis-arranged. I'll get down to it in a couple of days and arrange it based on functionality or Operating Systems. As of right now my intention is to provide a small article on each of these tools.
But since I am a terribly lazy person, don't hold your breath for me to publish these articles. I will definitely write them within upcoming two month's time. Till then feel free to email me with any problems that you might have run into, with these tools. If you have reached this blog, you probably know my email id. Its

Cyao people.

Sunday, January 17, 2010

Hey!!! I am blogging.

This is my first blog entry. And being that it's gonna be pretty boring one at that. I have been struggling, thinking, re-thinking and re-re-thinking (contemplating, one might say) about creating my own blog.
After four years of serious contemplation here I am blogging. The problem with me was that I had no idea what I should blog about. Apparently, contrary to my own belief, things that happen in daily life are worth blogging about. At least that is what some of my friends have convinced me of.

Let's see, what would I like to to tell the world today? Nothing comes to mind, except maybe recent movie that I saw called "3 idiots". This is what I thought about it (an amateur movie appreciator's handiwork)

Chetan Bhagat's book and the movie:
Barely 10% of it is based on Chetan Bhagat's "Five Point Someone". So he should probably stop screaming (hey, he already stopped)
The twist about Rancho is good, though there are times when the movie is entirely predictable. (Like Lobo's suicide)
Good. Couldn't find explicit problems with continuity or other mix-ups. Did think once or twice that Mr. Lobo (The suicide guy) re-appears in one or two scenes, but maybe I just had too much grass. :D
Sharman Joshi Rocks, Ameer Khan never did not rock, R. Madhawan is what he is, cool and dandy in the movie. Kareens Kapoor looks good but the role doesn't use any of her acting skills (yeah she has them, check out Chameli and then Jab We Met one after the other, a lot of dynamic range).
Delivered very well, without boring anyone. The movie can be watched and enjoyed without getting the message at all!!! And for those who understand the message, the movie means so much more.
Best liked characters:
Omi, in his role as Silencer. Boman Irani, in his role as Virus.
WTF, I didn't like the others (wait, don't kill me yet, don't call the hired guns).
Ameer, Sharman,Madhawan are central characters. They WILL be remembered anyway. Omi however carries out the pompous, egoistic bearing to its fullest during the scene when the three guys enter Rancho's home and find that Rancho's father (the real Rancho's father) has died.
is Boman Irani, how can I not like him. Come on, now.

Oh my god, I wrote so much without even realizing that I am at office and should be working. So will write again. Maybe about my most recently finished novel.

And my friends (who convinced me to write) beware, for I will now be asking you over and over and over and over if you read what I wrote and what do you think of it.

Cyao somewhen.