PWM RGB flickering (solved)

I have a standard SMD5050 LED strip from china that came with a 44key remote and a small RGB controller. I wanted to replace the RGB controller with an Arduino Nano however I have now have a fast flickering problem with PWM driven RGB lights.

Using an Arduino Nano + IRLB8721 Mosfets to drive 12v non-addressable RGB SMD5050 led strip. Using FastLED Example called "AnaogOutput.ino" and these PWM pin assignments.

define PIN_RED 3

define PIN_GREEN 5

define PIN_BLUE 6

Tutorial I followed to wire it up.

Problem 1:

  • individual non mixed colors are fine with no flicker on their own. e.g. only red, or only blue
  • red+green solid color - high frequency flicker
  • red+blue solid color = high frequency flicker.
  • green+blue solid color = smooth with no flicker.

Is the flickering caused by PWM pin 3 runs at 490Hz and pin 5,6 run at 980Hz?

Can I make pin 3, 5 and 6 have identical PWM? Is there a recommended PWM frequency for AnalogOutput?

Additional testing with PWM:

TCCR2B = TCCR2B & B11111000 | B00000111; // for PWM frequency of 30.64 Hz pin 3 11 made flicker much worse

TCCR2B = TCCR2B & B11111000 | B00000011; // for PWM frequency of 980.39 Hz pin 3 11 made flicker a bit better

There seems to be various modes for the timers. How do I get pwm on pin 3 have the same pwm settings as pin 5 and 6?

I've also read that there may be a way to calculate the optimal PWM frequency for the mosfets and LEDs - however I have no idea how to figure that out.

https://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM

==== Additional background. The reason why I'm switching from stock RGB controller to a Arduino Nano is so I can add MySensors + custom lighting animations.

Found the solution to the flicker problem on "SecretsOfArduinoPWM" page: - pins 5 and 6 use "Fast PWM" on Timer0 at 980Hz. - pins 3 and 11 use "Phase-Correct PWM" on Timer2 at 490Hz Solution was on the page was to set pins 3 and 11 Timer2 to "Fast PWM" at 976Hz with the following code:

void setup(){
  // Set pin 3 and 11 on Timer2 to "Fast PWM" 976Hz
  TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
  TCCR2B = _BV(CS22);
  pinMode(PIN_RED, OUTPUT);
  pinMode(PIN_GREEN, OUTPUT);
  pinMode(PIN_BLUE, OUTPUT);
}