6 8 varying pwm output volatile uint8t width positive

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: e uint8_t delay; /* used to slow the pulse width changing */ SIGNAL (SIG_OVERFLOW2) { if(delay++ == 20) { OCR2 = width++; delay = 0; } } int main (void) { /* must make OC2 pin an output for the PWM to visible */ DDRD = _BV(DDD7); /* use Timer 2 FastPWM and the overflow interrupt to update duty-cycle */ TCCR2 = _BV (WGM21) | _BV (WGM20) | _BV (COM21) | _BV(COM20) | _BV(CS21) | _BV(CS20); TIMSK = _BV (TOIE2); /* setup initial conditions */ delay = 0; /* enable interrupts */ sei (); for (;;) { ; /* LOOP FOREVER as the interrupt will make necessary adjustment */ } return (0); } 10...
View Full Document

Ask a homework question - tutors are online