SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By Morrog
#30357
For one of my projects I need to individually control up to 128 LEDs, perhaps even more. I'm still pretty new to this, so I'd appreciate someone looking over my rough design real quick to see if it'll work.

My design will work similar to Spark Fun's giant clock project. There are 8 lines which describe LED states, aka Control lines. Then there are 5 Driver lines.

The 5 driver lines connect to a 1:32 demux as select lines. The outputs on the demux connect to the Clock line on 32 different Octal D-flip flop chips. The Control lines go to all 32 Octal D-flip flop chips. Each flip flop is connected to a darlington array, which is connected to 8 LEDs.

So the PIC uses its driver lines to select a flip flop bank to control. It sets up the control lines for that bank, pulses the clock, and then goes to the next bank. This is repeated whenever an LED or more needs to change state.


Does that all sound like it should work? Again, I'm still new to this stuff so go easy on me.

Parts:
D-type flip-flop
Darl Transis. Array
1:8 demux
hex inverter
The demuxes will be connected together to form the 1:32 demux. inverter is needed because the outputs of the demux are complements.

Any help is greatly appreciated!
User avatar
By bigglez
#30364
Morrog wrote:There are 8 lines which describe LED states, aka Control lines. Then there are 5 Driver lines.

The 5 driver lines connect to a 1:32 demux as select lines. The outputs on the demux connect to the Clock line on 32 different Octal D-flip flop chips. The Control lines go to all 32 Octal D-flip flop chips. Each flip flop is connected to a darlington array, which is connected to 8 LEDs.

So the PIC uses its driver lines to select a flip flop bank to control. It sets up the control lines for that bank, pulses the clock, and then goes to the next bank. This is repeated whenever an LED or more needs to change state.

Does that all sound like it should work? Again, I'm still new to this stuff so go easy on me.
Greetings morrog,

Your scheme is sound and should work as described. Good Job! There's a few gaps in the spec you've given which might cause some issues with the project.

(1) How fast do the LEDs change? Video images? Static patterns? Text? Scrolling text? (Hint: how long does it take to change every LED?).
(2) Are the LEDs only ON-OFF or do you expect to dim them (grey-scale or half-tone imaging)?
(3) Does it matter that when all LEDs are on there will likely be shading (brightness variations)?
(4) Your hardware will take quite a bit of space, there are chips with higher levels of integration, that are used in commercial LED video and messaging arrays.
(5) Are these special LEDs? If not, with only one LED connected to it's own driver you can use CMOS logic and eliminate the darlington drivers.
(6) Aranging the display (any display) as a grid (m*n) instead of linear array (1*n) greatly reduces the number of drivers needed:

For a 1*n display where n=128 you'll need 128 drivers, and a minimum of 2^7 IO lines for addressing. This is 16 bytes of data.

For an m*n array (where m*n = 128) you'll only need 24 drivers, such as 16*8 (8 + 16 = 24). This is only three bytes of data.

(7) Instead of clocking the flip-flops after the demux (if I've understood your scheme) why not clock all the flip-flops at once? Better yet, have two sets of flip-flops in cascade, the second one supports the LED outputs while the first one is loaded with new data. A master clock transfers the new data to the output flip-flops all at once. The input flip-flops can be serially connected and therefore you'll only need three IO pins on the uC (serial data, serial clock, output load).

(8) The m*n array can be further reduced using "Charlieplexing".

Comments Welcome!
By jasonharper
#30366
This could be made to work, the only problem is that the darlington array you linked to isn't appropriate for the job - you want ULN2803 to drive 8 outputs from 5V logic, ULN2004 is 7 outputs from 6-15V logic.

And I'm sure that whoever you buy the parts from will love you for it - 74 ICs total, if I'm counting correctly!

If you must have each ON LED be on for 100% of the time, consider using shift registers such as the 74HC595. 32 of those, plus your PIC, would do the entire job (although you might want to add a buffer chip or two for the signals that have to go to all the shift registers in parallel). You can reduce the chip count by using drivers with more outputs, perhaps down to 3 chips total if you can solder a TQFP-80 package...

The usual way of driving lots of outputs is via multiplexing. You'd wire your LEDs as a matrix, with only one row (or perhaps column) actually being lit at a time, at higher brightness. If you go through all the rows 100 times per second or so, lit LEDs will appear to be constantly on. This can be done with a combination of ULN2x03's for the axis that drives the LED cathodes, and the corresponding high-side driver (I forget the part numbers) for the anode axis. There are also controller chips that will handle all the multiplexing for you - take a look at the MAX7219, MAX7221, or MAX6951. Two of those (16 pin chips, I think), plus your PIC, would do the job. You don't even need individual LED current limiting resistors with those chips.
By Morrog
#30369
Thanks for all the help and comments! I really appreciate it :)
(1) How fast do the LEDs change? Video images? Static patterns? Text? Scrolling text? (Hint: how long does it take to change every LED?).
Something like video, but less intensive. I'm going to sync the LEDs to music. So I guess the switching should be around 30FPS.
(2) Are the LEDs only ON-OFF or do you expect to dim them (grey-scale or half-tone imaging)?
Grey-scale would be cool, but not necessary. I figure if I can switch them fast enough I can just use PWM to take care of that.

3) Doesn't matter to me. As long as it looks good enough.

5) Just standard LEDs.

6) Well the demux+flip-flop should allow me to have a total of 256 drivers from just 14 lines.
If you must have each ON LED be on for 100% of the time, consider using shift registers such as the 74HC595.
Okay, I read up on those. If I were to take that approach, I'd hook up the SER of the 2nd shift register to the Q'h of the first, and so on? And then whenever I want to update an LED's state I'd need to refresh the entire thing? Clock through all 128 or more bits of information? I guess that wouldn't be too bad ...

That shift register approach seems cheaper than using two display drivers.

So would I hook up the shift register outputs to a darlington array to power the LEDs?

Here's the new part list for that setup:
Darlington Array ULN2803
Shift reigster, 74HC595

Guess I'll have to solder the darlington arrays since they aren't DIP.

Again, thanks a lot for the help. I hope I got that shift register thing right, that would be a really easy solution!
By jasonharper
#30371
Yes, with shift registers you have to update the whole thing each time. Choose a PIC with a SPI or synchronous serial peripheral, and this becomes trivial - just write bytes to the peripheral, and let it shift out the bits one by one.

The 74HC595 has a fairly high drive current spec, as I recall - it can drive the LEDs directly, although perhaps not at maximum brightness (and if that's the case, look for shift registers with higher current, try TPICB595, TPICC595 I think). You will need a current limiting resistor per LED - one advantage of the specialized LED driver chips is that they can set the current for all LEDs with a single resistor.

ULN2803's are definitely available in DIP-18 packages, although you shouldn't need them with appropriate choice of shift registers.
By Morrog
#30374
Oh, I just assumed it wasn't going to be able to pump that much current but according to this datasheet
"DC Output Current, per pin (Iout) ±35 mA"
"DC Vcc or GND Current, per pin (Icc) ±70 mA"

Each LED only needs 20mA, so that should cover it, right?

Two more question then, just so I'm sure on everything:
The output will be 5V (4.5V input, datasheet says Vcc+0.5V) at the pin, right? So for a 1.5V@20mA LED I'd need a 175Ohm resistor?

Why can't I just put the resistor on the GND line going to all the LEDs?


Again, thanks for the help. I can't wait to start building this project.
User avatar
By bigglez
#30379
Morrog wrote:Oh, I just assumed it wasn't going to be able to pump that much current but according to this datasheet
"DC Output Current, per pin (Iout) ±35 mA"
"DC Vcc or GND Current, per pin (Icc) ±70 mA"
morrog,

Don't confuse abs max with recommended operating values. You might get something to work on the bench at or above the abs max. but it may not be reliable or reproducible. Use the recommended values here.
Morrog wrote:Each LED only needs 20mA, so that should cover it, right?
The cd74hc595 is spec'd to 7.8mA. Perhaps your LEDs need more current? Again, 20mA is an abs max spec.
Morrog wrote:Two more question then, just so I'm sure on everything:
The output will be 5V (4.5V input, datasheet says Vcc+0.5V) at the pin, right?
No. Output logic high voltage will be always be lower than the supply, regardless of input voltage. The logic high voltage is assumed to be within 500mV of the rail, but depending upon load, could be less. See the data sheet. If you are only driving an LED (and not more logic) from the output you can load the device further, but watch out for power dissipation in the device, more so if you are loading multiple outputs at the same time.

Always design for the worse case.
Morrog wrote:So for a 1.5V@20mA LED I'd need a 175Ohm resistor?
5.25 (VDD upper spec) - 1.5 (LED Vf) / Iled = 187.5 ohms (use 180).

Once again, you probably don't want to be at 20mA.
Morrog wrote:Why can't I just put the resistor on the GND line going to all the LEDs?
Because the resistor is for one LED. There might be an except if the LEDs are MUX'd as noted here. In a single LED case you can place the resistor anywhere in the loop (supply to LED, LED to driver, Driver to ground*).

*If the driver is an IC take care not to raise the ground pin voltage.

Comments Welcome!
User avatar
By bigglez
#30380
Morrog wrote:
bigglez wrote: (1) How fast do the LEDs change? Video images? Static patterns? Text? Scrolling text? (Hint: how long does it take to change every LED?).
Something like video, but less intensive. I'm going to sync the LEDs to music. So I guess the switching should be around 30FPS.
So the minimum refresh rate of 30FPS times the number of LEDs (128) means that the data 'frame' is 3.8kHz (260us).
Morrog wrote:
bigglez wrote: (2) Are the LEDs only ON-OFF or do you expect to dim them (grey-scale or half-tone imaging)?
Grey-scale would be cool, but not necessary. I figure if I can switch them fast enough I can just use PWM to take care of that.
If you PWM each channel you must send all the data at a multiple of the static data frame rate, depending upon how much resolution you need for PWM.

At eight levels (3 bits) the new data rate will be 30.72KHz (32.6us).

This is well within the range of a uC and CMOS logic. Commerical LED matrix drivers typically operate at a 5MHz data clock.

Comments Welcome!
By Philba
#30383
Different datasheets spec the limits on the 74HC595 (and HC series in general) at wildly different values. I've driven lots of LEDs directly from the '595 with no problems at all. I deliberately set up 8 LEDs driven from one 595 SOIC to 10 mA each (80 mA total) and the chip didn't heat up at all - I let it run overnight. It was a Fairchild part. I didn't test to 20 mA but it wouldn't surprise me if it handles that. worth trying - the worst that can happen is you are out 32 cents...

BTW, use a series current limiter on the inputs (1-10K) and a high value pull down (500K or so) to ground as the inputs can be very susceptible to high current draw. I kept blowing '595s until I did that.
By Morrog
#30386
Well I'll order a small sampling of all the components I need tonight and test things out.
BTW, use a series current limiter on the inputs (1-10K) and a high value pull down (500K or so) to ground as the inputs can be very susceptible to high current draw. I kept blowing '595s until I did that.
Could you explain further, please? I know to put a resistor between each pin of the output on the shift register and each LED. Did you mean something else?


Two extra questions:
How would I go about getting a voltage regulator that can handle more than 1A of current? All the VREGs I find are rated for 1A. If I have 128 LEDs on at once that's about 2.6Amps. Can I put a couple in parallel?

Also, do those AA battery holders put the batteries in series or parallel? I'm gonna need to put 8 AA NiMH batteries in series to get enough voltage to hook into a 5V VREG.
User avatar
By bigglez
#30389
Morrog wrote:
BTW, use a series current limiter on the inputs (1-10K) and a high value pull down (500K or so) to ground as the inputs can be very susceptible to high current draw. I kept blowing '595s until I did that.
Could you explain further, please? I know to put a resistor between each pin of the output on the shift register and each LED. Did you mean something else?
Morrog,

The series resistor for the LED is to limit the current (in the LED) to a safe level. Too much current will damage the LED (either dead, weak light output, or a "no-light emitting diode").

CMOS logic can latch up due to the parastitic diodes at the inputs. This condition is often fatal, as too much current flows in the input stages and overheats the die.

There are some recommended ways to avoid this condition. Adding series resistance at the inputs will limit the current. The latch is caused by a negative spike on the input of enough level to forward bias the diode(s) at the input pins. I haven't tried the series resistor trick but I think it would work.

In a related issue I'm currently using the TPIC6C595 (TI power logic - same as your '595 with 500mA capable outputs) as a lamp driver. I had issues with latch up. Although TI's engineers looked at my design they didn't find the source of the problem. I did cure it with better decoupling caps at the IC pins.

Morrog wrote:Two extra questions:
How would I go about getting a voltage regulator that can handle more than 1A of current? All the VREGs I find are rated for 1A. If I have 128 LEDs on at once that's about 2.6Amps. Can I put a couple in parallel?
You have several choices:

(1) Use a commercial power supply rated to the desired current.
(2) Split your load to separate "channels" (say, four) and power each one form it's own 1A regulator.
(3) Add power resistors to the existing regulator to increase the load current, assumes that you have a fairly steady load (not true in this case).
(4) Add an external pass transistor to the standard 1A regulator, as shown in the data sheets, figure 21,22,here.
Morrog wrote:Also, do those AA battery holders put the batteries in series or parallel? I'm gonna need to put 8 AA NiMH batteries in series to get enough voltage to hook into a 5V VREG.
Series. Why would you use batteries to power this project? If it has to be portable why not use higher density batteries, such as LiPo?

Why eight cells (9.6V)? Why use linear regulators with a battery source? There are better ways to get LEDs to operate for longer while on battery power.

Comments Welcome!
By Morrog
#30403
Thanks for the tips of the voltage regulator!
Series. Why would you use batteries to power this project? If it has to be portable why not use higher density batteries, such as LiPo?

Why eight cells (9.6V)? Why use linear regulators with a battery source? There are better ways to get LEDs to operate for longer while on battery power.
Well, the longest lasting rechargeable battery I was able to find is a 2700mAh NiMH AA battery. Eight cells are necessary to get enough voltage to the VREG. The minimum is 7V (6 batteries) and if the batteries start dieing off I'd like a buffer there. The VREG is there to keep the voltage constant as the batteries slowly lose their juice.
User avatar
By bigglez
#30407
Morrog wrote:Well, the longest lasting rechargeable battery I was able to find is a 2700mAh NiMH AA battery. Eight cells are necessary to get enough voltage to the VREG. The minimum is 7V (6 batteries) and if the batteries start dieing off I'd like a buffer there. The VREG is there to keep the voltage constant as the batteries slowly lose their juice.
Morrog,

