Pages: [1] 2   Go Down
Author Topic: PWM control of many LED's from arduino  (Read 2112 times)
0 Members and 1 Guest are viewing this topic.
South UK
Offline Offline
God Member
*****
Karma: 5
Posts: 583
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all. I am playing with the idea of installing up 12 x LED down-lighters in my lounge. I'm using 3W white LED MR16 bulbs and driving them with a BC337 which works well from the PWM pins. I thought I'd get a Mega due to the extra PWM pins so I could do it that way (need 12 PWM outputs currently) but it won't be very future proofed and I want to also control some RGB strips.

I have tried softPWM before and it works well for fading, but not for holding - when i do a analogwrite of say 50, you can see the PWM effect (strobing LEDs). So I don't want to use soft pwm.

What other options do I have? I'm not very good at coding yet so I need a really simple solution.
Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 86
Posts: 3468
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If your getting strobing, then you can put a capacitor on each pin. It should help get rid of some of the strobing. Try maybe 10uf to start.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Dubuque, Iowa, USA
Offline Offline
Edison Member
*
Karma: 45
Posts: 2474
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If those bulbs have drivers in them you're probably making them angry by PWMing power to them. More detail as to exactly what bulb you're using and what is inside those bulbs would be warranted.

Logged

South UK
Offline Offline
God Member
*****
Karma: 5
Posts: 583
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have got a few different ones on the way to test. The one I have is working fine when running direct from a hardware PWM pin though? But it strobes at low duty cycles using softPWM. The one I have opened up looks like it has a rectifier bridge and some kind of current limiting circuit, I might modify them for direct DC.

This is the one I have http://www.ebay.co.uk/itm/251095501994

and these on the way
http://www.ebay.co.uk/itm/270758491217
http://www.ebay.co.uk/itm/320736975011

How would I wire a capacitor to them?
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What other options do I have?

A few:

1) use external chips;
2) find a chip with > 12 channel hardware pwm and port arduino to that chip;
3) use 1 main pwm channel and AND it with individual pwm outputs.
...
Logged

Pottstown, PA
Offline Offline
Sr. Member
****
Karma: 5
Posts: 317
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Quote
1) use external chips;

Like this? https://www.sparkfun.com/products/10136

- Scotty
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't put capacitors on the pins, you'll overload the Arduino if you do.

If the lamps work OK using hardware PWM (and you may not know whether they do without running them for a long time - as HazardsMind says, the controllers built-in to the lamps may not take kindly to PWM), but you can see strobing using the softPWM library, then you need to increase the PWM frequency when using SoftPWM. This is 490Hz by default for hardware PWM, but only 60Hz for the softPWM library.

To increase the PWM frequency for the softPWM library:

1. Simplify the timer ISR (the function "SoftPWM_Timer_Interrupt(void)" in SoftPWM.cpp). Get rid of the fade up/fade down code (you can do fading outside the ISR) and the normal/reverse PWM code. Move the declarations of local variables from the start of the function to where they are actually used. What you are looking to do is speed up the ISR substantially.

2. Change the definition of SOFTPWM_FREQ in SoftPWM.cpp from 60UL to something higher. How high you can go depends on how much you have simplified the timer ISR.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote

Yes. Many other vendors offer similar chips, Sanyo, Philips, Motorolla, or some asian vendors too. Search for LED drivers and you will get tons of them.

Alternatively, you can get a few avr/arduino and program them as slaves being controlled by a master arduino. The slaves output independent pwm signals based on commands sent to them by the master.
Logged

Dubuque, Iowa, USA
Offline Offline
Edison Member
*
Karma: 45
Posts: 2474
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Bulb #2 will take PWM fine because it's obviously using resistors for current control (low power LEDs; power input 5W but light output 2.5W). Bulb #1 and #3 are using high power LEDs and will have driver chips.

It shouldn't be possible to see flickering above 100Hz and at 60Hz any flickering should be barely noticeable (do you see flickering in a 20ma/5mm LED?). I still think your problem is just that you're making the driver angry.
Logged

