|
Build a high tech microcontroller based Xmas Tree, learn how a unique method for multiplexing LEDs and have fun with this eye catching conversation piece.
|
|
LEDs seem to be used in just about everything these days. They afford some advantages over incandescent lights in that they consume less power, produce less heat and have a very long life.
The typical way to drive an LED is for an output to source or sink current to drive an LED, usually through a current limiting resistor. This works well for small numbers of LEDs, but when the count goes up, using individual output pins becomes difficult. For example if we need to drive 12 LEDs, we need 12 output pins.
When the LED count is greater than a few, typically another technique is used, time-multiplexing. Using this scheme LEDs are arranged in a matrix. For example if we need to drive 12 LEDs we could arrange the LEDs to form a 3x4 matrix. The LEDs are driven by scanning in rows by row or column by column. If the scanning occurs quickly enough, the eye does not see the scanning. This techniques reduces the number of output pins to 7, (3 rows by 4) columns.
Yet another technique, not commonly used, can further reduce the outputs needed to drive 12 LEDs to just 4! The Xmas Tree project demonstrates this technique, and how it might be used.
How does it work?
The Xmas Tree uses a variation of time multiplexing, but exploits the fact that LEDs are after all, diodes. To understand this try a simple experiment, connect an ordinary LED to a battery, (be sure to use a current limiting resistor). Connect the Cathode to negative and the Anode to positive. Note that the LED lights up. Now reverse the polarity of the LED. Notice that it does not light up. If you connect a second LED with opposite polarity, you can choose which LED lights up based on the polarity.
This is the basic technique used in the project. You can imagine how connecting LEDs in this manner could reduce the outputs needed to drive 12 LEDs from 12 down to 6, but how do we get down to the claimed 4 outputs?
To do this we have to do some tricking things. Referring to the schematic, (figure 1) you notice that pairs of LEDs are connected in series across the output pins. If you set one of the output pins to a logic high, and another to logic low, at least one of the LEDs should be able to light, yet there are multiple paths for current to flow, which would seem to allow other LEDs to light as well. They do not however because there is not enough voltage drop across the LEDs that are in series to allow them to light up.
To make all of this work we need one more ingredient. We need the ability to “turn off” the output pins for LEDs we do not wish to drive, setting the output to a logic high or low is not good enough, either of these state might allow some un-intended LED to light. We need to “tri-state” the output pin. In this condition, the output pin does not sink or source current.
To make all of this work, we need output drivers that can source and sink enough current to light an LED, and we need to be able to tri-state the outputs. There are any number of devices that can do this, for the Xmas Tree project we also wanted something small, simple, and inexpensive.
Hardware
|
Referring to figure 1, the Xmas Tree circuit employs a MicroChip PIC 12C671 microcontroller (IC1), operating from an internal 4 Mhz clock. This device has only 8 pins, two of which are power and ground. Obviously directly driving 12 LEDs was not going to happen, even the matrix approach would not work. This device has 6 very flexible I/O pins, most of them have several purposes, plus they can be high/low/tristate.
|
Click on image for a larger view
|
Software
The software that is the heart of the Xmas Tree project. The software must set the I/O pins correctly to enable the proper LED. In addition the software performs several other interesting activities to make the result more interesting.
Random Numbers
The Xmas Tree does a lot of things randomly. Internally the software maintains a 32 bit linear feedback shift register to implement a pseudo random number. An exclusive-or between bits 31 and 18 of a 32 bit number is performed. The result is fed back into the shift register at bit 0. Then they entire 32 bit value is rotated left.
The Xmas Tree chooses at random which things it will do, and for how long. It has a number of tricks that it can choose from, including:
- Spin to the right, 3 different speeds
- Spin to the left, 3 different speeds
- Randomly flash
- Go to sleep
Sleepy Time
You might notice from the schematic that there is no on/off switch. The Xmas Tree project manages power by going to sleep. During sleep, all of the LEDs are turned off, and even the microcontroller's clock is stopped. An internal “watch dog” timer wakes the Xmas Tree periodically so it can decide what to do next. During sleep power consumption is extremely low, these sleep periods greatly extend battery life.
Construction and Checkout
The Xmas Tree is simple enough that it can be constructed on a piece of perfboard using standard construction techniques, keep in mind that the technique used here can be a bit complicated to layout. Get the Firmware
When assembling the board, double-check the polarity of IC1, it is best to use a socket for this component. Also the LED polarity is very important. A reversed LED will not cause a complete failure, but will cause multiple LEDs to light, and can be difficult to troubleshoot.
After you have completed assembly, it's a good idea to double check for bad or missed solder joints, and reversed polarity of components. If all is well, it's time to “let the smoke out”.
Now that you have completed construction, you are ready to see it work. You will need a source of 3 volts, a pair of ordinary 1.5 volt AAA batteries connected in series will do nicely.
With power applied, the LEDs should start flashing, this indicates that the circuit is receiving power. If for some reason the are not flashing, remove power.
Troubleshooting
The most likely problem is some component is reversed. Remove power and carefully check for a polarized component that is not correct.
It's also a good idea to check all of you solder joints for joints that are not good, or pins that might have been missed. It's easy to do.
Another common problem, is reversing an LED. The typical failure, is that multiple LEDs light when only one should. This can be difficult to troubleshoot, the best thing to do is to check the polarity of each LED.
Operation
There is not much to using the Xmas Tree, it is intended to operate for many hours without changing batteries. It is intended to hang on the Christmas tree, or other similar location. It's particularly interesting to watch in the dark.
Further experiments
What other interesting things can you do with the technique? You are not limited to 12 LEDs, the technique can be extended to larger arrays of LEDs, can you figure out how to do it?
| SEMICONDUCTORS |
| IC1 | PIC16C671P MicroChips microcontroller |
| LED1-LED4 | Red Light Emitting Diode |
| LED5-LED8 | Green Light Emitting Diode |
| LED9-LED12 | Yellow Light Emitting Diode |
| RESISTORS |
| R1-R4 | 50-ohm 1/8-watt |
| ADDITIONAL PARTS |
| B1 | Battery holder |