Mega 2560 Fast PWM Problems With Timer 3

I believe that I have everything set correctly but I am not getting a PWM frequency of 1.953KHz. I am just getting a blip every now and then from the pins listed. I have been through the datasheet over and over many times trying to figure out what I did wrong. Any assistance would be greatly appreciated.

void setup() {

  DDRE = (1 << PORTE3) | (1 << PORTE4) | (1 << PORTE5); //Set Pins D5, D2, D3 As OUTPUT

  TCCR3A = 0b10101000; //Use Channels A, B And C

  TCCR3B = 0b00011001; //Fast PWM - No Prescaler

  ICR3 = 8191; //Set The Top Limit - (8,192 - 1) = 8,191 - Frequency = 1.953kHz

  OCR3A = 3240; //Set The Starting Point For D5 Low Enough So The Mosefet Is Off
  OCR3B = 3240;
  OCR3C = 3240;

}

void loop() {

}

I was able to fix my issue by changing this line:

TCCR3A = 0b10101000;

To this:

TCCR3A = 0b10101010;

Everything is working perfectly now. Hopefully this post will be able to help others.

Why do you think WGM33:0 = 0b1100 is Fast PWM?

==

Oops I was too slow. I had tried your sketch in Wokwi with a scope on D5.

Thank you for your valuable input DaveX. The chart you posted shows where I went wrong.

Silly me was trying to set it for PWM, Phase and Frequency Correct which is 00.

Lucky for me that I found my error. lol

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.