Arduino frequency control for led fade

Hi

I'm using the arduino uno to achieve led fade in/out on pin 9 (980hz default output). I'm seeing a very small flicker when it reaches the lower fade level. I am also aware that arduino analogWrite can't go lower than 1% analogWrite(ledpin, 1) .Most people can't see the 8bit resolution at 256step but I can and it's annoying. I have read countless articles on this subject and I am aware that it's possible to use timer1 fast pwm to solve issue. From using timer1 I noticed it's much better. I'm also using cos fade function to provide a smooth dimming.

My question is: Will a higher output frequency on the 8bit res solve the issue as well without using timer1. For example changing the default prescaler. I am trying not to use the timer1 library because I also have to upload it eventually to attiny chip which will not be able to support that library and I would then have to manipulate the registers directly. I'm trying the get away from all of this extra coding.

A friend of mine suggested using a proper led driver that can dim down at about 0.1% at a frequency of 5000Hz - 10 000Hz with an input pwm arduino signal 200 - 1000Hz.
It might solve the issue but it's another component extra.
I don't won't to use a DAC or digital pots. Been there done that and still same issue.

Can anyone provide a suggestion.

This is NOT 1% but approximately 0.4% (1/255 = 0.0039). If you see flashing at low brightness, then you need a higher frequency. You can easily try this as you have guessed by changing the PWM divider.
https://arduinoinfo.mywikis.net/wiki/Arduino-PWM-Frequency

If none of this helps, you can try ESP8266. It has commands with which you set the operating frequency (from 100Hz to 40kHz) as well as the range or bit size of the PWM (from 4 bit to 16 bit if i remember corectly). Or you can use a specialized LED driver that meets your criteria.

Hi Flashko

Much appreciated for your reply. I tried the prescaler and tested the difference between the default and higher frequencies.

I think the if I can get to at least 2khz it will be ok. I'm not sure if different frequencies are available seeing the prescalers are 1, 8, 64 etc. I have also never messed around with trying to achieve different output frequencies besides the default values depending on the pin outputs.
Going from prescaler 64 to 8 is to much.
Is there a way to achieve a specific frequency output by using just a few code lines.
I'm doing internet search now to see what I can try. The other solution is to buy a 16bit mcu but then I have compatibility issues to solve.

set timer 0 divisor to 8 for PWM frequency of 7812.50 Hz
set timer 0 divisor to 64 for PWM frequency of 976.56 Hz

Yes, only 1 line of program code. Did you see my first link, not the second? For example, for pin 9, you only need to add
TCCR1B = TCCR1B & B11111000 | B00000010;
in 'void setup ()' and so you change the frequency of pins 9 and 10 to about 3920Hz. For LEDs, this and even higher frequencies are not a problem.

No.

Yes it can. You can get it down to zero which will be off, which I believe is what you want it to do.

It worked brilliantly!. I had issues with the time (period) but as expected when frequency changes the time will also change.

I will adopt same strategy with attiny registers.

Thanks a lot.

So fine if you were happy with it. Have you tried viewing it in the dark?

It is fundamentally the wrong way to do it. I don’t think you understand the JND (just noticeable difference) requirements of the eye.

So for any one else reading this thread later I would not recommend it.

I just moved house and changed states so I've looked at it in the dark yet but I'll try it.

What would you suggest then if this isn't a good solution.

Like I said in reply #5, take the analogWrite function down to zero. Then it is off.