LED Christmas Lights
Recently I bought a set of LED Christmas lights from All Electronics:These lights are sold as-is because the controlling units overheats. So why buy a known-defective set of Christmas lights? To fix them, of course! These lights are controlled by a programmable chip called a PIC. Careful programming can significantly reduce the power consumption, and fix the heat problem.
What is a PIC?
A PIC is essentially a one-chip computer designed for embedded systems. You can't play video games on it, or even run Windows. It's made to run very simple tasks. A typical PIC only has a few hundred bytes of RAM.Replacement PIC
The PIC that comes with the LED lights is a write-once device. It can't be modified. Fortunately there are a number of programmable replacements. I choose the PIC16F627a, mostly because I already had several on hand. They're available at mouser.com. for about $1.75.
Original: PIC16C54 (CF745) |
New: PIC16F627a |
Tools
Writing code into a PIC requires a programmer. Removing the original PIC part requires a soldering iron, and a solder sucker (remover).
Warp 13 PIC Programmer |
Soldering Iron |
Solder Sucker |
Adding a Socket
The LED controller comes with a 18-pin DIP (through-hole) PIC soldered directly into the PC board:To ease development it is best to remove the original part, and install a socket:
Desolder PIC |
PIC chip removed |
Socket |
Hardware Programming Model
Eight bits (signals) are used to control LED illumination. Four bits are used to select each LED color (red, yellow, orange, and green). Four bits are used to select a bar or arm of the star (e.g. all LEDs on the horizontal axis correspond to bar 3):An LED will illuminate if both of its bar and, color are selected. Thus, selecting red, and bar 1 will light the two LEDs on the vertical axis:
The following diagram shows the control signal to PIC mappings:
Software
Originally I had hoped to read the software from the original PIC, and then modify it for my purposes. But the PIC16C54 is an unusual part, and my programmer can't read it. So I decided to write everything from scratch.Pulse Width Modulation
This code uses one of the PICs timers to create pulse width modulated signals. To prevent the unit from overheating the power consumption must significantly reduced. A common trick to reduce the brightness of an LED is pulse width modulation (PWM). Basically this means turning the LED on and off very rapidly -- so quickly it is undetectible to the naked eye.The brightness, and power consumption are adjusted by changing the duty cycle (percentage of time spent on).
Algorithm
Here's a highly simplified version of the code, written in 'C':Source Code
Here's the real assembly code:Conclusions
The power reduction was a success. The lights used to draw a maximum of about 1.8 amps; now it's down to about 430 milliamps. It doesn't get warm even after hours of operation.Writting display patterns is pretty easy. But because of the limitations in the hardware, there just aren't that many interesting designs you can create.
Here's a video of the lights in action (4MB):
xmas.avi
No comments:
Post a Comment