Driving LED's with PWM


Closed Thread
Results 1 to 20 of 20
  1. #1
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425

    Default Driving LED's with PWM

    I'm confused.

    The project: I'm making an outdoor sign that has 500 LED's.

    The problem: It draws way too much current.

    The current solution: Use PWM with a ULN2003 to drive the LED's.

    The secondary problem: What if my PIC gets "stuck" with the PWM in the on position?

    I researched my question and found some information that helps. However, I need a better understanding. I know PWM works because it's been running these LED's for two days now. A lot of information on the internet states that you shouldn't use PWM without a current limiting resistor. I understand why but if there was a hardware backup (crowbar, TVS, zener, etc) are there any other concerns? I know uneven current is one of them but if the brightest LED is kept below the maximum then the rest should be okay? I guess it may boil down to looks at that point.

    My other confusion is about current measurement. I set up the LED's (I'm testing 12 in parallel at the moment) to display maximum sustained current, which the datasheet states is 30mA. I get about 352 mA and this is a lot of current and heat to dissipate. I set up PWM (240uS on / 5uS off) with the same configuration of LED's. My measurement shows 125mA but should this be measured in DC or AC amps since it is PWM? When I switch to AC amps the current measurement is 290 mA.

    I'm trying to figure out two things. One, can I make the LED's more efficient and two, can I make the LED's look bright without having to use more current.

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,599


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    I don't know your exact setup, but I'd put a transistor after the PIC and use a pull-down resistor. If the PIC fries, transistor goes off. If PIC fails ON, not much you can do besides safety features you mentionned.

    Robert

  3. #3
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    The ULN2003 is a transistor (darlington pair).

    Years ago I learned (the hard way) that having a hardware backup to protect the device (i.e. After all of the controlling hardware/software) is worth a mountain of gold. Fuses are under-appreciated and have a thankless job.

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,599


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    (for what my "limitted knowledge" is worth)

    PWN is intermittent DC, I would use DC mode to measure current.

    As to make LED brighter without using more current, I think that strays into 'free energy' subject. I don't think you can.

    Do a test, DC with varying voltage, adjust to desired brightness, measure current.

    Repeat using PWM, adjust to similar brightness and measure current.

    I think you won't find a way around 2+2=4. I hope you can but I couldn't a few years back.

    Robert

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,599


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    Agreed about fuses, but they are slow to burn even if "fast" model. Crowbar, TVS, zener, etc offer much faster response for delicate devices.

    I'd still shove a fuse in there regardless, super cheap.

    Robert

  6. #6
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    Quote Originally Posted by Demon View Post

    Do a test, DC with varying voltage, adjust to desired brightness, measure current.

    Repeat using PWM, adjust to similar brightness and measure current.

    Robert
    I did that. It's hard to tell if the brightness is different but that kind of answers my own question. For me it looks the same whether the current is 125mA DC or 360 mA DC. It's technically an AC sine wave, which would make sense given the fact that I measured 300mA AC, but I don't know for sure.

    I know I have some photocells at home and that's about the best I can do to measure the amount of light.

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,599


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    Wouldn't AC mode measure current above and below neutral, basically 2 readings and then adding them?

    That might explain why your reading is twice as high on AC.

    (total guess)

    Robert

  8. #8
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    Rapidly switching DC on & off (PWM) is a square wave. It's still DC.
    If you vary the duty cycle from 50% it will look different, but we still call that a square wave.

    You can measure the current with LEDs running constantly for a single row like it sounds like you're doing.
    If it's a POV display where you cycle rows, then no more than one row (or column depending on how you look at it)
    is going to be powered at one time, so you can assume the total of the switching transistor and LEDs for a
    single row is the maximum current that your display will draw.

    Be careful trying to measure PWM with a digital multimeter.
    The digital multimeter is a microcontoller too, and can only take samples at a certain rate that is not synced with your PWM.

    I believe the best insurance against software failure is your watchdog timer.
    The best place to clear it is in your display routine that cycles the rows.
    Depending on complexity, I suppose some insurance against hardware failure is also prudent.

    Last edited by Art; - 31st December 2013 at 01:35.

  9. #9
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    Quote Originally Posted by Art View Post
    You can measure the current with LEDs running constantly for a single row like it sounds like you're doing.
    If it's a POV display where you cycle rows, then no more than one row (or column depending on how you look at it)
    is going to be powered at one time, so you can assume the total of the switching transistor and LEDs for a
    single row is the maximum current that your display will draw.
    The PCB has 12 LED's in parallel. Not sure I completely follow your comment but I'm trying to validate how much current I'm saving by decreasing the duty cycle/frequency. I have an oscilliscope if there's a good way to measure the current with it.

    Quote Originally Posted by Art View Post
    I believe the best insurance against software failure is your watchdog timer.
    Depending on complexity, I suppose some insurance against hardware failure is also prudent.
    I've never used the watchdog timer but assume it checks the continuous loop that's running inside the PIC. If so, what happens if the ULN2003 fails or my power supply fails (overvoltage or overcurrent)? The LED's aren't expensive to replace but they are a PITA to access. I want to avoid replacing them at any cost.

  10. #10
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    That's the benefit of hardware failsafe. Something could break to leave an LED on,
    but the watchdog timer is still the cheapest and most effective on the software side.
    If your display routine fails to cycle, the watchdog should be on an independent timer,
    and fire even if, for example the chip's oscillator shorted.

    If you have rows of 12 LEDs parallel, that means they can't be independently controlled
    for graphics, etc. You are just cycling whole rows of LEDs?

    The current can still be measured at 100% duty cycle, and as you lower the duty cycle,
    the average current should lower approximately with the duty cycle.
    Transistors have cut off slopes, so it's not extremely precise. Someone else may have to chime in about that.
    However, just because you use say 50% duty cycle, the fact remains that the row of LEDs and hardware to drive
    them are using the same current for half of the time, and no current for the other half of the time.
    That's if you negate a little error for the actual switching on and off, but I don't know exactly what the cost is there.

  11. #11
    Join Date
    Dec 2013
    Posts
    1


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    Hello

    I am working with LED and trying to make them as bright as possible.

    What I have read, I can provide higher current through the LED with pulses. I am now running a 30 ma LED with 90 ma and pulses. 1khz with 1/10 duty cycle.

    I was trying to measure the light intensity, but there is no difference between a normal none wave setup wtih 30 ma, compared to my PWM setup.

    The measurements was done with a photodiode and I measured the voltage after. Can this be a bad way to measure the light and therefore I cant trust the outcome, cause maybe it shows more the average light intensity/voltage.

  12. #12
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    Quote Originally Posted by Art View Post
    If you have rows of 12 LEDs parallel, that means they can't be independently controlled
    for graphics, etc. You are just cycling whole rows of LEDs?
    It's not for graphics. I am testing a number and the 12 LED's are one segment of the number.

    Quote Originally Posted by Art View Post
    The current can still be measured at 100% duty cycle, and as you lower the duty cycle,
    the average current should lower approximately with the duty cycle.
    Transistors have cut off slopes, so it's not extremely precise. Someone else may have to chime in about that.
    However, just because you use say 50% duty cycle, the fact remains that the row of LEDs and hardware to drive
    them are using the same current for half of the time, and no current for the other half of the time.
    That's if you negate a little error for the actual switching on and off, but I don't know exactly what the cost is there.
    I did some testing tonight but things still aren't clear for me. I will post the results below and maybe someone can derive something useful from this information. Brightness (how the user views it) is the ultimate test so I put a photocell on top of one LED and wrapped it in black electrical tape. I took random measurements with a bunch of tests using only PWM and the other using straight DC with a resistor. For clarification, the lower the resistance the higher the brightness.

    Code:
    LED'S ON	ON TIME	OFF TIME	CDS Resistance	DC Current	AC Current	Resistor	
    1---------	5uS	        740 uS	92.2 Ohms	         36.4 mA	XXXXXXXXX	No	XXXXXXXXX
    2---------- 5uS	        740 uS	94.2 Ohms	         41.3 mA	XXXXXXXXX	No	XXXXXXXXX
    3---------- 5uS	        740 uS	98.3 Ohms	         52.6 mA	XXXXXXXXX	No	XXXXXXXXX
    1+12 LED's	5uS	        740 uS	150.4 Ohms	         49.9 mA	189.3 mA	        No	XXXXXXXXX
    1+12 LED's	5uS	        640 uS	141.2 Ohms        	 57.2 mA	214.2 mA	        No	XXXXXXXXX
    1---------- 5 uS	        940 uS	118.4 Ohms       	 27.2 mA	XXXXXXXXX	No	XXXXXXXXX
    1---------- 5 uS	       1140 uS	128.6 Ohms	          23.5 mA	XXXXXXXXX	No	XXXXXXXXX
    2---------- 5 uS	       1140 uS	133.5 Ohms	         29.6 mA	XXXXXXXXX	No	XXXXXXXXX
    3---------- 5 uS	       1140 uS	133.6 Ohms	         37.2 mA	XXXXXXXXX	No	XXXXXXXXX
    1+12 LED's	5 uS	       1140 uS	194.8 Ohms    	33.4 mA	159.7 mA	        No	XXXXXXXXX
    1+12 LED's	5 uS	        1240 uS	203 Ohms	        31.3 mA	154.6 mA	        No	XXXXXXXXX
    1---------- 5 uS   	1240 uS	127 Ohms	         21.5 mA	XXXXXXXXX	No	XXXXXXXXX
    
    1+12 LED'S	100	0---------	         109.2 Ohms	94.2 mA	XXXXXXXXX	Yes	29.6 Ohms
    1+12 LED'S	100	0---------	         117.3 Ohms	79.9 mA	XXXXXXXXX	Yes	35.6 Ohms
    1+12 LED'S	100	0---------	         136.1 Ohms	64.7 mA	XXXXXXXXX	Yes	44.5 Ohms
    1+12 LED'S	100	0---------	         159.4 Ohms	49.3 mA	XXXXXXXXX	Yes	59.3 Ohms
    1+12 LED'S	100	0---------	         201.6 Ohms	33.5 mA	XXXXXXXXX	Yes	89 Ohms
    1+12 LED'S	100	0---------	         310.2 Ohms	17.1 mA	XXXXXXXXX	Yes	178 Ohms
    I don't see much of a difference between PWM and using a resistor.

  13. #13
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,599


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    Pretty much the same thing I observed.

    Brightness requires current, I don't think you can get around that.

    Maybe if you start tinkering with transformers?

    Robert

  14. #14
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    Is this statement correct?

    Even though the currents are similar, using PWM without a resistor must be more efficient since a resistor isn't being heated.

    Another thing that doesn't make sense is the non-linear curve in current when adding diodes onto the PCB. One LED consumes 30mA but two doesn't equal 60.

  15. #15
    Join Date
    Oct 2011
    Location
    East Coast USA
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    An LED cannot have more than its forward bias voltage across it. For an old red LED that voltage is about 1.6 volts. Sacrifice one by driving one with a variable power supply. It will start lighting at a little over 1.5 v. It will be brightest at 1.6v. Only when it burns out will the voltage go much higher than that.

    In a circuit, the current is limited by the impedance (resistance) of the circuit driving it. If you drive the LED directly from a i/o pin, the current will be limited by the impedance of the output circuit. The output transistor or FET will act as the resistor and limit the current to some value.

    There are two different limits on the current through the LED, the maximum instantaneous current and the max average current. If you exceed the first, the LED will fail immediately. If you exceed the second, it will overheat and die more slowly. There should be a resistor to limit the current to below the max instantaneous current. You can then use PWM to stay below the max average current.

    The instantaneous current through the LED can be calculated using i = e / r where r equals the sum of the impedance of the driver plus any external resistor. Heat will be lost by the voltage drop across the driver transistor and the external resistor.

  16. #16
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,599


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    Quote Originally Posted by Christopher4187 View Post
    ...Another thing that doesn't make sense is the non-linear curve in current when adding diodes onto the PCB. One LED consumes 30mA but two doesn't equal 60.
    I have a similar problem. I'm designing panels for my residential alarm system and I'm kinda overwhelmed by the possible maximum current. A LOT of LEDs could potentially be on at the same time (I'm using solid strand 24 AWG telephone wire with 12V 7Ah battery backup).

    I started with LCDs, but these panels are not only for the house where it's warm, it's also for the garage (worried about cold and humidity).

    Robert


  17. #17
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    Dave
    Always wear safety glasses while programming.

  18. #18
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    Quote Originally Posted by Demon View Post
    I have a similar problem. I'm designing panels for my residential alarm system and I'm kinda overwhelmed by the possible maximum current. A LOT of LEDs could potentially be on at the same time (I'm using solid strand 24 AWG telephone wire with 12V 7Ah battery backup).

    I started with LCDs, but these panels are not only for the house where it's warm, it's also for the garage (worried about cold and humidity).

    Robert

    If it's a panel inside then you could supply 1-3mA per LED. There's no reason to supply the maximum amount of current since you won't have an audience to view them and they are inside. I recently used Screenmaster LED's and at 1mA they were really bright. I wish I had your problem. My LED scoreboard is outside and the sunlight hits it. Needless to say the LED's have to be really bright.

  19. #19
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,599


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    Thanks!

    Just went through the 1st, great stuff!

    Didn't download the dice yet. I want to see what I can do on my own first.

    Robert The Very Happy Camper

  20. #20
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,599


    Did you find this post helpful? Yes | No

    Default Re: Driving LED's with PWM

    Quote Originally Posted by Christopher4187 View Post
    If it's a panel inside then you could supply 1-3mA per LED. There's no reason to supply the maximum amount of current since you won't have an audience to view them and they are inside. ...

    I'll be using surface-mount LEDs that I have on hand (got some greens, yellows and reds). I think they require somewhere between 15-20mA to be reasonably visible in daylight inside the house (some panels could be in full sunlight).

    I'll be making my own light chimneys with clear liquid plastic from Smooth-On.

    Finished preliminary testing today, very low current is achievable, I just have to improve code logic and efficiency:
    http://www.picbasic.co.uk/forum/showthread.php?t=18906

    Of course none of the colours I have are of the same brightness so some tweaking of the resistors will be necessary.

    Robert

Similar Threads

  1. control 60 tri-color LED's
    By MOUNTAIN747 in forum General
    Replies: 0
    Last Post: - 15th September 2011, 23:30
  2. shared data lines for LCD and LED'S?
    By nomad in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th February 2009, 04:37
  3. Scolling LED's
    By Melanie in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th July 2008, 23:28
  4. Killing blue led's
    By Steve_88 in forum Off Topic
    Replies: 3
    Last Post: - 31st January 2008, 02:37
  5. Driving a Voltage Regulator with PWM
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 27th June 2007, 13:14

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts