## smoother RGBW LED fading

raspbee
Posts: 40
Joined: Tue Sep 25, 2012 1:25 pm

### smoother RGBW LED fading

I was experimenting with LED fading quite a while ago for a lightning clock.
I controlled a RGBW strip once with milight however this was limited to 17 steps of brightness and I wasn´t really satisfied with that because I already woke up with the first step

Now I started a more direct control through pigpiod but I am still not really happy as the white LEDs get bright pretty quick.

I am wondering if there is a way to achieve more than 255 steps of PWM or is that a technical limitation?

Heater
Posts: 12976
Joined: Tue Jul 17, 2012 3:02 pm

### Re: smoother RGBW LED fading

raspbee,
Now I started a more direct control through pigpiod but I am still not really happy as the white LEDs get bright pretty quick.
Be aware that human sense perception is not linear. It's logarithmic. A perception of twice the brightness requires 10 times more intensity. This is known as "Fechner's Law". From wikipedia:
Fechner's law states that the subjective sensation is proportional to the logarithm of the stimulus intensity.
Given that fact we see that in order to achieve a perceived, smooth, linear increase in brightness over time we need to crank up the power in steps of 10 or at least logarithmically.

I have never played with this but I suspect 255 steps of PWM should be fine. Just use PWM settings like, 0, 1, 3, 7, 15, 31, 65, 127, 255.

You will have to arrange that step 1 is barely perceptible.

raspbee
Posts: 40
Joined: Tue Sep 25, 2012 1:25 pm

### Re: smoother RGBW LED fading

Hmm doesn´t make much sense to me to make the steps wider if already from 1 to 2 is a too big step, why should 1 to 3 be better?
My problem is that I recognize the steps visibly like a step but I want to recognize it as a flow.

Let´s assume I´d like to simulate a sunrise over 15 minutes. (I want a slow wake-up so it is more likely to have 20 minutes or more.)
That is 900 seconds / 255 = 3,5. Because I only have 255 steps I have to climb the stairs all 3,5 seconds and that is not smooth.

It does look smooth if you fade in 128 seconds or maybe 64 but not if you need more than a second per step.

rzusman
Posts: 346
Joined: Fri Jan 01, 2016 10:27 pm

### Re: smoother RGBW LED fading

I made an PWM LED dimmer for a friend’s art project, using a Silicon Labs processor.
The 8-bit PWM looked fine, until the LEDs were very dim, and then the last 8-10 steps or so were very abrupt. When I used the 16-bit PWM, the fades were perfectly smooth, all the way to zero brightness.

So, PWM granularity is important.

joan
Posts: 14093
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

### Re: smoother RGBW LED fading

PWM has two attributes. 1) the frequency, and 2) the number of steps between on and off.

With pigpio if you drop the frequency there will be more steps between on and off.

E.g. see http://abyz.me.uk/rpi/pigpio/pigs.html#PFS and http://abyz.me.uk/rpi/pigpio/pigs.html#PRG (there are similar functions for C and Python).

raspbee
Posts: 40
Joined: Tue Sep 25, 2012 1:25 pm

### Re: smoother RGBW LED fading

Thanks, this stuff I need to learn obviously. Didn´t know the parameters can bes set for pigs.
A different processor is probably too much tech for me but I´ll google around.

Return to “General programming discussion”