FastPWM newbie

Hi all!! I'm trying to dimmer some leds with fast pwm,
for Green&Blue i'm using this code:

  pinMode(6  , OUTPUT);//Rosso
  pinMode(3, OUTPUT);//Verde
  pinMode(11, OUTPUT);//BLU

  TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
  TCCR2B = _BV(CS22);
  
  OCR2A = 0;//BLU  PWM from 0-255     pin 3
  OCR2B = 0;//GREEN PWM from 0-255  pin 11

For the RED i'm using this one... but it dosn't work!! It always stays lightned!

  TCCR0A |= (1<<COM0A1 )|(1<<WGM01)|(1<<WGM00);
  TCCR0B |= (1<<WGM02)|(1<<CS00); 
  OCR0B = 0;//RED WM from 0-255  pin 6

Thankyou for your time!

Arduino uses analogWrite() for a PWM signal.
To dim a led, you don't need to program the registers.

TIMER0 is used by the Arduino for the system timer. The function milli() uses that.

Hi i'm multiplexing 4 led strips, analogWrite is too slow!
I'll change timer! with the other 2 it works

Hi i'm multiplexing 4 led strips, analogWrite is too slow!

Show us some figures that prove that!

Mark

I had a terrible flickering using analogWrite or digitalWrite so i tried with PORTD/C and it worked...
But i discovered why it's not working! Timer0 is used by the system, TImer1 is used by VirtualWire so i only have 2 pins of timer Timer2
So i stopped working with PWM and use fixed colors :wink: