Skip to main content
Tweeted twitter.com/StackArduino/status/1116219496358993920
Became Hot Network Question
edited title
Link
Duncan C
  • 5.7k
  • 3
  • 18
  • 30

Why is no PWNPWM signal generated using Timer 2?

Source Link

Why is no PWN 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 <avr/io.h>

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

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

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

    /* prescaler = 8 */
    TCCR2B |= (1 << 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