Charlieplexing RGB LEDs?

Discussion in 'General Electronics Chat' started by johan, Oct 29, 2008.

  1. johan

    Thread Starter Member

    Oct 25, 2008
    12
    0
    I need 4 RGB LEDs for my next project. In theory you should be able to charlieplex these with 4 pins on an MCU. I just realized though that maybe it won't work since the LEDs have common cathode or anode pins.

    Will it still work or do I need more pins? I can order both common cathode and common anode LEDs if it helps (maybe 50/50 or something).
     
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Yes you can switch the leds in sequence at a fast rate as your eyes see that they are always on due to the effect of the persistence of vision. Until now you will need 4 pins. Also, you will need another 3 pins to determine which colour the leds will emit each time it is switch on.
    If they are common cathode you will switch the cathode of the first led to ground and use the other led pins to determine the colour by applying a positive voltage, then switch it off by making the cathode voltage positive and switch the next led cathode to ground, determine its colour and so on. The same works for common anode but with the voltages interchanged.

    If you dont belive that this works check my spectrum analyzer here:

    http://www.youtube.com/watch?v=j-4h3l9O4fc

    I switch each column in sequence in a fast rate and control which leds on the column turn on ech time, thus i can control 100 leds with just only 20 pins of the microcontroller.
     
  3. johan

    Thread Starter Member

    Oct 25, 2008
    12
    0
    Thank you, that makes a lot of sense. So I will need 7 pins for this to work? I'm running out of pins :eek: Gonna have to figure out a way to make the switches run on fewer pins.

    That video is really cool. I bet the whole thing must have taken ages to build though :D
     
  4. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    No, it took me a week to design the circuit on a PCB design software and about 3 days to solder the components on the PCB board. Also, the programming of the microcontroller took me 2 days.

    If you want to use fewer pins you can do it by using a 2 to four channel decoder like this one here:

    http://en.wikipedia.org/wiki/Decoder

    You will be able to drive four leds by using only 2 pins
     
  5. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    edn.com had a recent article on how to read an array of switches into a uC using just one of the uC's pins. Unfortunately, their site is down for maintenance at the moment.

    Basically, it used a parallel load shift register, some inverters, caps, resistors and diodes. The single uC pin was used as both input and output. If the uC pin were held low for a relatively long period, it would cause the shift register to load the states of 8 switches. The uC pin would then be held low for a short period of time, then changed back to an input to read the bits, one cycle per bit.

    Try the site later on today. This link should get you to the index of ideas:
    http://www.edn.com/index.asp?layout=news&spacedesc=designIdeas
    [eta]
    I've attached the relevant Design Ideas digest. See the last two pages of the .PDF document.
    Note that BAT54 diodes are used; these are Schottky diodes with a Vf of 0.32v. Standard diodes such as 1N4148, etc. would not work as well due to the comparatively high Vf.
     
    Last edited: Oct 29, 2008
  6. johan

    Thread Starter Member

    Oct 25, 2008
    12
    0
    Hmm, yeah I've thought about using shift registers/decoders/something similar but I like the idea of using multiplexing since only LED will be on at a time. 20mA current draw is better than 240mA.

    The problem I have is that I am running out of pins. I could upgrade to a bigger microcontroller but maybe there's some way of merging some other things together?

    I currently have 3 switches, 3 potentiometers, 2 rotary encoders (2-bit) and one pin for an LFO. Can I merge some of that stuff together in some sort of clever way?
     
  7. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Did you look at that EDN article I posted?

    I'm not talking about using shift registers, etc. for the RGB LEDs; I'm talking about the inputs.

    You could take care of the 3 switches and two rotary encoders that way. Seven bits handled with a single I/O pin.
     
    Last edited: Oct 29, 2008
  8. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Which microcontroller are you using?
     
  9. johan

    Thread Starter Member

    Oct 25, 2008
    12
    0
    I did. The stuff was a bit over my head, but now when you say that it's for switches everything makes a whole lot more sense. I will definitely do some reading, the idea of only needing 1 pin for all that really does make me interested.

    I'm only in the "design stage" yet so it's not set in stone. I'm thinking the ATmega168 though.

    *edit*

    I also found this: http://www.instructables.com/id/A-CharliePlexed-RGB-LED-Dice/
    Maybe I can get it down to only 3 pins if I only need 4 RGB LEDs.
     
  10. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    If you havent bought the microcontroller yet, its better to choose another one with more pins to make your life easier. Believe me it will be much easier and you will require less wiring and PCB space. Also, by using only the uC to control the circuit you can change the program anytime without changing any parts on the PCB, that's one of the advantages of programmable controllers.
     
  11. johan

    Thread Starter Member

    Oct 25, 2008
    12
    0
    I should. It's just that I would have liked the option of running the arduino bootloader to make my life easier.

    I will take a look at the multiple-switches-on-one-pin-thing SgtWookie gave me and if that end up making sense to me, I'll have 10 or more pins for the LEDs which should be way more manageable than what I have now.

    But if not, I might have to get something else. ATmega32 maybe?
     
  12. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    The circuit I suggested is a work-around hardware solution; basically a "for your information" kind of thing.

    It adds complexity to the board, and reduces reliability along with increasing assembly difficulty and component count.

    If you can use a single uC that has more pins to accomplish what you need to do, you will be much better off. With a single uC, you can change configurations via software "on the fly" aka no cutting traces and adding wires/components/etc. Once you chain yourself to a hardware configuration, you're pretty much stuck.

    While it may seem daunting at the moment, software changes are much easier to accomplish than hardware changes.

    Make sure you include provisions for re-programming your uC while it's in situ aka installed on the board. If you try to use a socket, you'll wind up breaking pins off of the uC after a half-dozen tries (maybe less), and you'll hate yourself.
     
  13. johan

    Thread Starter Member

    Oct 25, 2008
    12
    0
    Yep. The problem is that the 40-pin version of the ATmega is huge compared to the 28-pin version I was going to use. It's not just an extra 6 rows of pins but it's also much deeper. I'm not sure if it'll fit on the PCB unless I'll make it bigger (something that my freeware version of Eagle doesn't allow).

    So I'm not sure what I'll do.
     
  14. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    The microcontroller is bigger than the previous one but if you use the smaller uC and decoder chips then the circuit will get much bigger than using one big uC.
     
Loading...