2009-12-13
As discussed in the LOL can tree article I've been thinking about this project for a while.
This fun little toy was built as a proof-of-concept test bed for a number of different Christmas "das blinken lighten" projects.
I decided to use the Atmel Tiny13 once again. The choice is largely because I have many of them, they are physically small, and they can provide 5 drive lines in an uncomplicated manner (without also using the reset pin, so simple programmers still work). 5 tristate outputs lets you charlieplex 20 LEDs with a relatively simple wiring topology. Much more than 20 LEDs on a single scan matrix, the duty-cycle and maximum drive current become more of a problem, so it is a reasonable engineering choice also.
For the prototype I am using only 16 of the 20 possible control vectors. Simply because the state vector of the display then fits into two bytes and makes the software easier and more compact for the initial development.
You can think of a maximum charlieplexing topology as a complete graph, where each vertex (tristate drive line) is connected by an edge (reverse-parallel LED pair) to every other vertex. The K5 complete graph in this case, but omitting two edges (only 16 LEDs).
The ultra-bright amber LEDs (from a Rockby clearance) were paired up and soldered in reverse parallel with reducing lead lengths, then threaded onto a bamboo kebab stick as a support with every second pair placed orthogonally. The wiring matrix was then soldered in place using 5 pieces of fine magnet wire (the wiring pencil makes this task easy).
Each drive line from the MCU has a 39 ohm resistor in series to limit the LED current. The value is a compromise between brightness and peak LED current. The peak current specification of the LEDs is unknown but they are not overheating so service life should not be impacted.
The code is written in C and is quite straight forward. A table of control vectors for each individual LED is used to store the tristate drive vectors. One byte per LED is used, split into two nibbles. The top nibble is the number of the pin to be asserted high, the bottom nibble is the pin to be asserted low. This data is used to generate the required DDRB and PORTB states. The table has obvious redundancy and could be halved in size, but the simplicity of indexing it by LED ID is preferred over the small space saving.
The charlieplexing loop lights each LED in turn if its bit in a global state array is set. The loop takes essentially constant time regardless of each LEDs state so brightness is constant.
A timer causes a periodic interrupt which updates the display state from another table of animation frames. Each frame takes two bytes (same as the state), and setting the state is simply assignment from the table indexed by the current frame (which advances circularly through the table).
The display structure was wrapped in black knitting yarn to disguise the wiring, make the bamboo less visible, and hold everything in place. A small square potting box (from Jaycar) was used to contain the drive board, and a 9-volt battery snap exits the box for connection to the double-AA battery holder that powers the device.
A USB lead terminating in a 9-volt battery plug is also provided for running off PC supplies. The current through the display is safe at the higher 5 volt supply given by USB, and the extra brightness make the unit quite impressive even in well lit conditions.
In the picture above you can see the larger 19 LED Christmas Star I have built using the same general design. It has somewhat different animation software, based on a state machine that "executes" byte-coded animation programming in the MCU. This is more compact and flexible than a simple table of frames.
For the Christmas tree, with its simpler software, I have only programmed in a basic loop at the moment. There are almost endless possibilities however, and plenty of space in the MCU for longer loops.
I think I'll write some software to emulate the system on a PC and let me design the display with a GUI, especially for the star project which should be quite spectacular with its ultra-bright white LEDs...
2 comments.
title | type | size |
---|---|---|
Original Raw Loop Example Video | video/avi | 15.698 Mbytes |