Okay on your reasoning. The down-side to this approach is that about half of the battery charge is wasted (as heat) with this scheme.

A linear regulator passes the same current as the load (give or take a small bias for internal circuits), and has the voltage drop from the load to the input (Vbulk).

In your scheme Vbulk = 9.6V at full charge, and perhaps 8V at full discharge (it's not wise to run rechargeables down too much).

With zero LEDs turned on you have a small standby current for the logic and uC plus whatever else your have on the 5V rail. Perhaps 50mA or less.

With all LEDs on, at say 10mA per LED, the current rises to 50mA plus 128 * 10mA = 1330mA.

In the low demand - fully charged case the battery provides:

9.6V * 50mA = 480mW total

While the linear regulator wastes:

Vbulk - Vreg * Iload = (9.6 - 5) * 50mA = 230mW

230/480 = 48% efficient.

In the high demand - fully charged case:

9.6V * 1330mA = 12.77W total, 6.12W wasted.

A better approach would be to reduce the battery voltage to match the LED voltage (the logic and uC will operate below five volts). Perhaps only 3.6V (three cells fully-charged) is needed?

Or, add a switching regulator that converts the higher bulk voltage (9.6V fully-charged) down to 5V and operates at say 75% efficiency or better.

A third alternative is to keep a low power linear regulator for the logic and uC only, and run the LEDs directly from the battery. Increasing the LED resistors will maintain the LED current (we used 10mA above). Now the power is wasted in the LED resistors. Not good for efficiency but the high current linear regulator is no longer required.

The fourth option is to run the LEDs from Vbulk (the battery) and PWM all the LEDs so that they average 10mA, but get 40mA pulses from Vbulk for only 25% of the time. This reduces the waste in the linear regulator and avoids the complication of a high efficiency switcher to change Vbulk to Vled.

If you want to squeeze the most efficiency out of this arrangement, monitor the LED current with the uC (A2D channel, analog comparator, or your own linear detector circuit) and change the PWM to keep the LEDs at the same brightness as the Vbulk falls (battery discharging). This would be a good place to put a battery under-cut circuit that shuts everything down when Vbulk gets down to 8V.

Comments Welcome!
By Morrog
#30416
How informative! Thanks for helping, bigglez.

I guess, then, it would be easiest for me to hook 4 AA NiMH batteries together for the powering the LEDs, and then leave my old 9V setup for powering the PIC.
User avatar
By bigglez
#30418
Morrog wrote:How informative! Thanks for helping, bigglez.

I guess, then, it would be easiest for me to hook 4 AA NiMH batteries together for the powering the LEDs, and then leave my old 9V setup for powering the PIC.
Morrog,

Sure! That would work. Your uC and logic could be run form the same supply as the LEDs (4 x 1.2 = 4.8V fully charged, 4 x 1.0 = 4V at end of charge). Check your uC and logic data sheets again, I think you'll find they can work below 4V, saving you the 9V supply and linear regulator.

Comments Welcome!