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.

Oct 24, 2011

Oscillator Fail

Well, as it turns out even the simple things have to be difficult when you don't know what you are doing. In my first attempt to code a test animation into my four pumpkins, I was able to get them to light up in sequence...for about 20 seconds. The idea was to have each one light up from left to right and then repeat the cycle. Everything seemed to be working great until I walked away and came back about 5 minutes later. Eventually, each pumpkin started to light up out of sequence or with a noticeable delay. As time went on, things only got worse. My first instinct was that it had to do with the inaccuracy of the internal oscillator, which is running at 4 MHz. Based on the data sheet values for the PIC 16F690, the internal oscillator is rated at 1% accuracy, which I know sounds good, but it is actually very poor for a timing device. For reference, that means if you wanted to make a simple clock project where the microcontroller just keeps track of time, your clock would be 15 minutes off the actual time by the end of the day.

I posted my results and my thoughts to the EEVblog forum yesterday afternoon, and the responses have enforced what I believe to be the problem. As you can see in the video below, the initial sequence actually functions very well.


Unfortunately, this is what it looks like about 4 minutes in...............


I have started to think of ways to work around this issue without a lot of extra effort. This problem is by no means insurmountable, but given the time I have and my knowledge of the chip it will be difficult to come up a robust solution before Halloween. My latest thought is to speed up the light triggers and finish the entire show before the oscillators get too far out of sync with each other. After the entire loop has run through once, I think I can enable the chip's reset and start it over with the clocks synced like they are when you first apply power to the circuits. If worse comes to worst, I will let the light show run free and generate what looks like random sequences. Given my high hopes for the project starting out, I really don't want to dumb it down to that level.

Oct 18, 2011

Pumpkin Quartet

As promised, this is a short update on the progress of my Halloween display project. So far, I have managed to get one chip programmed using Microchip’s new MPLABX IDE, the HI-TECH C compiler, and a PicKit 2. I haven’t ever actually programmed a microcontroller with C before and MPLABX is still in beta so it took some time to get familiar with setting up even a basic LED flash program (mostly due to the fact that I don’t entirely know what I am doing). At the moment I am only running simple timing loops to control the animations, but I hope to get more functionality in the next couple weeks. My plan is to hardcode an animation sequence into the micros as a backup  in case I can’t get my additional features built in before Halloween. We will see how things go.

Now for some pictures. Below are three pictures of the pumpkins as they look right now. I found four faces online (since no one gave me any suggestions) that I more or less copied for my own use. The pumpkins themselves are hollow, but the foam walls were actually about half an inch thick in certain areas so getting a decent pattern out of them takes some effort. I am pretty happy with the way they turned out though.

My color choices below aren’t final yet. I am still experimenting with colors and suggestions from friends so leave comments if you have suggestions. The colors are kind of hard to make out in the photos, but they look much better in person. From left to right they are: green, red, white, and blue.

Since these will be outside in the dark I took a night shot too. One thing I am pretty proud of is how even the light looks inside the pumpkins. I found some diffusers at our local Michaels that I think will really work well in the final project. There will be more to come on these in my final bill of materials.

That’s all that I’ve got for this update. I am going to start working out some lighting patterns and planning out their timing with an Excel spreadsheet for event scheduling. In the interest of open source, I will post all the materials I used to create the final project once I wrap things up.

Oct 16, 2011

September Power News

I’m back today for the third installment of my “Power in the News” series. This month I am sticking with the format I used earlier, but I will try to trim things down even more. I have been investing more time on my projects recently so my posting frequency has decreased pretty significantly. Hence, I am posting on September’s power news in the middle of October.


The US Energy Information Administration (EIA) has reported that global energy consumption will increase by 53% from 2008 to 2035. Contributions from renewable energy sources will continue to rise each year, and by 2035 renewables will be responsible for 15% of world’s power demand. Carbon emissions are also expected to rise from 30.2 billion metric tons in 2008 to 43.2 billion tons in 2035 due in large part to increasing industrialization in developing countries throughout Asia and Africa.

I will never understand the concept of projecting 30 years into the future. Life is too variable and most of the time these estimates don’t get anywhere near reality. I chose to include this story though because I think the study shows how our need for reliable energy sources is only going to get bigger. The EIA stated that we will still be largely dependent on fossil fuels by 2035, but I hope they are wrong. Don’t misunderstand what I am saying. I don’t have any grand delusions about the implementation of renewable resources, but, given their potential for energy production and the funds that are rolling into renewable research, I am almost positive that we will do better than 15 percent.

A 2009 article in The Sunday Times called out Google for emitting 7 grams of CO2 per internet search, and wrote that “Google is secretive about its energy consumption and carbon footprint”. Google responded this week by releasing its energy consumption numbers based on figures from the last few years. As it turns out, Google consumes about 2.3 billion kilowatt-hours of energy per year while generating carbon emissions 35 times fewer than the article originally stated. For perspective, 2.3 billion kWhs would power around 207,000 homes or 41 Empire State buildings for a year.

This is largely a non-story. Google has been one of the most active companies on the planet when it comes to investing in new energy resources. They have also been involved in CO2 reductions that offset their own production. From the numbers I have seen, The Sunday Times was way off base in their estimates and should’ve done their research ahead of time. Trying to drag a company as big as Google with their slogan of “Don’t be evil” through the mud doesn’t look like it will end well for the British periodical.

Korea just activated their new superconducting cable manufactured by American Superconductor (AMSC). With copper prices on the rise, new cables like these are becoming cost-effective options for utility companies because they can carry 10 times the amount of power compared to standard transmission lines. This new version replaces several current superconducting cables, making it the longest of its kind in the world.

I wanted to bring up this story because I believe it’s a step in the right direction for power distribution systems. Most grids around the world are woefully out of date, with the US being the prime example. We need to be smarter about power distribution across the globe. Without a smart and efficient way to distribute power, it will not matter how efficient we make the end use products. Like lighting, we rely far too heavily today on distribution technologies that were developed over a century ago. We are wasting power, wasting resources, and, given our efforts to upgrade, wasting time.

 Eleven wind farms in Britain were shut down following higher than average wind speeds as a result of Hurricane Katia in the middle of September. The National Grid actually paid the farms 2.6 million euros (title refers to the 1.2 million that went to just one farm) to shut down production for eight hours amid fears that the grid would be overloaded by excess electricity. For context, that is roughly 10 times what the farms would have received for actually selling electricity to the grid during that time period. The National grid made up the payments by tacking on additional charges to consumers electricity bills. Payments to cap electricity production are not uncommon and are increasing as more and more wind farms come online.

You can probably tell from the description why this wins September’s idiotic category. First, The National Grid isn’t prepared to handle excess electricity from wind farms yet they encourage more and more to come online. People are starting to question the long term sustainability of wind farms because of human incompetence. As if wind energy didn’t have enough problems getting over human complaints about bird fatalities, noise, and aesthetics, inept implementations are now adding fuel to the fire. On top of that, because of their own failure The National Grid is passing on their costs to consumers, which isn’t fair. Wind farms should be an amazing source of energy when the winds pick up, but instead they have become a hazard due to mismanagement. Granted, wind turbines need a cut in speed and have a max rated speed, but from what I can tell the turbines could’ve handled the wind speeds. The National Grid not only lost out on capturing the excess energy, but spent millions to prevent its generation and screwed over consumers in the process. Someone please regulate this thing.