Go Down

Topic: PWM control of many LED's from arduino (Read 2477 times) previous topic - next topic

dtokez

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.

HazardsMind

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.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

Chagrin

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.


dtokez

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?

dhenry

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.
...


dc42

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.
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.

dhenry

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


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.

Chagrin

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


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.

dtokez


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 :( are there any easier ways?


dtokez


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


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

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!

Chagrin

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.

dtokez

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


Chagrin

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.

Go Up