diff --git a/src/include/timer.h b/src/include/timer.h index a751398..828c4f3 100644 --- a/src/include/timer.h +++ b/src/include/timer.h @@ -1,3 +1,4 @@ +void initPwmTimer1(void); void initCtcTimer0(void); void initOverflowTimer0(void); void initOverflowTimer1(void); \ No newline at end of file diff --git a/src/timer.c b/src/timer.c index c04ad11..1fbc712 100644 --- a/src/timer.c +++ b/src/timer.c @@ -6,6 +6,28 @@ #include "include/timer.h" +void initPwmTimer1(void) +{ + /* Enable Fast PWM with TOP in OCR1A */ + TCCR1A |= (1 << WGM11) | (1 << WGM10); + TCCR1B |= (1 << WGM13) | (1 << WGM12); + + /* Clock prescaler of 8 */ + TCCR1B |= (1 << CS11); + + /* Set OC1B on compare match, clear OC1B at TOP */ + TCCR1A |= (1 << COM1B1); + + /* Enable Counter1 Compare Match B Interrupt */ + TIMSK1 |= (1 << OCIE1B); + + /* TOP value */ + OCR1A = 1000; + + /* Compare Match with OCR1B */ + OCR1B = 900; +} + void initCtcTimer0(void) { /* Initialize counter 0 */