Some time ago I stumbled over an article about charlieplexing on hackaday.com. Charlieplexing is basically a method to control n * (n-1) LEDs using only n I/O ports of a microcontroller. Say you have 5 I/O ports, then you can control 5 x 4 = 20 LEDs independently! Find more details in Wikipedia. I was fascinated, because I had never thought it was possible to control so many LEDs with so little hardware.
But it seems that charlieplexing comes with a few drawbacks. While this is certainly true, some of these drawbacks are in my opinion over-emphasised, especially when compared to "conventional" LED multiplexing. So I set out to explore the issue, just for the fun of it.
One misconception that seems not to go away is that there can always be only one LED activated at a time. Allegedly this means that a very high multiplexing frequency has to be used. Not true. If one I/O port is set to L, then the other ports can be set to either H or Z. For every port set to H, exactly one LED will be activated.
Perhaps this becomes clearer, if we compare a conventional LED multiplex matrix with a charlieplexed matrix.
A normal LED matrix looks like this:
You set one row line to L, the other two to H or Z. By setting any of the column lines to H you can activate their corresponding LED. With this conventional set-up you need 6 I/O ports and every LED has a duty cycle of 33%.
Now let's look at a charlieplexing configuration. I chose a schematic structure that is similar to the one above to make things clear:
Note that the R-ports have vanished. They are replaced by C-ports, which means that now there are only 3 ports controlling the matrix. You can verify that this is a charlieplexing structure by checking if there is a LED from every port to every port.
The result is that now we have three ports less, at the cost of three LEDs less. Those LEDs were useless, because there anodes and cathodes would be connected to the same I/O port in the new structure. Of course it would be possible to use 4 ports and then control 4 x 3 = 12 LEDs, but I wanted to keeps things similar.
If you look at that structure, perhaps it is easier to see how multiple LEDs can be activated at the same time. The duty cycle for a 6 LED set-up is again 33%. And immediately another fact can be seen. The layout of a charlieplexing structure is not more complicated than that of conventional multiplexing. This is true even for larger structures. Of course, a two layer wiring scheme is necessary, because in both cases there are a lot of lines crossing.
It is obvious that it is possible to move the LEDs so that you get a normal LED matrix. All you have to do is to bend your wiring somewhat. This is what I mean:
This is exactly the same structure as before, only the LEDs have moved to form an orderly matrix. Some people say that programming a charlieplexed display is quite difficult. I think this example shows that it really isn't to bad, because there is a lot of regularity in it. Controlling the display as shown here is just a little bit of bit-juggling - piece of cake.
And here is one last issue, that I would like to address: The limited current one can get from a microcontroller's I/O ports. It makes good sense to use very bright LEDs for a multiplexed display, because of the relatively low duty cycle per LED. So you get relatively high current requirements per LED. Many bright LEDs are rated at 20 mA, but can be supplied with higher pulse currents. This is a problem for many microcontrollers, because they can not drive these amounts of current. When you have a traditional multiplexed display, the solution is to use transistors. Usually an inverted driver configuration is used, like so:
For a charlieplexed display, an inverting driver would not work. But a non-inverting configuration works perfectly well. Here is how:
Simply an emitter follower. The hardware costs per port are the same as for conventional multiplexing. But remember that less ports are needed. So the total hardware costs are actually less.
To test my theories on charlieplexing, I had to build a display myself. I can say that everything works as expected. Here is a photo of that experiment. It consists of an Amtel tiny13, 20 LEDs, five transistors and resistors for current limiting. Lots of fun, and a nice project to show off...
Here is a photo of the hardware. It is built on a prototype board.
This video shows the display in action. Unfortunaltely it flickers a bit. It doesn't do that in real life.
And finally here is the schematic...
...and the corresponding layout.
That's it. My first post is finished. Let me know, what you think. Any comment is appreciated.
Update 25-Mar-2011: Due to popular demand, here is a link to the source code: Link.
It is written in assembler and probably not too well commented. It wasn't meant for publishing. If you just want to create your own patterns, leave everything alone apart from the main_loop. There is a "video ram" consisting of registers matrix0-4. Its contents will be converted and displayed by the interrupt routine.
You can just set those registers. There is also a set of display manipulation routines, like scroll_up, invert_all and so on. See example patterns in the main_loop as to how they are used.