working with avr and pwm
I seemed to have a lot of trouble getting pwm code going. below is some simple code that got me going. looking back on it now I am unsure as to why I was having such problems. I think its because, arduino, port codes, and timer codes, and pwm codes dont exactly match and I wasnt looking at the reference material. anyways hope this helps.
int main (void)
{
DDRD |= (1<< PD3) | (1<< PD5) | (1<< PD6);
TCCR0A = (1<<COM0A1)|(1<<COM0B1)|(1<<WGM01)|(1<<WGM00);
TCCR0B = (1<<CS00);
TCCR2A = (1<<COM2A1)|(1<<COM2B1)|(1<<WGM21)|(1<<WGM20);
TCCR2B = (1<<CS20);
OCR0A = 0;
OCR0B = 100;
OCR2B = 255;
sei();
while (1)
{
;
}
}
Tags: avr, programming