Change PWM pin of Timer2 from D3 to D11

Hello I have found this code (from tutorial):

pinMode(3, OUTPUT);
  TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
  TCCR2B = _BV(WGM22) | _BV(CS20);
  OCR2B = 0;

It is working nice on pin 3 but in my case this pin is used for other purpose (AttachInterrupt for rotary) I'm trying to change PWM pin from D3 to D11, by keeping generated PWM without any luck. Can someone explain me what need to be changed in timer configuration to move PWM to D11? ...

Arduino Pro Mini (Atmega328p)

see the datasheet

I so the datasheet, but changes does not work (pin staying high without any PWM).
That’s way I’m asking here for some extra explains or example.

Fire1: I so the datasheet, but changes does not work (pin staying high without any PWM). That's way I'm asking here for some extra explains or example.

is it ATmega328p on Uno or Nano or Mini or ...?

Ohh..., sorry miss this... For Arduino Pro mini (atmega328p) Thanks for attention!

Hello I have found this code (from tutorial):

I expect there is more than that snippet.

I so the datasheet,

What did the data sheet tell you about the mode of operation of the timer with those settings?

This timer setup needs to generate 250khz PWM. In general I know I need to change OCRnA and OCRnB registers in order to switch from pin D3 to D11, but by switching values doesn't affect pin PWM

Don't know why some of the helpers "help" with questions not with corrections.

So... This is the answer:

// pin 3 output
    TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
    TCCR2B = _BV(WGM22) | _BV(CS20);
    OCR2A = 63;
    OCR2B = 0;

Or in my case pin 11 as output:

    // pin 11 output
    TCCR2A = _BV(COM2A0) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
    TCCR2B =  _BV(WGM22) | _BV(CS20);
    OCR2A = 0;
    OCR2B = 63;

Switching TCCR2A = _BV(COM2A*1) to TCCR2A = _BV(COM2A0*) changes the port

Generated PWM is moved to Port B , but duty cycle cannot be changed.

If I'm wrong, PLEASE correct me!

You should post a COMPLETE code that compiles and demonstrates the problem.

ok... here is my test:

void setup() {
    pinMode(11,OUTPUT);
    TCCR2A = _BV(COM2A0) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
    TCCR2B =  _BV(WGM22) | _BV(CS20);
    OCR2A = 63;// compare reset
    OCR2B = 0;
    Serial.begin(115200);
}

uint8_t pwm = 0;
void loop() {
    if (pwm > 63) {
        pwm = 0;
    }
    OCR2B = pwm;
//    OCR2A = pwm;
    Serial.println(pwm);
    delay(150);
    pwm++;
}

Notice: As far as i get, it is impossible to be D11 since OCR2A /OCR2B are in compare-reset mode

With bits set in WGM22 WGM21 and WGM20 you are in the Fast PWM to OCR2A mode. OCR2A set the frequency of the Timer repeat. The reason you got output on pin 11 by changing the bit setting of of COM2A from 1 to 0 is that you set that output to toggle on compare match.

I think that you should be seeing 50% duty cycle at 125Khz.

When you use fast pwm to OCR2A you can not get variable duty cycle on pin 2A.

An excellent tutorial on Timers is by Nick Gammon https://www.gammon.com.au/timers The Timer register summarys sheets at reply #18 are a good companion to the full AT328 data sheet.

Don't know why some of the helpers "help" with questions not with corrections.

I was tying to get you to do some research and think, and come up with the answer by yourself rather than just give it to you. I wanted to encourage learning. When you get into low level timer control with register settings, you need a good understanding of the details.

What did the data sheet tell you about the mode of operation of the timer with those settings?

The goal of this question was for you to discover "Fast PWM to OCR2A" and to understand that the pin 11 pwm output was not available because the normal OCR2A compare match duty cycle control setting was being used to set frequency.