From a3192fc431ab39b25befab3b146f39096cced0bc Mon Sep 17 00:00:00 2001 From: Marco Date: Sun, 29 May 2022 16:47:15 +0200 Subject: [PATCH] Introduce functions that configures Timer 1 with Fast PWM. --- src/include/timer.h | 1 + src/timer.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) 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 */