Oct 27, 2011

Keeping Circuits Up When the Sun Goes Down

Temperature is one of the most often overlooked specifications in electronic design. We spend most of our time in controlled climates and it’s easy to forget that the products we create might not. The problem is that most component suppliers know this and either don’t include any data about their product over temperature or only give you their ratings at the peak conditions, i.e. the ideal temperature, voltage, light, etc. The casual electronics person/lifetime tinkerer might not even consider designing for environmental conditions because in their case they just need something that works in one specific instance. In fact, the reason I chose to write briefly on this subject is because I have been caught by temperature restrictions in the past, and I was almost caught again with my pumpkin animation project.

Last Halloween, I attempted a lamer, less thought out version of this project that involved some kludge of LEDs, resistors, batteries, and switches. It didn’t go well in part because I used Lithium coin cells as the power source. To this day I have not confirmed my suspicions, but Lithium-ion batteries are notoriously sensitive to temperature variations, and I think because of the low temperatures outside the battery voltage dropped and the LEDs did not stay lit for very long. There are of course many other reasons to explain why my first attempts were failures – one being that I have little skill designing stuff – but I am inclined to think it was the temperature that did me in. My main reason for thinking that is because once I brought the circuit back inside and it returned to room temperature, the LEDs started to become bright again.

To avoid being screwed over by lame batteries again this year I decided to pick up some 9V Alkaline Enercell batteries from our local RadioShack. The idea here is that I will step down the voltage from 9V to 5V to power the PICs that control the lighting sequence using a linear regulator (currently on its way from Digi-Key). To make sure that I wouldn’t lose any battery voltage when the temperature drops at night, I tested one of the Enercells at varying environmental conditions. The first test (pictured below) was conducted at around room temperature. The second was done after I left the battery out in the night air for a few hours. The last was after I left the battery in the freezer overnight. 

Figure 1. Battery voltage across various temperatures (From Left to Right: room, fall night, below freezing)

As you can see, there shouldn’t be any voltage drop on the terminals at all based on any realistic temperature conditions on Halloween. I expected this given the battery chemistry, but RadioShack is infamous for not providing datasheets for any of their parts so I had to be sure before I relied on them. As long as Halloween night stays above absolute zero everything should work fine as far as the batteries are concerned. Current projections have the nighttime low set a 42° F.

Unfortunately, 42° F could be problematic for another aspect of my design. In trying to find a workaround for my oscillator timing problem I came across Figure 2 in the datasheet for the PIC 16F690 (lazily colorized for your enjoyment).

Figure 2. HFINTOSC frequency accuracy over supply voltage and temperature

What this graph is showing is the high frequency internal oscillator (HFINTOSC) accuracy over temperature and voltage. Remember how I stated in my last post that the accuracy of the internal oscillator is only quoted at 1%? And remember how I said earlier that datasheets often quote the best metrics up front without qualifying the conditions for their execution? Well according to their own chart I can only get 1% accuracy if I run the PIC on 3.5V at room temperature, plus or minus about 10° C. Running the PIC on 5V alone is enough to push the accuracy to 2%, and when you consider that temperatures could get as low as 40° F (4° C) I am trending dangerously close to pushing that accuracy to a horrendous 5%. While all this sounds really bad I am not in panic mode just yet. Based on some reading I have been doing I think I can work around this by shortening up the animation times, which will limit the amount of time the four oscillators in the chips have to drift away from each other. I am also working with putting the PICs to sleep when they don’t need to turn on LEDs and then waking them back up using the Watchdog timer (WDT). From what I can gather the watchdog timer triggers a processor reset when it overflows so I think I can use that to re-sync the clocks after each light sequence. With only four days left to work, getting this project up and running could come down to the wire.


Joel Ryan said...

Down to a hare's breath, even

Noah Ryan said...

Isn't the watchdog timer stepping based on an oscillator also? Or is it some independent hardware counter with timing based on physical characteristic of the circuit? I really don't know.

Post a Comment