South UK
Offline Offline
God Member
*****
Karma: 5
Posts: 583
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't put capacitors on the pins, you'll overload the Arduino if you do.

If the lamps work OK using hardware PWM (and you may not know whether they do without running them for a long time - as HazardsMind says, the controllers built-in to the lamps may not take kindly to PWM), but you can see strobing using the softPWM library, then you need to increase the PWM frequency when using SoftPWM. This is 490Hz by default for hardware PWM, but only 60Hz for the softPWM library.

To increase the PWM frequency for the softPWM library:

1. Simplify the timer ISR (the function "SoftPWM_Timer_Interrupt(void)" in SoftPWM.cpp). Get rid of the fade up/fade down code (you can do fading outside the ISR) and the normal/reverse PWM code. Move the declarations of local variables from the start of the function to where they are actually used. What you are looking to do is speed up the ISR substantially.

2. Change the definition of SOFTPWM_FREQ in SoftPWM.cpp from 60UL to something higher. How high you can go depends on how much you have simplified the timer ISR.

Thanks DC, that all sounds pretty complicated though and I think I will struggle smiley-sad are there any easier ways?

Logged

South UK
Offline Offline
God Member
*****
Karma: 5
Posts: 583
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Bulb #2 will take PWM fine because it's obviously using resistors for current control (low power LEDs; power input 5W but light output 2.5W). Bulb #1 and #3 are using high power LEDs and will have driver chips.

It shouldn't be possible to see flickering above 100Hz and at 60Hz any flickering should be barely noticeable (do you see flickering in a 20ma/5mm LED?). I still think your problem is just that you're making the driver angry.

Could I not just use a big resistor to current limit too the 3 x 1w LEDs, and chuck out the driver circuit? I think I might prefer #2 (when/if they turn up) because of the wide viewing angle
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

have you tried a joule ringer or several joule theif's in parallel on a 1.5 v input? A joule thief would light several led's in a row with little input, you could almost power the thief's with a pwm off of the board. you could do a two turoid setup and get all the lighting you want. You could have your arduino ran through an "external chip" to turn it on and off!
Logged

Dubuque, Iowa, USA
Offline Offline
Edison Member
*
Karma: 45
Posts: 2474
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could I not just use a big resistor to current limit too the 3 x 1w LEDs, and chuck out the driver circuit?

Yes, but you don't want to. Looking at the "wide angle" bulb linked earlier, it's only driving the LED with 50% efficiency. A proper driver will do much better than that. Also, the high wattage resistors required are pretty expensive themselves, and then you also have the problem of them getting freakishly hot.

The drivers in your bulbs might have a PWM option that is not being used, but again only a look at the IC in question would provide the answer. At worst you could find a replacement driver for ~$2 that has a PWM option; drivers based on the PT4115 are pretty common.
Logged

South UK
Offline Offline
God Member
*****
Karma: 5
Posts: 583
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the driver from the bulb I have. I can't really tell what is going on apart from a bridge rectifier?



* IMG_20121228_0155451.jpg (260.01 KB, 1141x874 - viewed 38 times.)

* IMG_20121228_0155251.jpg (241.76 KB, 990x816 - viewed 34 times.)
Logged

Dubuque, Iowa, USA
Offline Offline
Edison Member
*
Karma: 45
Posts: 2474
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.datasheetdir.com/ZXLD1360+download explains everything quite nicely.

Aside from the ZXLD1360 that the driver is built around and the (unnecessary) bridge rectifier you identified, the only interesting component is the R300 (.3ohm) resistor that is used to set the max current for the driver. Per the datasheet .1 / .3 = 333ma.

I can't see in the first picture clearly due to the glare, but the pin below the "0" on the chip labeled "1360", the ZXLD1360, should be floating (soldered to a pad that goes nowhere) currently. Wire the bulb with +12V and GND, then connect to that pin through a resistor (~10K) and to a PWM output on the Arduino. Voila.
Logged

Pages: [1] 2   Go Up
Jump to: