How do I smoothly dim a LED stripe?

My goal is to dim a 12 V LED stripe. I successfully dimmed a LED stripe using PWM and different scripts. The problem is that there is always a leap from OFF (0) to ON (1 of 255). The analog output of 1 is already quite bright. I wonder if I have to adjust the PWM frequency in order to get a higher resolution of my PWM output or if I have to fetch another hardware such as the SparkFun I2C DAC Breakout MCP4725. I want to realize a very smooth breathing LED light using a function like this. I am afraid that adjusting the timer is not enough and I have to use a DAC as well. If not, I would be glad. At the moment, I work with an Arduino Uno and a Velleman LED shield. Do you have any experience and advice?

P.S. If a digital-to-analog converter (DAC) is necessary, where would I have to place it? Arduino—LED shield—DAC—LED stripe. Like this?

You can get 0-1023 PWM using the TimerOne library.

Here is a starting point:

#include <TimerOne.h>
//UNO only

void setup()
{
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);

Timer1.initialize(100);  // Frequency, 100us = 10khz
Timer1.pwm(9,512);       // 50% DC on pin 9

//Timer1.pwm(10,255);    // 25% DC on pin 10

// D.C. 
// 10KHz
// You can use 2 to 1023 
// 0 & 1 gives a constant LOW 
// 1024 gives a constant HIGH
// 2 gives ~125ns HIGH pulses
// 1023 gives ~125ns low pulses
// 512 gives 50us
}

void loop()
{
}

8-bit PWM only gives you about 25 visible equal brightness steps, because our vision is sort of logarithmic.
The lower PWM values have course steps, and the high values seem to do very little.
PWM frequency has nothing to do with it. Bit depth has. 12-bit PWM works for me.

I use a 16-channel PCA9685 breakout board for that, with constant current LED drivers.
And a library with an 8-bit equal brightness lookup table.
Never used mosfets between PCA and a LED strip.
Should work, I think.
Leo..

Indeed, PWM frequency will not help you here. Same as a DAC. If you want finer control in the lower end you need more then 8-bit PWM. Pins 9 and 10 can be made into 10-bit PWM which will give you 1/4th of the current brightness at step 1.

And like Wawa said, don't forget to add gamma correction if you want to have smooth dimming. Just doing it linear will not give you smooth :wink:

https://forum.arduino.cc/index.php?topic=417166.msg2872889#msg2872889

A gamma table of 255 for 8-bit PWM is pretty useless... I Already stretch it by using 101 steps (0 to 100%) for 8-bit PWM in FadeLed-library...

septillion:
A gamma table of 255 for 8-bit PWM is pretty useless... I Already stretch it by using 101 steps (0 to 100%) for 8-bit PWM in FadeLed-library...

I wouldn't say useless, but I use both.
The 0-255 for long/automatic/computer controlled fades.
And 0-100% for "human" interfaces.
0-100% is also easier to understand than 0-255 for the grey cells.
Leo..

I agree on the gray matter part. But a computer can use it as well, no problem. All those same values in the low range do nothing and the small steps in the high rang seem like they do nothing...