Go Down

Topic: RGB LED flickering (Read 13307 times) previous topic - next topic

Grumpy_Mike

#15
Apr 07, 2015, 10:07 pm Last Edit: Apr 07, 2015, 10:08 pm by Grumpy_Mike
Quote
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.

TijuanaKez

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!

blueshade

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 ;)

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 ;) but I can live with that ;)

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.

maprambo

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

maprambo

I got it!
I found this article: http://playground.arduino.cc/Main/TimerPWMCheatsheet
I think it's a bit better explained here how you get to a solution.
So I just put this into setup:
Code: [Select]
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):
Code: [Select]
// 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))

LGMan

Does anyone have the correct way to set timer 1 and 2 to fast pwm, rather than timer 0 to phase correct?
I'm running 2 RGB strips, so I'm using all 6 PWM pins.
I've tried following other guides for this, but they all seem to assume you'd only want to set timer 1. My attempts to set timer 2 to anything else have it either not fix the problem, or it gets some massive deadspots for all values between about 50 to 225(I think its accidentally set to 16 bit mode). Timer 2 acts differently to timer 1, and I dont really know what I'm doing.
Setting timer 0 to phase correct PWN mode definitely solves my flicker problem, but I have a lot of code with some delicate delay interdependence, so I'd rather not have to adjust it all if I dont have to.

gkarnavat

I think it is explained in this video:  Why I'm switching over from the awesome Arduino IDE to Atmel Studio

https://youtu.be/648Tx5N9Zoc

timkolson

Old thread, but I thought this may be helpful for those new to this (like me).

I am driving a single 16ft led rgb strip using IRLB8721 N channel mosfet's, with a 12v 5a power supply connected to the barrel jack on the uno.  The VIN is connected to the +12v lead on the rgb strip.   This was following the adafruit example here: https://learn.adafruit.com/rgb-led-strips/usage  

I was experiencing PWM led rgb flicker as well, once the duty cycle wasn't 100%.  As other's have mentioned, different pins have a different frequency depending on their timer.

On Arduino Uno ATmega328P, the frequencies are defined in the previously mentioned article, http://playground.arduino.cc/Main/TimerPWMCheatsheet.  

I was originally using pin's 3 (red),5 (green) and 6 (blue) and noticed the flicker almost immediately when changing values.  

The solution is very simple if you only need to drive one strip (3 pins). In my case, choosing pins with the same frequency works fine. e.g., 3, 9, 10 which all have the same frequency of 490.2.  Dimming, fading, etc., all works great.

Hope this helps!





Wawa

#23
Mar 17, 2018, 01:28 am Last Edit: Mar 17, 2018, 01:42 am by Wawa
I am driving a single 16ft led rgb strip using IRLB8721 N channel mosfet's, with a 12v 5a power supply connected to the barrel jack on the uno.  The VIN is connected to the +12v lead on the rgb strip.
Not ok.
There is a reverse protection diode between the DC socket and V-in with a max rating of 1Amp.
Drawing more than 1Amp through the Arduino board will eventually fry that diode.

That diode also has a volt drop of ~1volt@1Amp, that will make your strip less bright.

Power the strip (12volt and GND/mosfet) directly from the supply, and the Arduino through the DC socket.
Leo..

Go Up