Alternate Charlieplexing Unit

This is a slightly modified library unit for Charlieplexing LEDs. Such a scheme greatly reduces the required port pins.


I've only made three small changes to the stock PMP unit. First, I reordered the pin assignments when using four outputs (which permits up to twelve LEDs) to be more orderly. I also revised the port assignments for the three-output case with conditional compilation to avoid getting an "unused variable" warning. Lastly, I reformatted the code slightly to make it easier to read. But the library unit really is the work of Philippe Paternotte.

The explanations below are derived from his source code, too.

Compilation Constants

There are three compilation constants at your disposal.

  Define the port to be used, e.g.,
  {$DEFINE CHARLIE_PORT PORTC}  // default port

  Define the number of LEDs to implement, e.g.,
  {$DEFINE CHARLIE_LEDS = 5}    // default is 6

  Defines if the BOLD option should be generated, e.g.,
  {$DEFINE CHARLIE_BOLD_OPTION} // default is no.

Note that while the port may be changed, it is always assumed that the pins within that port are at the lowest positions, i.e., 0 through 2, or 0 through 3. Perhaps in a later revision we can make them assignable anywhere.

Global Constants and Variables

The unit makes the following global constants and variables available to your programs:

  Charlie_PORT: byte @ PORTx; 
  // Selected output port.
  Charlie_TRIS: byte @ TRISx;
  // Selected output control register. 

   Charlie_LAST_LED = n;
   // last LED index (first = 0).
   Charlie_MAX_LEDS = n;
   // max number of LEDs allowed for the pins


There's only one procedure to call: CharliePlexing(); it may be called  from within an interrupt procedure. Each time the procedure is called, one LED is treated. If multiplexing via interrupts, then the procedure has to be called often enough so the LEDs are free of flicker.

If the BOLD option is used, the interface is:

procedure CharliePlexing(LEDs, B_LEDs: tLED_Mask);, where
    - LEDs is the mask of the LEDs to be on (first is bit 0).
    - B_LEDs is the mask of the LEDs to be BOLD.

Note that bold LEDs are lit during a period whose length is double that of others.

Otherwise, without the BOLD option, the interface is simplified to:

procedure CharliePlexing(LEDs: tLEDs_Mask);

Add It to Your Library Collection

And here's the new library unit, "Charlie_alt.pas" for you to download:

Be sure to read over the source code for additional details on how to use it.

Try It Out

There are three exercises on this blog which can demonstrate this library unit. The first simply Charlieplexes six discrete LEDs. Go to it here. The second one uses Charlieplexing to drive a ten-element dot-graph. You'll find it here. And the third one uses interrupt driven Charlieplexing to drive a ten-element bar graph. Click this to go there.

No comments:

Post a Comment