Wednesday, June 10, 2009

Uno V Dos Sensor Board Progress



So tonight I finally got back around to working on Uno V. Dos. The part I really wanted to get working was the multiplexer driver. The idea behind the multiplexer circuit is that the 10us pulse that happens 300 times per a second will redirected to a new IR LED bank after each pulse causing the LED banks to fire one at a time in a ring sequence. To effect that, I set my timer up to generate a 10us pulse 300 times a second on the Timer1 Output Compare A pin (OC1A). That was pretty easy and I was able to see the pulse in TomG's old but still quite capable o-scope.

The pulse goes to the enable pin of the high power 3-to-8 multiplexer chip. Each of the eight outputs goes to a different bank of LEDs. So when that pulse comes in one bank and one bank only will light up for 10 us. Exactly which bank lights up is controlled by the 3 address lines of the multiplexer. I needed to swap out those address lines shortly after the strobe pulse ended when the multiplexer would be disabled, the LEDs off and there would be a goodly wait until the next pulse.

Initially I set my Timer to Fast PWM mode with the TOP controlled by ICR1 and set to about 27,000. The compare register was set to 67. OC1A was configured to set on overflow and clear on compare match. This looked great on the scope and I didn't think I'd need touch those values again. Since OC1A was set to clear on a compare match I figured that of the several timer interrupts, the Compare A Interrupt was the right time adjust my address lines that headed to the multiplexer. Wrong.

For some reason that I still not certain of, the Compare A Interrupt does not seem to fire.  I know I had the Timer 1 Interrupt mask set properly to enable both Compare A and Overflow and I had the Global Interrupts Enabled flag set, but still no joy. Overflow Interrupt, however, worked just fine. Odd. Of course, the way the timer was configured, overflow was a terrible time to mess with the address Lines. It could result in two banks lighting up, each for some percentage of the 10 us time.

Maybe its just a quirk of Fast PWM mode, but by the time I determined that Overflow worked and Compare A didn't it was late and I didn't want to change the mode. I wound up setting the Compare Register to 27000 minus 67 and changing OC1A to clear on overflow and set on compare match. This gave me the same over all signal, it just occurred at the other end of the time period. (26933 through 27000 rather than 0 through 67) It also made overflow the correct time to change the address lines.

Above you can see a picture of my success. The top two pairs of lines are two of the three address lines. The last square wave at the bottom is the strobe pulse signal from the Output Compare pin (OC1A). The Address lines appear double because the o-scope is set to trigger on OC1A and the value of the address lines changes with each pulse. The rapid variation makes the high and the low states blur together and appear to be occurring simultaneously on the o-scope. However the code that actually changes the line first sets them all to zero so that a simple bitwise OR operation can be used to write the new line states all at once. This causes a noticeable glitch in the address line wave shape where all the lines are zero for a time. However, as you can see in the photo the glitch occurs a few microseconds after the LED strobe pulse comes down meaning the LEDs are off. So the glitch does not affect them. What the glitch does do is provide me a nice point of reference that allows me to overcome the blurring of states and confirm that the address lines are changing at the right time. It was a happy glitch to end the evening with!