Skip to content

Commit

Permalink
fix the timer prescaler for 8 MHz and 2 ms tick, blink once in ~30 sec
Browse files Browse the repository at this point in the history
  • Loading branch information
OsoianMarcel committed Sep 28, 2022
1 parent 1395dab commit 85f097a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand All @@ -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
}

Expand Down

0 comments on commit 85f097a

Please sign in to comment.