Shop OBEX P1 Docs P2 Docs Learn Events
fading multiple leds — Parallax Forums

fading multiple leds

jcfergusonjcferguson Posts: 86
edited 2007-03-03 15:02 in BASIC Stamp
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
«1

Comments

  • randyazrandyaz Posts: 61
    edited 2007-02-19 16:06
    Here's a thread that might help you



    http://forums.parallax.com/showthread.php?p=522895
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-19 16:07
    LEDs don't fade well by controlling the power to the LEDs. You need to vary the time spent on in relation to the time spent off and the eye averages this so the LEDs look dimmer. If you plan to use 5V to supply the LEDs, you could put two LEDs in series with a current limiting resistor, then parallel several of these on each ULN2803 output to make up your total number of LEDs. Connect all the ULN2803 inputs to one Stamp pin and use a PULSOUT statement to vary the ON time vs a PAUSE statement to set the OFF time. You'll need to experiment to find the ON/OFF ratios for the light intensity steps you want.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-02-19 17:07
    If you use the MoBoStamp-pe BASIC Stamp 2pe motherboard, there are PWM outputs that will maintain any of 255 dimming ratios for you on up to four separate channels. These are provided by the onboard AVR coprocessors and can be set via a simple command. Once set, they don't require further intervention from the BASIC Stamp to maintain the pulse stream — only to change the ratio. And their frequency is high enough (up to 37.5KHz) that you won't notice any flicker.

    -Phil
  • jcfergusonjcferguson Posts: 86
    edited 2007-02-19 17:28
    Thanks, good solutions here.

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-19 19:16
    Look at the datasheet for the ULN2803. It gives the maximum input current as around 1.3ma.

    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.
  • jcfergusonjcferguson Posts: 86
    edited 2007-02-19 20:10
    I looked the data sheet as well - does that 1.3 ma mean per pin or total - I can't tell from the data sheet, though "maximum" would suggest total? Then I tried driving three pins - they drew 9 ma according to my multimeter - so I put in a resistor and the outputs still come on with less than 1 ma of draw. Am I supposed to have a resistor on the inputs to the uln2803? Dang. I should go to robot school to learn more about these things!

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-19 20:41
    Carlos,
    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.
  • jcfergusonjcferguson Posts: 86
    edited 2007-02-19 20:43
    Thanks Mike, I just editted my post above -- does a resistor before the uln make sense?

    Carlos
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-19 20:55
    I can't see why you'd need a resistor. I checked the input current graph in the datasheet. Even at +5V input, the input current per pin is supposed to be less than 2ma. The Stamp can easily handle that x 8.
  • jcfergusonjcferguson Posts: 86
    edited 2007-02-19 21:09
    Ok on the resistor.


    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
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-02-19 21:12
    I believe a "Darlington Array" (the ULN28003) is basically a 'super-transistor', each circuit made up of two transistors. As such, I don't think there's any inherent "current limiting" in the input 'base' lead. So you SHOULD put in a resistor to limit the current to 1.5 mA per input pin, or a 3.3 Kohm resistor.

    I could be wrong in this -- I haven't personally used a Darlington Array myself yet.
  • jcfergusonjcferguson Posts: 86
    edited 2007-02-19 21:15
    Ha! I still had the uln2803 hooked up through a resistor that I asked about above, removed the resistor, smoother light!

    Thanks,

    Carlos
  • Steve JoblinSteve Joblin Posts: 784
    edited 2007-02-19 21:15
    what am I missing here?· isn't using a capacitor the easiest way to fade out an LED?
  • jcfergusonjcferguson Posts: 86
    edited 2007-02-19 21:17
    Y'all are too darned fast!

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-19 21:17
    allanlane5,
    If you look on the ULN2803 datasheet, you'll see that the device includes a series resistor.
  • jcfergusonjcferguson Posts: 86
    edited 2007-02-19 21:19
    Steve,

    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
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-02-20 15:03
    Thanks, Mike, the only data sheet I could get my hands on at short notice was the uln2003. You are correct.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-20 15:33
    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.
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-02-20 17:38
    Carlos

    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
    925 x 502 - 79K
  • jcfergusonjcferguson Posts: 86
    edited 2007-02-21 00:03
    Thanks techno, I'll try that out tonight. It looks to me like the fade rate is set with the rc combo so that it is fixed once set.

    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.
    862 x 464 - 6K
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-02-21 00:13
    I've done something similar to that but it was controlling a servo and it controlled the 555 through pin 5 (control).Here's the schematic and code feel free to modify to suit your needs.

    TR

    Post Edited (TechnoRobbo) : 2/23/2007 11:21:25 AM GMT
    2055 x 1585 - 228K
    1161 x 617 - 83K
  • jcfergusonjcferguson Posts: 86
    edited 2007-02-22 20:58
    Techno -

    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
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-02-23 02:31
    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
    2055 x 1585 - 192K
  • jcfergusonjcferguson Posts: 86
    edited 2007-02-23 03:49
    Thanks for the diagram!, I think what I need to do is read more about 555 timers. I have always tied pin 5 to ground through a capacitor... You are using the chip in a different way it seems.

    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
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-02-23 11:08
    The reason for using pin 5 was to maximize the control range. (I originally designed the pot replacing a resistor). For the Servo I only required a 2 volt range which amounts to 50 steps of the AD5220. By adding the voltage dividers on A1 and B1 of the digital pot I was able to match the 128 (0 - 127) steps to the full throttling range of the servo. Similarly the LED circuit only requires a 2.5 volt (64 step) range to go from full bright to full dark. By adding the voltage dividers you can adjust that to the full 128 step range!

    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
    2055 x 1585 - 208K
  • jcfergusonjcferguson Posts: 86
    edited 2007-02-23 15:23
    Hi Techno,

    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
    1038 x 356 - 7K
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-02-24 02:45
    You are correct I forgot to connect the wiper - I reposted the schematic - refresh your browser to see.

    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:
    attachment.php?attachmentid=73714

    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
    141 x 160 - 2K
  • jcfergusonjcferguson Posts: 86
    edited 2007-02-27 05:58
    Ok Techno, let me see how much of this I understand. You are using the digital pot as a voltage divider instead of just a variable resistor - the A1 and B1 pins are set to a voltage between ground and 5+ with the 10k pots. Then the wiper pin is a voltage between those two voltages.

    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
  • StarManStarMan Posts: 306
    edited 2007-02-27 20:52
    Have you looked at the MAX7219?· You can control up to 64 LEDs with one chip and there is a PWM brightness control to boot.

    Chris I.
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-02-28 00:44
    Carlos,

    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
    1477 x 725 - 181K
    PWM.JPG 180.5K
Sign In or Register to comment.