fading multiple leds
jcferguson
Posts: 86
Hi All,
What would be the best way of fading a bank of 20-40 leds with a bs2? Should I use a digital pot to control a transistor that gets power to the leds? Or a uln2803 (How would I fade the supply voltage in and out with this method?)
Thanks, I really appreciate all the help offered here.
Carlos Ferguson
What would be the best way of fading a bank of 20-40 leds with a bs2? Should I use a digital pot to control a transistor that gets power to the leds? Or a uln2803 (How would I fade the supply voltage in and out with this method?)
Thanks, I really appreciate all the help offered here.
Carlos Ferguson
Comments
http://forums.parallax.com/showthread.php?p=522895
-Phil
Mike, I didn't realize I could just put all the inputs on a uln2803 to one pin on the stamp, but of course it makes sense. Is there effectively no draw (or very minimal) on that pin then? Can I PWM a uln 2803 and will either of these methods (pulsout and pause - or - pwm) make for leds that don't flicker?
Again, thanks for the help!
Carlos
You should be able to use the PWM statement as well. The human eye doesn't respond discretely to refresh rates much faster than 50Hz so cycle times less than 20ms shouldn't noticibly flicker.
What about this concept -
run a digital pot from the stamp that varies a pwm 555 circuit to pulse the leds through a uln2803? Would that work/be the right way to go about it? It would seem like a way to off-load the pwm from the stamp - I could just vary the digital pot When I wanted to fade the leds, otherwise leave it be...
Thanks again Mike,
Carlos
Post Edited (jcferguson) : 2/19/2007 8:43:12 PM GMT
I believe the 1.3ma is per input. The total would be 8 x 1.3 = 10.4ma which is well within the capabilities of a Stamp pin.
If you want to off-load the PWM from the Stamp, I would just use a PWM-PAL which is a little peripheral processor that mounts under the Stamp itself and provides 4 independent PWM outputs with independent control of the on and off times of each output by means of a 10 byte serial command sequence sent from the Stamp to the PWM-PAL. There are also 4 independent counters in the PWM-PAL that can count its output pulses or any other source. These could be used for an independent time reference to control the fade rate.
Carlos
I hooked this up on my breadboard with the attached code - I am driving three uln2803 pins with pin0 on my stamp, counting up the pwm value and then back down - this does work, but there is a "hitch" in the even rise and fall in illumination about halfway through, not quite a smooth climb and fall. Can you think of any reason for this? Perhaps that the relationship between the pulses and the led light output isnt linear?
Carlos
I could be wrong in this -- I haven't personally used a Darlington Array myself yet.
Thanks,
Carlos
Now I wonder though - resistor or no? It is definately causing a less smooth rise and fall to the light and I measure about 3 ma tops when the circuit is in action - driving three pins.
Carlos
If you look on the ULN2803 datasheet, you'll see that the device includes a series resistor.
I am looking to be able to fade a large number of leds in and out - a capacitor seems to do this better in one direction (fading out) than the other - also, I wouldn't have code control of how long the fade lasts?
Carlos
You don't want to use a capacitor except across the power supply leads to the ULN2803/LEDs where you'll need some filtering to supply the momentary load when the ULN2803s switch on. You're deliberately driving the LEDs full on for a short time, then full off for a short time with the average on/off time determining the brightness. There's probably a non-linear brightness vs. average current curve and you may want to use a lookup table to adjust the PWM value you use for a given fade time. Basically, you're stepping through a list of 256 or 128 brightness values and you'd use a table in EEPROM (using DATA/READ statements) to supply the actual PWM value to use.
Capacitors should work. If you use a couple of diodes you can control the fade in and fade out time.·Schematic and program attached:
I just threw this circuit together for you feel free to modify.You can control fade times by having two Stamp outputs connected to 1 cap - instead of low or high put the unused output in input mode this will give you·4 combination of fade in and·fade out times(speeds) per cap /LED. If your driving 20 - 40 LED's simultaneously you can control them all through·a single SPDT relay, 1 circuit per LED.Error in schematic reposted (twice - doesn't pay to rush)- refresh your browser!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 2/23/2007 11:20:33 AM GMT
This is the circuit I am trying out - couldn't I just replace the 100k pot in the 555 circuit with a ad5220 or like (digital pot) and then be able to vary the brightness by adjusting the pot with the stamp? It would seem like I would have good control and be able to fade as many leds as I like with two pins.
TR
Post Edited (TechnoRobbo) : 2/23/2007 11:21:25 AM GMT
I'm not sure I really understand how you are using the voltage to drive the servo - it looks like you have two voltage dividers on the dig. pot. and are setting low to .7, high to 2.8 and then the wiper runs between them, making for another voltage divider? This then goes to the 555 control voltage? Maybe the part I don't understand is the 555 - I have just used it by varying an rc relationship to set the pulse time/duty cycle. You, instead, are controlling the 555 with a varying voltage on pin 5? What's the difference?
I have things working - I have a 555 circuit (shown above) and simply replaced the 100k pot with a digital pot, so that when I change the digital pot, the leds are pulsed more or less... This work. I would, however, like to make the fade a little less bumpy - could I use a combination of the two ideas we have been talking about here (caps and 555)? If I mixed a cap in with the leds would it smooth the jumps from one click on the digital pot to the next?
Thanks for the help,
Carlos
·Sorry if I confused you - the voltage dividers are to calibrate the servo range.·Pin # 5 controls the pulse width via 0 to 5 volts.
I put it on the scope and figured out the RC values for you.
Attached is a working schematic to dim LED's and the code to run it.
Reposted - added NPN transistor to schematic.
Watch the circuit in a dark room and you'll see the full range of dimming.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 2/23/2007 11:19:42 AM GMT
In your circuit is the end result the same - the leds are dimmed by changing the percentage of "on" time within the duty cycle? I'll post my circuit again when I get the dig. pot. drawn in.
Carlos
This will make your fading much smoother just as it did the servo control. With that being said, attached is a schematic to allow calibration of the range:
Have Fun
TR
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 2/24/2007 2:25:36 AM GMT
1 - Here is the circuit I have been working on. So I can just rewire the first two parts to your circuit and adjust for the endpoints I want?
2 - Is that pot between Vdd and ground on the ad5220 correct? The wiper is flying free?
3 - I was, in fact, going to ask how to "spread" the range of the digital pot to cover the leds. Could you tell me in brief how the two circuits work differently if you have time?
4 - And... one other question: it seems like the third LED in my three-led/one resitor series is dimmer in each of the series - is this possible? Should I rewire with just one led per resistor?
Thanks for the help,
Carlos Ferguson
Post Edited (jcferguson) : 2/23/2007 4:34:43 PM GMT
The difference between the two circuits is distinct.· Your circuit works by controlling the charge/discharge time of the capacitor by varying resistance. My circuit uses the 555's·internal comparator to control the threshhold via voltage.· By narrowing the voltage range of the digital pot to the throttling range of the circuit you maximize your control resolution, like using a magnifying glass to concentrate on only the important part of a picture.
As for your dim LED I assume your using 5 volts as your supply for the LED's. The LED's consume a fixed amount of voltage (diode forward voltage) Since you've wired them in series the sum of the forward voltages probably exceeds the voltage your sourcing.
These are the common LED forward voltages:
As you can see 3 red LED's = 5.4 volts in series. Try wiring them in parallel with current limiting resistors (470 ohm is good for a Red LED). Make sure you don't exceed the current sourced by 1 pin of your 2803 with too many LED's in parallel (think 7.23ma per LED in parallel).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 2/24/2007 2:59:01 AM GMT
This voltage from the wiper goes to the control pin on the 555 which adjusts the "threshold" (usually 2/3 of Vcc) for the 555 circuit - which is the point where the charging of the cap reaches 2/3 and the output pin goes low.
How does the voltage on pin 5 affect the threshold voltage? I'm still not quite putting together how you set the high and low points on the leds with the voltage from the digital pot.
I really appreciate your help,
Carlos
Chris I.
The circuit is actually a pulse-position modulation circuit it varies the frequency as well as the width via the comparator voltage feeding the flip-flop.· The control voltage overrides the internal triple 5k resistor voltage divider by creating a potential difference and sets a new threshold for the upper comparator. I use this for servos since the period in between the pulses is fairly constant.
As for the digital pot the voltage dividers set the high·and low voltage on either side of the pot (A1 & B1) the wiper output then varies in between the voltages - The idea is to match the high and low points of the LED or the Servo so the full 127 step range controls only this range. That way you dont limit your steps to the usable range. There is a visual plateau when the LED appears not to be getting any brighter (it is but your eyes dont catch it) - eliminating this range gives you more·(finer) control over the "sweet spot" of the brightness range.
Below is a true PWM pulse-width modulation circuit but I'm using a 556 dual timer. It keeps a constant frequency but alters only the width. It's an astable multivibrator feeding into a monostable one-shot.· The astable circuit creates the clock and the one-shot alters the width via voltage control.· I adjusted all the RC's to work with LED's it can also drive motors.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 2/28/2007 2:30:57 AM GMT