From 85f097a63159103da35940cc46512ae08d0f8210 Mon Sep 17 00:00:00 2001 From: Osoian Marcel Date: Wed, 28 Sep 2022 11:28:44 +0300 Subject: [PATCH] fix the timer prescaler for 8 MHz and 2 ms tick, blink once in ~30 sec --- src/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 28d2346..23fab5e 100644 --- a/src/main.c +++ b/src/main.c @@ -80,7 +80,8 @@ void task2(void) { led_off(&led); } - if (halfSecs >= 255) { + // 0.5 sec * 60 = ~30 sec + if (halfSecs >= 60) { halfSecs = 0; } else { halfSecs++; @@ -96,7 +97,7 @@ void task3(void) { void timer0_init(void) { TCNT0 = 0; // Reset timer value - TCCR0B |= (1 << CS01); // Clock select /8 (overflow once in 2 ms) + TCCR0B |= (1 << CS01) | (1 << CS00); // Clock select /64 (overflow once in (1 / (8e6 / 64) * 255 * 1e3) = 2 ms) TIMSK |= (1 << TOIE0); // Allow overflow interrupt }