PWM Timers/Modes ETC

I don’t know if this is the right section or not, it’s nothing really to do with LEDs other than I happen to be using PWM to drive LEDs in this case but…

I’ve been reading → http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM and it’s becoming a bit clearer now.

I’m using all 6 PWMs to control 2 sets of RGB LEDS. The LEDS connected to 3,5,6 seem to be pulsating under certain circumstances and I’m pretty sure it’s isolated to just the reg and green channels.

I’m guessing that 2 of the 6 PWMs are setup in a different way or one of the 3 timers is doing something different and this is causing the flickering I can see.

So how do I get all my PWM working in the same way? I do use millis() in my code so I need to keep that working too. I’m not too fussed what mode/freq the PWMs use, as long as all 6 are the same and you can’t see the LEDs flickering.

Any ideas?

OK, so aparently the PWMs are setup as follows by default...

TCCR0B = 0x01; // Timer 0: PWM 5 & 6 @ 16 kHz - Fast PWM TCCR1B = 0x01; // Timer 1: PWM 9 & 10 @ 32 kHz - Phase-Correct PWM TCCR2B = 0x01; // Timer 2: PWM 3 & 11 @ 32 kHz - Phase-Correct PWM

How do I set all 3 to 16 kHz / Phase-Correct PWM, and will this allow millis() to still work and my LEDs still look pretty?

I'm not really sure how but adding the follwoing line of code has fixed it...

TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);

Which in theory has set Timer2 (pins 3 + 11) to fast PWM and a divider of 64

So as is my understanding all 3 timers are running differently, but it seems to work so I'm not complaining.

Can anyone explain this?

well that's not cured it completely - which makes sense because timer1 isn't in fast PWM mode.

I've tried TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM12) | _BV(WGM10);

and this should put it in fast PWM mode but I think the compare settings are wrong because adding this make it go completely wrong.

Does anyone know the register values I need to set to get all 3 timers working in the same way?

I'd message grumpymike and/or Crossroads. You can probably find their profile by browsing a few threads here. they are very active and very knowledgeable about this kind of stuff.

Many people here speak from experience, those guys speak from knowledge.