-->
Page 1 of 2

Problem dimming LEDs with PWM

PostPosted: Thu Feb 02, 2017 10:17 am
by Mikew
Hi,
I'm making an LED dimmer using an ESP8266. The intent is to control brightness with PWM that is adjusted by sending UDP strings to it. I noticed something strange when using analogWrite to a pin. The LED only gets brighter on odd numbers. Going from 0 to 1 makes the led come on very dim. An analogWrite 2 makes no difference. 3 makes the led a bit brighter. 4 makes no difference etc. It doesn't matter what I set the analogWriterange to. 1023 or 255, same affect. I've tried a few different 8266s so its not a defective device.
I'm using arduino 1.81. Is this a known bug?

Re: Problem dimming LEDs with PWM

PostPosted: Sun Feb 05, 2017 10:33 am
by g6ejd
Observations: The ESP8266 is not a hardware PWM implementation, so software based and uses interrupt initiated timers, therefore there will be a small amount of variability in PWM output/lengths. At low PWM values I have noticed occasional flickering of LED's like a short burst of full brightness followed by periods of correct brightness, which I presume is a function of other activity like network tasks taking priority. Try a slower PWM frequency, I don't know what frequency your using but maybe 100-200Hz would help reduce flickering.

The affect your seeing is probably due to PWM resolution as AFGAIK the PWM does not change until a threshold of change has been detected, perhaps increase your brightness levels in steps of 2 or more. What resolution does your programme work to 1024? the same as the PWM channel?

Re: Problem dimming LEDs with PWM

PostPosted: Sun Feb 05, 2017 11:48 am
by peut
I don't know if PWM is correctly changing duty cycles or not, as I have no oscilloscope.
But there is gamma correction to consider. Depending on the LEDs you are using, and assuming you use
the default 1024 resolution, you can observe ranges of sometimes 100 were the observed difference in brightness is minimal or invisible.
Dimming LEDS of different types show these gammas to vary widely.
A good example is your exact case: the difference between "Off"=0 and "On"=1 is bound to be more noticeable then the difference between 1/1024 and 2/1024 of brightness.
I have a number of different LEDs and LED strips and have just dealt with it by using a gamma correction table. I don't have the urls at hand, but Google yields rich results.

Re: Problem dimming LEDs with PWM

PostPosted: Mon Feb 06, 2017 12:26 am
by altonroot
it's valuable information...thank you for sharing