Monday, July 20, 2009

How To Control 12 LED's Using 4 Microcontroller Pins

What you need to know about 12 LED's Using 4 Microcontroller Pins.

If you have ever done any electronics before you will probably be familiar with multiplexing but charlieplexing adds a new dimension. It's a technique commercially developed at Maxim by Charlie Allen hence the name but you can still use the technique in your own circuits.

Note: The actual technique has been around for some time but Maxim is one of the first companies to use it in a commercial chip.

Multiplexing simply means sharing whether it is

FDM Frequency division multiplexing

TDM Time division multiplexing

WDM Wavelength division multiplexing

Of course the other form of multiplexing which every electronic engineer uses to steer signals around a digital circuit uses standard logic gates and although not as glamorous as FDM, TDM and WDM it is a core technique for designing digital circuitry.

With a normal logic gate multiplexer you will have a minimum of two inputs that you want to select and send to a single output controlled by a control signal.

The states of the output gates are as you would expect either high (logic 1) or low (logic 0) but charlieplexing recognizes another state:

High Impedance.
Note: This is the third state in addition to 0 and 1 so it is often called tri-state.

High impedance just means switching off the output current circuit so no current can flow into or out of the output pin.

Of course high impedance output logic gates have been around for as long as digital circuits have been used mainly for accessing a microprocessor bus where each device is tri-stated to disconnect it from the shared bus while another device outputs data to the bus.

Charliplexing

Charlieplexing uses the third state to disconnect a pin from a mesh of devices so no current flows at that node and it's ideally suited for control from a microcontroller since it's easy to change the operation just by re-programming the microcontroller.

One of the uses of charlieplexing is to control many leds using very few pins. LEDs are also diodes so reversing the voltage across an LED means no current will flow. If you connect two leds to two output pins with the second diode connected the opposite way to the first one (and using current limit resistors). Setting the output pins to 01 will turn on the 1st LED while setting the output pins to 10 will turn on the 2nd LED.

Now add in a third output pin and add two diodes connected between each microcontroller pin as before. You now have 6 LEDs and by tristating each microcontroller pin in turn only two output pins are 'connected' i.e. You can control each LED individually.

You have now controlled 6 LEDs using only 3 pins normally you would need 6 individual output pins.

The formula for how many LEDs you can control is:

LEDs = N * (N-1)

  • Two pins gives 2 x (2-1) = 2
  • Three pins gives 3 x (3-1) = 6
  • Four pins gives 4 x (4-1) = 12

Advantage of Charlieplexing

Very few pins control many LEDs.

Disadvantage of Charlieplexing

Only certain sets of LEDs can be turned on at the same time.

No comments:

Post a Comment

Bookmark and Share