There you have it: six LEDs for the cost of three pins
and three resistors. There are a couple things to note
when using Charlieplexed LEDs. When using the simple
circuit shown in Figure 3, the LEDs should be of the same
type and forward voltage. If you're going to mix LEDs,
remove the resistors shown and replace each LED with an
appropriate LED/resistor combination.
■ FIGURE 5. Bad path.
Another thing that one must watch for is the resistor
values. Have a look at Figure 5; what this illustrates is the
possibility of lighting multiple LEDs under the right
conditions. When we light D1 (P0 high, P1 low, P2
floating), there can be a secondary path through D3 and
D6 as shown.
repeat n from 5 to 1
This can happen if the combined forward voltage of
the LEDs is lower than the output voltage of the
controller, and the resistors are so small that enough
current can flow to light both LEDs — though they won't
be as bright as the target LED.
The first parameter of run_larson() is the number of
back and forth cycles to run; the second is the delay time
for each LED. For a one second cycle, the delay timing is
set to 100 ms by the caller.
For my circuit, this isn't a problem because the
forward voltage of each LED is about two volts; there is
no way to light two of these LEDs in series with a 3.3V
micro. That said, if I moved this circuit to a 5V micro, I
would have to check the resistor values.
The second method is a simple counter that uses all
pub run_counter(ms) | n
Finally, I mentioned earlier that the Spin driver will
run down to a clock speed of 20 MHz (PLL = 4x). We
can speed things up by converting the Charlieplex
operations to PASM; this will allow us to run all the way
down to 5 MHz (PLL = 1x). This might be helpful when
using the Charlieplex circuit in a battery powered
repeat n from %111111 to %000000
No, it's not terribly exciting, but it does, in fact, verify
that we can have up to six LEDs [appear to] be on at the
I've included a duplicate of the demo code which
uses the PASM version at the article link. Those of you
that are starting to make the move from Spin to PASM
will find the code interesting. The PASM is very simple,
and a near direct match of the Spin code.
Lock It Down!
If you're like me, you have solderless breadboards
■ FIGURE 7. Overlay on PAB.
■ FIGURE 6. Overlay PCB.
18 August 2015