Running Fast PWM on Uno's Pin 11

Hello,

I am trying to run Fast PWM on pin 11 calling on it like so:

  TCCR2A = 0b00000011;
  TCCR2B = 0b00000001;//Prescaler=1

I'm trying to get 31.4kHz but it's not behaving correctly. I tried the same on the other eight bit register TCCR0A and it works. I have plans to use pins 5 and 6 for another part of my project.

Am I over looking something?

Am I over looking something?

Setting pin 11 to an OUTPUT? Setting an output compare mode in COM2A1 and COM2A0?

Sorry I'm asking a dumb question, but I'm trying learning.

Why will Pin 5 and 6 work TCCR0A works but for pins 11 and 3 it doesn't work? Isn't Pin 11 output a PWM frequency?

I'm not sure what your questions are?

Setting pin 11 to an OUTPUT? Is there anywhere in your code where you set the pinMode of pin11 to be an output. The default setting is to INPUT.

Setting an output compare mode in COM2A1 and COM2A0? PWM duty cycle depends on output compare mode set by the bits in COM2A1 and COM2A0

COM2A1 COM2A0 Description 0 0 Normal port operation, OC2A disconnected. 0 1 Toggle OC2A on Compare Match 1 0 Clear OC2A on Compare Match, set OC2A at BOTTOM (non-inverting mode) 1 1 Set OC2A on Compare Match, clear OC2A at BOTTOM (inverting mode)

Perhaps you should have a read of this https://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM

Please provide a minimum example of complete code which compiles and demonstrates your problem.

cattledog: Setting pin 11 to an OUTPUT? Is there anywhere in your code where you set the pinMode of pin11 to be an output. The default setting is to INPUT.

Yes in my code I have it set to an output, and yes I also seen that sight. I under stand how COM0A1 works, I am comparing TCCR0A to TCCR2A, since the are both 8 bit registers.

I should be able to set pin 11 in Fast PWM with mode 3 (00000011), and have an output of 31.4 kHz and no prescale (00000001).

If you read my initial post, I have pin 6 working to produce the fast PWM 62.5 kHz but I need use those pins in another part of my project.

When I set pin 11, in the same method (change TCCR0A to TCCR2A) it produces the default.

If you set the mode and the prescaler, you should be able to call the pwm output with analogWrite(11, value) and that function will set the bits in TCCR2A for non inverting output.

If you try to set OCR2A directly in the code, you will nedt to set the bit in COM2A1.

The code you provided is incomplete and the rest of your mistake is in the parts of the code you did not post. If you can post a complete sketch showing Timer2 acting differently from Timer0 it might be possible to point out why.