Home     Contact     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS     Terms of services     Privacy policy  
   
 Home      Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science   

5 April 2011
Author: kammenos
The Charlieplexing

History

Charlieplexing is a rather new multiplexing technique. It was first proposed in early 1995 by Charlie Allen at Maxim Integrated Products for driving a multiplexed display. Like other multiplexing techniques (eg matrix), charlieplexing is used to control more loads with less I/O ports.




Charlieplexing does more!

A typical I/O port of a microcontroller, when used as an output, has basically two states: the HIGH and the LOW state. When the port is used as an input, it is driven into High Impedance state. During this state, the port's internal resistance gets very high values (Mega Ohm), and the current that flows through the port is very small, measured in micro amperes.

Charlieplexing can multiplex the I/O ports of a microcontroller more efficiently, because it utilizes this characteristic, which is called "tri-state".




A very simple example

Look at the following simple circuit, which uses two ports to control two LEDs.





Here is the principle of operation. The two LEDs are connected anti-parallel, the anode of the red LED (left) is connected to the cathode of the green LED (right). When port 1 becomes HIGH and port 2 becomes LOW, then the green LED turns on, and when port 1 becomes LOW and port 2 becomes HIGH, the red LED turns on.




One more port...

Now we add one more port to control more LEDs. I have broken apart the circuit into 3 sub-circuits, each one showing 2 ports. So, we have 2 LEDs controlled by port 1 and 2, two more LEDs controlled by ports 1 and 3, and another 2 LEDs controlled by ports 2 and 3, a total of 6 LEDs:





So, with the same principle as before, a microcontroller can control individually 6 LEDs with only 3 ports. A typical matrix cannot control that much LEDs with only 3 ports! As i said before, the charlieplexing utilizes the tri-state of a micro-controller's port. But how? Let me re-draw the same circuit with the 3 ports and the 6 LEDs, but this time i will not draw them separately:





When Port 1 is HIGH and Port 3 is LOW, then L6 will light. But in what state must Port 2 be? If Port 2 is HIGH, then L4 will light as well, and if it was LOW, L2 would light simultaneously. So, to avoid unwanted situations, Port 2 must be in High impedance state, often show with the symbol "Z". Same applies of course if we try to light L2. Port 1 should become HIGH and Port 2 should become LOW. If Port 3 was HIGH, L3 would light as well, and if it was LOW, L6 would light simultaneously. So, the general rule is that, only 2 ports can be simultaneously outputs and all others are in High Impedance state by defining them as inputs.




Operation Table

So, here is the Operation Table for the previous circuit. Symbol H stands for HIGH, L for LOW and Z for High Impedance:


#PORT 1PORT 2PORT 3
L1LHZ
L2HLZ
L3ZLH
L4ZHL
L5LZH
L6HZL




Manual 0.5 Sec  1 Sec  2 Sec 



Many LEDs, but how many?

You can calculate the maximum number of LEDs that can be controlled with Charlieplexing, if you solve the following formula:



n = Pn x (Pn-1)

n is the number of LEDs and Pn the number of ports used by the microcontroller. So, for 3 ports you can control 3 x (3-1) = 6 LEDs, for 4 ports 4 x (4-1) = 12 etc.




Do you see something strange???

Suppose that we want to light L6: According to the previous table, Port 1 must be High and Port 3 Low, with Port 2 driven to High Impedance. L6 if forward biased and it will light, correct, but what about L2 and L4? They are both forward biased! They should both light, shouldn't they?

The answer is simple, but you need to know something about LEDs. LEDs have a very narrow voltage operation range. They may consume very little current, but they will not light if the voltage across them is bellow a specific value. Typically, LEDs operate from 2.9 to 3.3 volts (but that is not a standard range). So, if we give +3.3 volts to Port 1 and 0 volts to port 3, then L6 will be forward biased with 3.3 volts and it will light indeed. But L2 and L4 are in series, and -according to Kirchhoff- the total voltage drop across a series circuit is the sum of the voltage drops across each part.

In other words, the series circuit is composed by 2 parts, L2 and L4. So, each of these parts will have 3.3/2 volts across it's leads, which is 1.65 volts, way bellow the minimum operational voltage threshold. So, these two LEDs will NOT light because they do not have sufficient voltage across them. Moreover, the current through L2 and L4 will be very small, a couple of miliamps or less.




Where to connect the limiting resistors?

Typically, the correct point to connect your limiting resistors is between the microcontroller and the ports of the Charlieplexing circuit. Each resistor must have HALF the value of the required value. If for example you want to protect the LEDs with 200 Ohms resistor, then you must use 100 ohms resistors, and that is because, to light each LED, the current goes every time through 2 resistors, and not one. Here is a typical circuit:





This circuit will operate normally, and all LEDs will have the same brightness. I said before, that only two ports can be outputs simultaneously. But that is not absolutely true. There are special situations, where more than 2 ports can be outputs, so that more than one LED is turned on. This can only happen with LEDs that have a common anode or a cathode, like for example L6 and L4 or L1 and L5. These LEDs can light simultaneously. Take for example L4 and L6. If Port 1 and Port 2 are HIGH and Port 3 is LOW, L4 and L6 will turn on. But the problem is that they will have much less brightness than the other LEDs. Why?

The answer is again simple. Suppose that each resistor is 100 ohms and the voltage supplied by the microcontroller is 5 volts. If ONE LED is turned on, then the maximum current allowed can be calculated by the ohm's law as follows:



I = V / R => I = 5 / (100+100) => I = 25mAmps

25 mAmps can go through the LED. But when 2 LEDs light simultaneously, the current is divided by two for each LED, because the LEDs are connected in parallel. So, only 12.5 mAmps can go through each LED, and this means that these LEDs will not be as bright. There is a solution though. The solution is to connect one resistor for each LED, like this:





Now each LED has its own resistor, and the current is no longer divided if other LEDs light simultaneously. So, the first circuit with the 3 resistors works pretty well, only if you plan to light each LED alone. If (for some reason) you want to light more than one LED simultaneously, then you need to follow the second circuit with one resistor for each LED. In general, the second circuit is rarely used and i suggest you avoid it unless you have a very good reason. And don't worry, there is another way to light more than one LED simultaneously...




So what? Only one LED can be turned on?

Yes and No. Yes because as i explained before, the Charlieplexing cannot control more than one LED at a time (i am always talking about the first circuit with the 3 resistors). And no because, the human eye can be tricked :D

Suppose that you want to light L1 L2 and L3 simultaneously. The only thing that you need to do, is to turn on L1, then turn it off, turn on L2 and turn it off and then turn on L3 and turn it off as well, but all this in a short time and continuously. If the ON-OFF of the LEDs is fast enough, the human eye cannot detect it. It is the same principle like in a cinema movies. The pictures change so fast, that the human eye thinks it is a continuous film.

There are some limitations and parameters that you need to take into account. First of all, the ON-OFF rate of an LED must be fast enough for the eye to be tricked. If for example the rate is 10Hz, the flickering will be visible. So, choose a frequency above 24Hz - remember that 24 frames per second is an acceptable movie frame rate.

Another problem that may appear is the brightness. The LEDs will not turn on at full brightness, and that is because the circuit will operate as a PWM dimmer for each LED, taking into consideration that there is an OFF time. This OFF time has to do with the number of LEDs that have to be controlled. The more the LEDs, the longer the OFF time for each LED, and thus the less the brightness. There is though one solution for this problem. You may choose to use smaller resistors than the calculated. This way, more current will flow within each LED and thus it will be brighter.

Be careful though! You don't want to go much above the nominal LED current allowed for two main reasons. First, the lifespan of the LED will be reduced. You may not notice the over-current situation by the brightness (because of the PWM effect), but this over current will certainly reduce the lifespan of the LED. And second, if the current is much too high above the nominal forward LED current and the microcontroller crashes for some reason, then the LED that is currently turned on will have a very hard time, for it will remain ON with full current flowing...




Charlieplexing also to interface buttons

Same as the classic matrix, the Charlieplexing technique can be used to interface buttons to a microcontroller. Here is a typical circuit to interface 6 buttons with only 3 microcontroller inputs:





The efficiency is unmatched. With 6 inputs, using the classic matrix method, up to 3x3=9 buttons can be interfaced, but with the Charlieplexing, a maximum of 6x(6-1)=30 buttons can be interfaced. To determine which button is pressed, the microcontroller must run a loop through all inputs. Each time, only one pin is defined as output and all others as inputs. Te inputs must be pulled HIGH or LOW. If the microcontroller supports internal pull-up resistors, then they can be used to minimize external components.

If the inputs are pulled-down, then the output pin is driven HIGH. The microcontroller then checks all inputs. If an input is found HIGH, then this means that a button is pressed. Each button corresponds to a specific Output-Input pair. Look at the following animation:





Manual 0.5 Sec  1 Sec  2 Sec 




This method has disadvantages and permanent ghosts

First if all, the diodes are mandatory for the circuit to operate normally. This makes the overall use more complex. But the most basic disadvantage it the ghosting. I have explained what the ghosting and masking problems are in the matrix theory, and i will not go through it again. Ghosting can also occur in the Charlieplexing method. In matrices, the ghosting can be solved by adding diodes to the buttons to prevent back current flow. But in charlieplexing, ghosting cannot be solved.

That is one good reason, why charlieplexing is not widely used, although it is so efficient. But still, it can be used in cases where only one button is pressed at a time. If for example you make a through-feed machine with multiple limit switches one after the other, you can safely use charlieplexing to interface them, as long as only one limit switch is activated at a time.







Comments

  Name

  Email (shall not be published)

  Website

Notify me of new posts via email


Write your comments below:
BEFORE you post a comment:You are welcome to comment for corrections and suggestions on this page. But if you have questions please use the forum instead to post it. Thank you.


      

  • At 14 February 2016, 16:13:19 user Sinjin wrote:   [reply @ Sinjin]
    • Great post! I've been looking for a good tutorial on Charlieplexing for a while and this one explains a lot. Thanks!


  • At 21 October 2015, 1:34:33 user stackoverflowrgb wrote:   [reply @ stackoverflowrgb]
    • You can eliminate ghosting of red leds in a matrix containing blue leds by placing a silicon diode in series with each red led. This will raise the turn-on voltage by 0.7 volts, preventing ghosting.


  • At 9 December 2012, 15:56:34 user zortharg wrote:   [reply @ zortharg]
    • "Charlieplexing", so arrogantly named after its "inventor" in 1995, is NOT new, nor was he the inventor, I have EE friends who were using it in the 1980s.

      You are also wrong that only one LED at a time can be displayed per display phase and wrong about where the resistors should be. You can turn on ANY combination of LEDs all at once.... so long as they share a common cathode or common anode. So you control n*(n-1) pins with n pins, and you can turn on the (n-1) pins sharing pin 0 as their cathode by having pin low, and pins 1 through n-1 high or hi-Z in any combination desired. Where should the resistors be? Well, the n pins should connect to the cathodes directly, and be fed through n resistors, and the other sides of the resistors should go to the anodes of the LEDs. That way, you use only n resistors total, and no matter how many LEDs sharing a common cathode come on together, they ALL get their own resistor, they don't all share the current that comes through a single resistor which would make them all dimmer if more than one is lit. That's the way it is done it in the Medworks clock (see http://www.medexamtools.com/calarm.htm and http://www.medexamtools.com/clock.htm). It displays AM/PM and the day of the week in the same phase, so that each LED is on at 25% duty cycle instead of 20.

      The only thing that needs to be bewared is the use of different color LEDs. A single green LED may, and a single blue WILL, develop enough voltage across it to turn on 2 reds in series.


  • At 13 April 2011, 12:42:45 user Fung wrote:   [reply @ Fung]
    • Emm...I cannot see the image of the "operation table" section, may be the URL of that image is incorrect?

      Also, I found problems in the Tech Blog entries, which is quite serious and annoying, could you please have a check?


  • At 8 April 2011, 5:44:36 user Kammenos wrote:   [reply @ Kammenos]
    • @Fung now it can be explained! When you half-push s1, it is neither 0 or 1. So, the input is left floating, and a floating input on a chip causes funny results, in your case it oscillates (which is absolutely normal). It is a good time to use pull-up resistor (remember you asked me in the dice circuit if the pull-up resistor is needed?). Put a 2.2K or 4.7K resistor between pin 2 of S1 and 5 volts. You can now disconnect pin 3 of S1 as it is no longer needed. You will see that the LED will not appear having both colors light.


  • At 8 April 2011, 5:31:35 user Fung wrote:   [reply @ Fung]
    • It is simply a quad gate, no pulses is provided, this LED is connected to 3 NAND gates of the chip, here is the schematic of these gates connection I have used in the circuit:
      http://i155.photobucket.com/albums/s304/mickeyfung_12/temporary/drive_bi-polar.png

      With 1 gate unused.

      When S1 connects to Vdd, the LED lights green; while it lights red if S1 connects to 0V. However, when I pushed a half of S1, it lights both red and green. Can it be considered as "logic undefined"?


  • At 7 April 2011, 14:26:36 user Kammenos wrote:   [reply @ Kammenos]
    • @Fung oh yes, sure, you are right. I confused them with bi-color. I have not test the bi-polar LEDs. I suppose that inside they have 2 LEDs connected anti-parallel... But i am not sure.
      Regarding the 74HC00, this is rather strange. Tell me, this chip provides pules? it could be possible, if it changes its ouputs. If you connect for example the LED in Q1 and Q2 and Q1 becomes 1 whenever Q2 becomes 0 and vice versa, and this is done very fast, then the effect that you would see is both LEDs light.


  • At 7 April 2011, 13:57:43 user Fung wrote:   [reply @ Fung]
    • Emm...that "bi-polar" LED I mention has 2 pins only, with no common pole (neither cathode nor anode), both connecting direction causes any one of the LED chip light up, either red or green. Because the circuit in this LED is same as the diagram you state in this page.

      The proof:
      http://i155.photobucket.com/albums/s304/mickeyfung_12/temporary/bp_LEDs.jpg

      I usually call those common anode or common cathode are "bi-color" LEDs because they have 2 color LED chips and same common pole.

      Also, I am going to know that is this type of multiplexing applicable for dual color LED message displays?

      ----
      Seems that I need to provide some photos to show the situation regarding the 74HC00.

      Look at this first:
      http://i155.photobucket.com/albums/s304/mickeyfung_12/temporary/undefined_logic.jpg

      The IC next to it is 74HC00.


  • At 7 April 2011, 12:40:34 user Kammenos wrote:   [reply @ Kammenos]
    • @Fung the bipolar LED is not replacement to the anti-parallel LEDs. A bi-polar has a common anode or common cathode, not the anode and the cathode connected together. You can use of course such LEDs (to replace the parallel connected LEDs), but not to replace anti-parallel connected LEDs.
      I suppose you can go to higher frequencies, maybe higher than 100 Hz. I will run some experiments shortly with this method and i will post the results.
      regarding the 74HC question, i did not understand it. It is able to power 2 leds, why shouldn't it?


  • At 7 April 2011, 7:33:06 user Fung wrote:   [reply @ Fung]
    • A bi-polar LED may be a good substitution of 2 LEDs in anti-parallel.

      Is the Charlieplexing usually apply to operate bi-polar LEDs or 2 LEDs in anti-parallel? How about the LEDs connected in parallel?

      Is higher frequency (eg 100Hz) not allowed in Charlieplexing? Because of the PWM effect?

      Also, for the bi-polar LEDs, a logic gate-based test (74HC00) proved that it is possible to make both chips of a bi-polar LED to turn on, do you know why?



    delicious
    digg
    reddit this Reddit this
    Faves



     HOT in heaven!


    NEW in heaven!



    New Theory: AC electric motor working principle



     Contact     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS   

    Site design: Giorgos Lazaridis
    © Copyright 2008
    Please read the Terms of services and the Privacy policy