RGB LED flickering

Hi,

I am controlling an RGB LED strip using PWM Pins 9,10,11 according based on this tutorial:

When I dim the light the LEDs start flickering. Shouldn't the the PWM frequency be high enough so that i cant see the flickering?
Does anyone knows the the standard frequency of PWM? Should I manipulate the PWM frequency?

Tanks in advance

Its kinda hard to tell what is happening and not. It sounds like maybe you are trying to run the whole strip of LEDs off the arduino, which sounds like too much current for the arduino, but then again, its hard to say from here.

If you can include more details (like show us the entire circuit, including power supply, how many LEDs, which type of arduino you are using, ...)

The standard Arduino PWM frequency is 488Hz, which is high enough to avoid visible flickering.

Most beginners forget to connect the ground of the 12V power supply to the ground of the arduino.

I use an Arduino "compatibel" to the Nano 328. I am using mosfets so the LEDs strip current does not flow over the arduino and the ground and the +12V supply are the same for the arduino and the LED Strip. The wiring is identical to the tutorial:Usage | RGB LED Strips | Adafruit Learning System

If you do it right with the right components you should not see any flicker.

Mike can you also tell me which are the right components?

The components mentioned in the artical and not a subistitute that you think might work.

Shouldn't the the PWM frequency be high enough so that i cant see the flickering?

Your eyes do get better at preceiving flickering at low brightness. What you observe could be due to that.

What do you actually mean by flickering?
Is it perceivable looking directly at the light?
Or is it that you want to see no flicker as you rapidly scan your eyes across the field of view that contains the lights?

Hi lukeskymuh, I believe I might be encountering the same issue as you. The flickering I encounter is when the leds are dimmed to a low pwm value, they flicker in a way a candle flame does right before it goes out. Not like a refresh rate problem. I thought it was my hardware but I realize now I am not encountering the problem when I set the pwm to a fixed value, or strobe it with a simple loop. Turns out, the only time I can get this flicker to happen is when running that color swirl code form adafruit which you linked to. We have different hardware setups, but we are using that same bit of code. Do you have the flicker when setting the pwm to a value of 10 or when doing a simple pwm increase loop on the leds?

-Sathi

Sathi:
Hi lukeskymuh, I believe I might be encountering the same issue as you. The flickering I encounter is when the leds are dimmed to a low pwm value, they flicker in a way a candle flame does right before it goes out. Not like a refresh rate problem. I thought it was my hardware but I realize now I am not encountering the problem when I set the pwm to a fixed value, or strobe it with a simple loop. Turns out, the only time I can get this flicker to happen is when running that color swirl code form adafruit which you linked to.

What TLC library is that using? It's definitely possible to cause flicker by not controlling the chip properly.

No where in the thread was the TLC mentioned, yet you guessed that I might be using it? I am indeed. Is this a known issue? When I get home I will check what version of the library I have. Thanks.

-Sathi

I am using the Tlc5940_r014_2 library. I am pretty sure it is the newest one from the google code page at:

http://code.google.com/p/tlc5940arduino/downloads/detail?name=Tlc5940_r014_2.zip&can=2&q=

Not sure what the deal is, but I can generate all sorts of weird artifacts based on different code parameters. If I increase
the pwm values at a slow rate, the leds increase in brightness in pulsating sort of pattern, like they are breathing. At faster speeds things look smooth. But I can't get it to fade slowly from one color to the next in a smooth manner. Especially at low
pwm values where they have that strange candle light like flicker. I'll avoid hijacking this guys thread and make a new topic on this I can't get it worked out. Thanks.

-Sathi

Know this is old but I thought I'd just chime in here as this was doing my head in!
I was seeing the exact same thing and no change in the code seemed to fix it.
It was barely noticeable on the red channel, but very noticeable on green and a bit less on blue.
Anyway, I was using a 12V 1A adapter and even though the strip i was using should have been drawing less than that, when I swapped it for a 6A unit, all flickering ceased.

Anyway, I was using a 12V 1A adapter and even though the strip i was using should have been drawing less than that, when I swapped it for a 6A unit, all flickering ceased.

That is probably because you did not have enough decoupling capacitors on your power supply. A couple of caps would have saved you from buying a 6A supply.

Grumpy_Mike:
That is probably because you did not have enough decoupling capacitors on your power supply. A couple of caps would have saved you from buying a 6A supply.

Seems I misread the current draw for the strips. With the 6A supply connected I measured 3A draw at %100 white. Stats were correct, I was just not accounting for the correct strip length.

3A from a 1A supply. Flickering should have been the least of my worries!

ok, sorry to rebump and old post but I also encountered this very issue and found it annoying enough to fight it tooth and nail...

I think I won :wink:

and the solution for me, was to force phase-correct PWM mode on timer0, based on this article: https://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM

(I was using pins 5, 6, 9 on an ATmega328P, 5+6 being controlled by timer0)

of course, that means that milliseconds now last twice as long :wink: but I can live with that :wink:

maybe it will help someone who has the same kind of problem...

btw, the flickering does seem to depend on the current drawn (as it was way less noticeable and sometimes completely unnoticeable with a shorter strip) but even though my LED strip draws ~1.5Amp, even buying a 5Amp power supply for it didn't solve the issue before I tried the timer tweak.

best,
blue.

I'm a bit sorry as this thread is so old, but I'm also so near to the solution...

@blueshade how did you do it?
I've read the article, but I'm new to Arduino and honestly I haven't understood it 100%, I only got what the exact problem is. It would be very nice if you could provide the code which got it working for you.

Have a nice day,
maprambo

I got it!
I found this article: Arduino Playground - TimerPWMCheatsheet
I think it's a bit better explained here how you get to a solution.
So I just put this into setup:

void setup() {
   TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM00);
   // other setup stuff
}

and made this change in the wiring.c file (revert this change! only use it for this one sketch so that the millis and delay are correct here):

// the prescaler is set so that timer0 ticks every 64 clock cycles, and the
// the overflow handler is called every 256 ticks.
#define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 510))