// this code sets up counter0 for an 8kHz Fast PWM wave @ 16Mhz Clock
#include <avr/io.h>
int main(void)
{
DDRB |= (1 << DDB3);
// PD6 is now an output
OCR0A = 0;
// set PWM for 50% duty cycle
TCCR0A |= (1 << COM0A1);
// set none-inverting mode
TCCR0A |= (1 << WGM01) | (1 << WGM00);
// set fast PWM Mode
TCCR0B |= (1 << CS01);
// set prescaler to 8 and starts PWM
//OCR0A = 255; //works!
while (1);
{
OCR0A = 255; //doesnt work!
}
}
Add a code snippet to your website: www.paste.org