Keyboard and display multiplexing -- Charlieplexing
After my previous review of more traditional ways of reducing the I/O lines needed to drive LEDs/displays and keyboards/switches, here I'm looking at the nominally new method of Charlieplexing.
Back in about 1982, I was asked to design a product that had 72 individual LEDs (see Figure 1). I solved the problem by using an ICM7218, which allowed for individual segment control of eight 7-segment displays, so I simply treated each LED as one of the segments. The eight remaining LEDs were driven from the micro (if I remember correctly). That would have taken up 24 IC pins.
Figure 1. An 8051-based product with 72 LEDs arranged in a matrix -- the red blur you see in the middle of the board.
As luck would have it, the solution that would have helped appeared long after I had completed the project. Charlieplexing was introduced in the 1990s (apparently its roots actually go back to quite a bit before that) by Charlie Allen at Maxim, it set the electronics world atwitter (in the 1990s sense) and there were quite a few design ideas published around this concept.
The Charlieplex idea was to use the bipolar drivers on the I/O lines so that the pin could source or sink a current. But an I/O pin also has an “off” state where it is high impedance or in read mode. If we analyze the simple arrangement in Figure 2 we can see that if P0 is logic high (and sourcing current), P1 is low (and sinking current) and P2 is in a read state (and in high impedance) LED DS1 will be illuminated. The six possible cases can be seen in Table 1.
Figure 2. Three pins controlling six LEDs as per the Charlieplexing technique.
Table 1. Possible combinations
The LEDs need current limiting and when they are all the same type, the three resistors shown in Figure 1 will suffice. If you are using different LEDs then each LED will need its own series resistor. The electrical properties of the LEDs ensure that they are undamaged and only one is illuminated. The reverse voltage across any LED is clamped to the forward voltage of the paralleled LED and will be within the maximum reverse voltage rating of the LED. When two series LEDs are forward biased, the voltage is clamped by the single LED in parallel across them and the voltage will be insufficient for the pair to turn on.
The number of LEDs that can be controlled by this technique is calculated as N x (N-1) where N is the number of lines. Now to me this is back to front and you really want to know how many lines you need for a given number of LEDs. I don’t need to tell a bunch of engineers that you need to solve the quadratic equation, but Table 2 lists the relationship at smaller numbers.
Table 2. Relationship between the number of pins, number of LEDs and the duty cycle for each LED.
I thought to myself, now let’s expand the circuitry to more lines, and then… well my mind boggled. How do you set about doing this systematically? I turned to trolling the Internet and came up with this technique, which I will realize with 6 pins.