PWM Atmega328 (Arduno Uno)


I am following the tutorial on PWM ( What I don’t get is why, when setting TCCR2A/B and the OCR2A/B, the signal goes to pin 3 and 11. I am using an arduino UNO, which has an ATMEGA 328P-PU. In the Pin Layout on side 3 in the manual Pin 11 (PD5) says (PCINT21/OC0B/T1). Doesn’t OC0B refer to the Output pin if timer 0? It also states in 14.3.3 that PD5 (Pin 11) alternate function is connected to OC0B Timer/Counter0 Outpute Compare match. When using the Fast PWM Mode of the example

pinMode(3, OUTPUT);
pinMode(11, OUTPUT);
TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(CS22);
OCR2A = 180;
OCR2B = 50;

the output goes to Pin 11.So the example is working as stated. I don’t get why! To my understanding there should be only a signal at (PCINT19/OC2B/INT1) PD3 and PB3 (MOSI/OC2A/PCINT3). Am I reading the datasheets wrong?


In the question you keep referencing timer 0. But in the code you are messing with timer 2.

Timer 2 outputs on pins 3 and 11. The OCR2B compare match gets output on pin 3, and the OCR2A compare match is output on pin 11.