Why is no PWM signal generated using Timer 2? I managed to work with timer 0 and 1 but am unable to generate a PWM with timer 2 in my atmega328p.

This is the code:

#include &lt;avr/io.h&gt;

int main(void)
{
    /* PD6 output */
    DDRD |= (1 &lt;&lt; DDD6);

    /* 50% duty cycle */
    OCR2A = 128;

    /* fast PWM  */
    TCCR2A |= (1 &lt;&lt; WGM21) | (1 &lt;&lt; WGM20);

    /* prescaler = 8 */
    TCCR2B |= (1 &lt;&lt; CS21);

    while (1);

}


Could someone explain what the issue is and why I am not seeing a pwm signal on pin 6 of my arduino uno board?

Thanks
The output compare unit of timer 2 is connected to pins PB3 (OC2A) and PD3 (OC2B). So you have to configure those as outputs.
Keep in mind that you can't choose any pin when using hardware pwm, this hardware feature is linked to specific pins.

You also have to set COM2A1 in TCCR2A. Otherwise OC2A is disconnected from the output compare unit (ref: Table 17-3 in datasheet).
The effect of COM2A0/1 depends on the configuration in WGM20-WGM22.
The same applies to OC2B respectively.