https://noisebridge.net/index.php?title=Charlieplexing_as_a_basis_function&feed=atom&action=historyCharlieplexing as a basis function - Revision history2016-02-07T13:07:44ZRevision history for this page on the wikiMediaWiki 1.19.1https://noisebridge.net/index.php?title=Charlieplexing_as_a_basis_function&diff=3606&oldid=prevJbm: New page: == Charlieplexing as a basis function == Short version: using ternary integers to encode charlieplexing as a basis function for encoding the state of an LED matrix. We can use POV for su...2009-03-16T01:12:14Z<p>New page: == Charlieplexing as a basis function == Short version: using ternary integers to encode charlieplexing as a basis function for encoding the state of an LED matrix. We can use POV for su...</p>
<p><b>New page</b></p><div>== Charlieplexing as a basis function ==<br />
<br />
Short version: using ternary integers to encode charlieplexing as a<br />
basis function for encoding the state of an LED matrix. We can use<br />
POV for superposition to recombine these "charlievectors", and get<br />
multiple levels of grey on the array for free in our decomposition<br />
step.<br />
<br />
=== Motivation and background ===<br />
<br />
Motivation: getting video onto a charlieplexed array.<br />
<br />
You can't do it because the normal way charlieplexing works is to set<br />
a single LED at a time. To turn on N LEDs requires toggling 4*N lines<br />
on the microcontroller. In this view, what you're putting onto the<br />
display is "encoded" as a set of LEDs that are on: if you want to turn<br />
on LEDs 1, 2, 3, 12, and 15, you'd encode it as { 1, 2, 3, 12, 15 }.<br />
You then walk through that list, turning them on, waiting a few<br />
milliseconds, then turn them off, and move on.<br />
<br />
==== Problems with charlieplexing video ====<br />
<br />
Ideally, we'd just turn on all the LEDs for a given frame of video at<br />
once, then turn them off. Sadly, we can't do that. Typical<br />
charlieplexing goes through the matrix LED by LED, turning them on,<br />
then turning them off, and moving on. If you do this fast enough, it<br />
sort of burns into the eye, a trick called "Persistence of Vision" or<br />
POV.<br />
<br />
However, POV only works well within certain parameters: if you take<br />
too long to strobe a frame, the video stops being video. If you go<br />
too fast, the lights are really dim. On the heart, for instance,<br />
if you want to turn on all the LEDs with POV, each LED can only be 1/27th its maximum<br />
possible brightness. In addition to these two problems, the display<br />
also tends to display "flicker" due to the time it takes to strobe<br />
across all the LEDs.<br />
<br />
==== A solution ====<br />
<br />
What if, instead of turning on one LED at a time, we could turn on<br />
many of them? We could turn a series of single-LED writes into a<br />
shorter sequence of multi-LED writes. This greatly increases our<br />
efficiency, giving us better brightness and less chance at flicker.<br />
It also greatly increases the framerate we can achieve.<br />
<br />
Can we turn on more than one LED at a time? Sure! Instead of turning<br />
only one or two pins to +5V or Ground, we turn multiple pins on and<br />
off. If we do this carefully, we can make patterns of multiple LEDs<br />
light up concurrently. The available set of patterns is determined by<br />
how the matrix is wired up. To figure out the patterns, we enumerate<br />
the basis in a software model, and write it out. But, first, a<br />
digression into ternary.<br />
<br />
==== Charlieplexed pins have a ternary encoding ====<br />
<br />
Note that every pin in a charlieplexed array is a trit, it has 3<br />
possible states: HIGH, LOW, and HI-Z. So, we can encode all possible<br />
states of our pins as a 6-trit number. This gives us 729 possible<br />
states, which are pretty easy to enumerate: you just count to 729!<br />
Then, you take this number modulo 3, and that gives you the first<br />
trit's value: 0, 1, or 2. 0 is HI-Z, 1 is LOW, and 2 is HIGH. You<br />
then divide the number by 3 (right shift in base 3), and take the<br />
modulus to get the second trit. Rinse, repeat, to get 6 trits. This<br />
gives you a set of six pin states. These can be applied on the<br />
microcontroller itself to actually drive the pins, or used in a<br />
modelling program.<br />
<br />
In fact, that's exactly what we do: we take a model of the LED pinout<br />
(ie: to turn on LED 1, turn pin 1 HIGH and pin 2 LOW) and check it<br />
against the pin states above. When we do this, we find that we can<br />
associate each of our 729 pin states with a set of LEDs that turn on.<br />
For example, TK state 106 turns on LEDs 1, 3, 12, and 15. To turn on<br />
just pin 2, we'd use state 11, which only turns on LED 2. We can thus<br />
encode the display of LEDs 1, 2, 3, 12, and 15 as { 106, 11 }.<br />
Before, we'd have to turn on all 5 LEDs individually, which meant that<br />
each LED could be at most 1/5 its total brightness. Now, we can do it<br />
in just two operations, letting each one be roughly half its peak<br />
brightness. Reducing the operations also reduces the problem with<br />
flicker, as there's not as much delay between the updates.<br />
<br />
=== The actual process we're going through ===<br />
<br />
So, then, what do we do?<br />
<br />
1. Generate the pin diagram (you probably have this already in your C code)<br />
2. Decide on your pin -> trits mapping function<br />
3. Generate a basis file, mapping integers into LED states (enumerate and decode using the above two files)<br />
4. Write microcontroller code that also implements the integer to pin states decoding. <br />
5. Spot check your two decoding implementations, to make sure your basis is correct (the heart circuit swaps pins all over the place, which makes it surprisingly tricky to get the mapping correct). I'd suggest writing a function that just turns on each of your LEDs for half a second in sequence, which gives a very good spot check. Once that works, you're probably okay.<br />
6. Here's the tricky bit: write a program that, given a set of LEDs to have on, turns that into a set of charlieplexed basis integers.<br />
7. Once you've got that, you're pretty well done with the binary case: you can now output single-grey video to the device.<br />
<br />
==== Greyscale for nothing ====<br />
<br />
Now, what about doing multiple levels of grey? Notice that the<br />
decomposition function above turns a given set of LED states into a<br />
set of charlieplexed basis integers, and we're getting them all to<br />
turn on through POV. Well, what if we just made the decomposition<br />
work on an array of multiple-valued integers, instead of only 1s and<br />
0s? The decomposition should be the exact same process, but just a<br />
little more expensive.<br />
<br />
I've gotten 4 levels to mostly work, but it looks like I have a<br />
problem with my pin mappings at the endpoint there. Some LEDs which aren't supposed to be lit up show up rather bright, or half-dim: I believe I need a full encoding of the LED matrix/network to make the modelled version better. However, until then, it's not a bad first approximation.</div>Jbm