Wednesday, July 29, 2009

Uno Sensor Board Update

I worked on my sensor board again tonight. I got the sensor portion, as opposed to the led driver portion, working. I had to do a bit more board repair. Apparently, when I swapped the incorrectly routed op-amp outputs and power lines, I damaged a via and disconnected the forward looking opamp from the MCU. I wound up drilling out a couple vias to fix it.

Once I had it going I tried to run a simple test program to show which of the four sensors saw the greatest amount of light. For the test I just used a loose IR LED wired to be always on at about 20 mA. I have moved the code around a bit since last time I talked about it. I don't use the timer interrupts at all now. I just use the ADC conversion complete interrupt. I discovered you can configure the ADC to automatically begin a conversion based off of a number of other interrupts. So I set the ADC to trigger off of Compare Match A for Timer 1. That interrupt is the one that raises the strobe line to the LEDs to begin emitting light for 10us. However, I don't actually have to service the Compare Match A interrupt, the ADC will begin conversion regardless. Instead I can just service the conversion complete interrupt and do everything there. The timing of the conversion is such that the sample and hold should happen somewhere around 7 us into the pulse. I've yet to verify that's really what's happening on the scope however.

Anyway my test program behaved quite oddly and only the forward channel seemed to ever detect anything. After some digging I discovered that there are restrictions on changing the ADC channel while in auto-trigger mode. Two of the three times they list that its OK to change, I could not puzzle out how to get at in code. I wound up actually disabling the auto-trigger bit, a listed time to change the channel, and then reset the bit right after the channel change. That seemed to work. But, it took about more than an hour to figure out what was going on.

I'll chalk it up to a learning experience. I've explored a corner of the AVR that'd I'd never visited before and found an annoying quirk. I'll know better next time and maybe I can get someone past the quirk in the future without them having to puzzle for an hour or more.

No comments: