Connect with us

how to control LED array?

Discussion in 'Electronic Basics' started by Michael Noone, Apr 24, 2005.

Scroll to continue with content
  1. Hi - I'm working on a project to make an 8x8 LED array. The idea is that
    the anodes in each row are tied together, and the cathodes in each column
    are attached together, giving me 16 pins which I can control 64 LEDs with.
    But now the only problem is making sure they get the right current/voltage?
    My plan is to only have one column turned on at any given time, but then
    any number of the 8 LEDs in that column could be on at that time, so things
    get a little difficult. I could apply 0 and 5V then just have a current
    limiting resistor on each LED, but that would be cumbersome and awkward. My
    end goal is to be able to drive this with 16 pins from a microcontroller.
    Hopefully I'm being somewhat clear about what I'm asking. Does anybody have
    any suggestions as to how I could do this? Thanks so much,

    Michael J. Noone
  2. John Fields

    John Fields Guest

  3. Hi Mr. Fields - I'd like to control as many at a time as possible. My plan
    was to control one column at a time, and cycle through each column about
    100 times per second. Does this seem like a good path to take, or is there
    a better way to accomplish this? I thought that this method would allow the
    board to be fairly simple (anode traces on the top of the board, cathode
    traces on the bottom), and would be fairly easy to control (just 16 control
    lines). Thanks,

    -Michael. J Noone
  4. Lord Garth

    Lord Garth Guest

    As you cycle through each column, only one LED per row is on at any given
    You would put your limit resistors in the row line after an appropriate
    You are multiplexing the array. I suggest you use a 1 of 8 demux chip such
    as the
    74138. The chip is fed by a binary counter. You clock the counter with 1
    bit from
    your port. This saves IO lines. You can create a clock on the Data Strobe*
    pin 1 of
    the parallel port. Any clock rate over 16 or so pulses per second is no
    necessary as the
    eye will blend the image. Faster is not better as it gives you a shorter
    time slot in which
    to write the active LEDs. You can read the counter overflow on one of the
    input bits
    such as paper empty.

    There are also specialty chips for doing this very thing to sets of such
    displays. Maxim
    comes to mind, I think their chip, in no decode mode, will handle 128 lamp
    That is 16) 8x8 arrays.
  5. Bob Eldred

    Bob Eldred Guest

    You have the right idea. With the 8 cathodes connected to the 8 column
    lines, you have the micro make one column at a time go low, the one being
    lit. All the others are high. Sequencing through the columns at 100 times
    per second is fine. It should be fast enough that you can't see flicker.
    Now, the anodes, row lines can be driven so that only one led is on at a
    time which means that only one of 64 led's is lit at a time but this makes a
    dim display. A better solution is to turn on all of the rows for all of the
    anodes needed in any given column at once and leave them on for the duration
    of that column. To turn on the anodes make them high and off low, the
    opposite of the column drives which are on low and off high. In this way up
    to 8 LED's may be on at a time in one column and the LED's are on for 1/8 of
    the total time. Since only one column is on at a time, only 8 current
    limiting resistors are required and they are placed on the row drivers for
    the anodes. As you sequence through the columns, you set up the required row
    pattern to light the LED's of each column in turn. There are many ways that
    this can be set up but one way is to mirror the matrix in memory. This would
    take 8 bytes with the bit patterns representing the rows. As the columns are
    sequenced through, the bytes are transferred one at a time, in turn, to the
    row port.
  6. John Fields

    John Fields Guest

    The problems I see with doing it
  7. John Fields

    John Fields Guest


    If we set up a 4X4 array for the sake of simplicity, then using your
    row-column scheme with common anode rows would yield this:

    A| A| A| A|
    [LED] [LED] [LED] [LED]
    | | | |
    +---+ +---+ +---+ +---+
    | | | |
    | +----|---+----|---+----|---+----C2
    | A| | A| | A| | A|
    | [LED] | [LED] | [LED] | [LED]
    | | | | | | | |
    +---+ +---+ +---+ +---+
    | | | |
    | +----|---+----|---+----|---+----C3
    | A| | A| | A| | A|
    | [LED] | [LED] | [LED] | [LED]
    | | | | | | | |
    +---+ +---+ +---+ +---+
    | | | |
    | +----|---+----|---+----|---+----C4
    | A| | A| | A| | A|
    | [LED] | [LED] | [LED] | [LED]
    | | | | | | | |
    +---+ +---+ +---+ +---+
    | | | |
    C1 C2 C3 C4

    Then, adding the drivers:

    2N4403 |
    +--------+--------+--------+----C E--[R]--+
    A| A| A| A| B |
    [LED] [LED] [LED] [LED] | | _
    1,1| 1,2| 1,3| 1,4| +----[R]--|---<R1
    +---+ +---+ +---+ +---+ |
    | | | | 2N4403 |
    | +----|---+----|---+----|---+----C E--[R]--+
    | A| | A| | A| | A| B |
    | [LED] | [LED] | [LED] | [LED] | | _
    |2,1| |2,2| |2,3| |2,4| +----[R]--|---<R2
    +---+ +---+ +---+ +---+ |
    | | | | 2N4403 |
    | +----|---+----|---+----|---+----C E--[R]--+
    | A| | A| | A| | A| B |
    | [LED] | [LED] | [LED] | [LED] | | _
    |3,1| |3,2| |3,3| |3,4| +----[R]--|---<R3
    +---+ +---+ +---+ +---+ |
    | | | | 2N4403 |
    | +----|---+----|---+----|---+----C E--[R]--+
    | A| | A| | A| | A| B
    | [LED] | [LED] | [LED] | [LED] | _
    |4,1| |4,2| |4,3| |4,4| +----[R]------<R4
    +---+ +---+ +---+ +---+
    | | | |
    |2N4401 |2N4401 |2N4401 |2N4401
    C E-+ C E-+ C E-+ C E-+
    B | B | B | B |
    | | | | | | | |
    | +----|---+----|---+----|---+
    | | | | +-------------[R]------<C4
    | GND | |
    | | +----------------------[R]------<C3
    | |
    | +-------------------------------[R]------<C2

    Now, if you wanted to illuminate the LED at 1,1 what you would do
    would be to pull R1 low and C1 high. Likewise, for any LED in the
    matrix you'd have to pull the row at its location low and the column
    at its location high.

    The display will need to be multiplexed, and the most efficient way to
    do that would be to broadside data, a byte at a time, into the row
    drivers and then to scan the columns. If you want to make a
    non-flickering display, then the pixel update rate should be somewhat
    higher than 30Hz, say 50Hz just to make sure. That means that since
    you have eight columns an you have to refresh every pixel 50 times per
    second, you'll be scanning columns eight times faster than that, or at
    400Hz. Duck soup. However, it also means that since each LED will
    only be illuminated for 1/8 of the time it will have to be made 8
    times brighter for it to seem to be as bright as if it were on all the
    time. If you use 20mA LEDs with 2N4401s and 2N4403s for drivers that
    won't be a problem, but driving the LEDs with 160mA might be. You
    need to look at the LED duty cycle amd maximum input current spec's to
    be sure.

    Assuming a 5V supply and 2V LEDs, the current limiting resistors come
    out to be:

    (V+) - Vled 2V
    R = ------------- = ------- = 12.5 ohms
    Iled 0.16A

    The next higher closest standard 5% value is 13 ohms, so with 2 volts
    across it it'll allow:

    I = ----- ~0.154 amperes

    Since all the lamps in a row could be on, one at a time with no
    off-time between them, that means the resistor would be passing 154mA
    all of the time, so it would be dissipating:

    P = IE = 0.154A * 2V ~ 0.308 watts

    So a half-watt resistor would be OK.

    I don't know how much current you have available from your micro's
    I/Os, but assuming you ran the drivers with a forced beta of 50, for a
    maximum collector current of 154mA, your base current would be about
    3mA, so with a 0.7V drop across the base-to-emitter junction you could

    R = -------- ~ 233 ohms,

    the next lower standard 5% value, 220 ohms, would be fine if your
    micro could supply 3.18mA.

    The goal is to get as much current as you can out of the I/O in order
    to make sure the transistors go into saturation so that you get the
    smallest possible voltage drop across their collector-to-emitter
  8. I can't believe I never realized that. Now it seems so simple and
    obvious - but before I was struggling trying to figure out how to limit
    Correct me if I'm wrong though, but wouldn't that require an extra two
    chips? I had been thinking that if I wanted to decrease control lines I
    could use an 8b shift register with parallel output to drive them.
    I should mention that I don't plan on using a computer to drive this
    array - my plan was for it to be entirely microcontroller driven.
    Do you have any idea of a part number for such a chip? I looked through
    their LED display driver chip section, but most all of them looked more
    like they were designed for controlling digits, not arrays. Also - any
    idea if any would be able to do PWM? Does this chip perhaps look right?


    -Michael Noone
  9. I don't entirely follow your calculations here. If you had the current
    limiting resistors on the row drivers, wouldn't you then want to turn on
    column by column so the current limiting resistor would only be limiting
    current for 1 LED? (as mr Garth suggested) That way you wouldn't have to
    worry about not all 8 LEDs being on. Also, I'm not entirely sure how
    you're getting the voltage that you'd need to dissipate? I was thinking
    that you'd subtract (2 * Vcesat + Vled) from the supply voltage (5V). So
    wouldn't that be 5 - 2 * 0.4 - 2.0 = 2.2V?
    Again - why would you use a resistor on the set of 8 LEDs being driven,
    instead of one per driven LED? I expect you do have a reason for this -
    I just am having trouble figuring out what it is.
    I believe most AVRs (the type of uC that I'm currently using) can sync
    about 30ma on each I/O line. Certainly 3ma would not present even the
    slightest problem.

    Mr. Fields - thanks for all your help. You have helped me in the past as
    well, and your help is always very much appreciated.

    Best regards,

  10. I disagree on the refresh rate. Having just experimented with PWM on
    some RGB LEDs, I can attest to the fact that 40Hz refresh is easily
    visible as flicker at very low duty cycles. You _will_ see the annoying
    flickering. I suggest using at least 80Hz for completely flicker free
    operation. Before you get all upset, I know it seems awfully high
    compared to what's acceptible for TV and movies, but I assure you that
    the flicker is much more visible on the LEDs. There is plenty of advice
    on the net about using refresh rates around 100Hz for this very reason.
    Just commenting for the benefit of the OP.

    Of course if the OP doesn't need low intensity levels, then a slower
    refresh may be fine.
  11. Lord Garth

    Lord Garth Guest

    I was just thinking that a column multiplexing scheme as opposed to
    a row multiplexing scheme would be more likely to show strobing
    as one drove by. Is this indeed the case? (not that this is at all a
    to the OP and his 8x8 array)
  12. I don't know if that would make any difference. My experiments were
    with only one LED and flickering was clearly visible at >40Hz refresh
    combined with low duty cycles. [I was using a software based 8 bit PWM
    routine (~25mS period with ~100uS resolution)] When I upped the clock
    speed to 8Mhz so that the period was ~12.5mS with ~50uS resolution the
    flicker was not visible to me even with a 1/256 duty cycle. I was also
    surprised by the brightness of the LED at 1/256 duty cycle, it was
    clearly visible.

    Disclaimer: I know that a linear duty cycle is not the most appropriate
    method of PWM driving an LED, but it was easy to implement. With the
    ISR running every 50uS, you don't have allot of time to jack around.

    Using an 8Mhz internally clocked 16F88, I was able to achieve my goal of
    imperceptibly varying the colors of an RGB LED, in a rainbow like
    fashion, without generating shades of grey, or taking a week to cycle
    thru all 16 million combinations. No biggy, but it looks allot better
    than those cheesy things with the built in color sequencer. ;-) My 10
    month old daughter really likes the effect and IMO it's going to look
    really good on my scooter as full-color, adjustable accent lighting.
  13. Lord Garth

    Lord Garth Guest

    Remember that certain color lights are illegal on personal
    vary however.
  14. Yep, but that's only when in motion on the road. And certain colors are
    only illegal from certain directions. AIUI, the law (here in TX) is
    such that the lights need to be directly visible to be considered
    illegal, hence the lights are carefully mounted so that only the
    reflection is visible (accent style). Of course that doesn't hurt the
    looks of things either. ;-)

    Since I want adjustable colors, I should be able to pick a nice color
    like yellow/green or amber (no real limit on those lights) for maximum
    visibility when riding and then a nice magenta, cyan, deep blue or the
    ever popular rainbow effect for parking. :)

    I also made a little doo-dad to replace the factory turn-signal module.
    It maintains full backward compatibility, has smarter self canceling,
    and converts the rear turns to running lights using PWM. The blink rate
    is insensitive to the bulb load (like God intended ;-) and the bulb
    drivers are short-circuit proof. It also has a nifty strobe mode for
    maximum attention grab _and_ 4-way flashing.

    FWICT, the DOT regs (fed and state) don't care if I strobe the turns
    instead of flashing them at a regular interval. They seem to only care
    about the number of flashes per minute, not their regularity. I guess
    that's why there's a ton of non-emergency vehicles on the road with
    strobing turn signals.

    If a stupid, chickensh*t, p*ssy hobbyist can build stuff like this with
    a PIC, just think what someone with half a brain could do.

  15. Lord Garth

    Lord Garth Guest

    Why the heck don't you post your circuits and source code...there have
    been questions regarding rainbow effects in the past. Besides, I'd like
    to see how you protect the PIC from the crappy power in a car.
  16. TVSP's are probably the best things that I know of, but a nice choke,
    some series resistance, a Zener or two followed by a 5V regulator and
    some more filtering mixed with plenty of bypass caps should do it for
    you with a PIC. Commonly available high side drivers are responsible
    for the output magic. Resistance, bypass caps and Zeners on input lines
    to feed 12V signals into 5V inputs. May be kinda sloppy, but it works
    well enough. The so-called nano-watt series PICs can be very
    unforgiving of power supply issues.

    While I've given up some good code for public usage in the past, the
    stuff for my turn-signal doo-dad is not for free. Too much effort
    combined with real commercial value. I posted a version of my rainbow
    LED code to A.B.S.E.
  17. Lord Garth

    Lord Garth Guest

    I got the post thanks....

    For me, I don't plug things in until the car is running. Once, my cap
    dried up and exploded. That car smelled for quite a while.
  18. John Fields

    John Fields Guest

    2N4403 |
    +--------+--------+--------+-[13R]-C E-------+
    A| A| A| A| B |
    [LED] [LED] [LED] [LED] | | _
    1,1| 1,2| 1,3| 1,4| +----[R]--|---<R1
    +---+ +---+ +---+ +---+ |
    | | | | 2N4403 |
    | +----|---+----|---+----|---+-[13R]-C E-------+
    | A| | A| | A| | A| B |
    | [LED] | [LED] | [LED] | [LED] | | _
    |2,1| |2,2| |2,3| |2,4| +----[R]--|---<R2
    +---+ +---+ +---+ +---+ |
    | | | | 2N4403 |
    | +----|---+----|---+----|---+-[13R]-C E-------+
    | A| | A| | A| | A| B |
    | [LED] | [LED] | [LED] | [LED] | | _
    |3,1| |3,2| |3,3| |3,4| +----[R]--|---<R3
    +---+ +---+ +---+ +---+ |
    | | | | 2N4403 |
    | +----|---+----|---+----|---+-[13R]-C E-------+
    | A| | A| | A| | A| B
    | [LED] | [LED] | [LED] | [LED] | _
    |4,1| |4,2| |4,3| |4,4| +----[R]------<R4
    +---+ +---+ +---+ +---+
    | | | |
    |2N4401 |2N4401 |2N4401 |2N4401
    C E-+ C E-+ C E-+ C E-+
    B | B | B | B |
    | | | | | | | |
    | +----|---+----|---+----|---+
    | | | | +-------------[R]------<C4
    | GND | |
    | | +----------------------[R]------<C3
    | |
    | +-------------------------------[R]------<C2

    Yes, of course, and they _are_ on the row drivers, although they were
    shown in the wrong place. I showed them on the emitters of the 2N4403s
    when they should have been on the collector side. I've corrected that
    on the schematic above.
    More or less... I added in the two Vcesat's at 0.5V each for 160mA in
    my head but, sloppily, didn't write them down, so:

    (V+) - Vled 2V
    R = ------------- = ------- = 12.5 ohms
    Iled 0.16A

    Should have read:

    (V+) - (Vled + 2*Vcesat) 2V
    R = -------------------------- = ------- = 12.5 ohms
    Iled 0.16A
    The row drivers connect the series limiting resistors to all of the
    LED anodes in that row, but only the active column will have its LED
    cathodes grounded through the column driver. That means that if you
    connect V+ (5V in this case) to all of the LED anodes in the array by
    pulling all the row driver bases low, only the column with the column
    driver's base pulled high will have its LEDs illuminated. The rest of
    the LEDs will remain unlit because their columns will not yet have
    become active. When they do, each in its own time slot, then its LEDs
    will light when the previous column's turn off, and all the rest will
    remain unlit until it's their turn to shine.
    Excellent! In that case, in order to run the drivers with a forced
    beta of ten and totally insure that they'll be running saturated,
    you'll need to put 16mA into their bases, so with a Vbesat of 1.2V,
    you'll need:

    5V - 1.2V
    R = ----------- ~ 240 ohms

    for the base resistors.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day