From 9090a5c3a0520ed3f82f9028769d74fed6febccd Mon Sep 17 00:00:00 2001 From: Tibor Peluch Date: Thu, 1 Sep 2016 21:43:52 +0200 Subject: [PATCH] timer: fixed calculation of divider when using asynchronous 32kHz timer --- simavr/sim/avr_timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simavr/sim/avr_timer.c b/simavr/sim/avr_timer.c index b1de9bd..dba4e9b 100644 --- a/simavr/sim/avr_timer.c +++ b/simavr/sim/avr_timer.c @@ -462,7 +462,7 @@ avr_timer_write( // to be synced. To obtain better simulation results // p->tov_base type must be float or avr->frequency // must be multiple of 32768. - p->cs_div_clock = avr->frequency / 32768; + p->cs_div_clock = (uint32_t)((float)avr->frequency * (1 << p->cs_div[new_cs]) / 32768); } else { p->cs_div_clock = 1 << p->cs_div[new_cs]; } -- 2.39.5