From: Tibor Peluch <messani@gmail.com>
Date: Thu, 1 Sep 2016 19:43:52 +0000 (+0200)
Subject: timer: fixed calculation of divider when using asynchronous 32kHz timer
X-Git-Tag: v1.4~9^2~3
X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=9090a5c3a0520ed3f82f9028769d74fed6febccd;p=sx%2Fsimavr.git

timer: fixed calculation of divider when using asynchronous 32kHz timer
---

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];
 		}