From ccad49469feb37e21424df67c385e53c95459668 Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Wed, 14 Apr 2010 18:05:12 +0100 Subject: [PATCH] timer: Fixed an off by one That was breaking the timers badly in corner cases Signed-off-by: Michel Pollet --- simavr/sim/avr_timer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simavr/sim/avr_timer.c b/simavr/sim/avr_timer.c index 803adf7..cb2c99f 100644 --- a/simavr/sim/avr_timer.c +++ b/simavr/sim/avr_timer.c @@ -110,7 +110,7 @@ static avr_cycle_count_t avr_timer_tov(struct avr_t * avr, avr_cycle_count_t whe if (p->comp[compi].comp_cycles) { if (p->comp[compi].comp_cycles < p->tov_cycles) avr_cycle_timer_register(avr, - p->comp[compi].comp_cycles - (avr->cycle - p->tov_base), + p->comp[compi].comp_cycles, dispatch[compi], p); else if (p->tov_cycles == p->comp[compi].comp_cycles && !start) dispatch[compi](avr, when, param); @@ -187,7 +187,7 @@ static void avr_timer_configure(avr_timer_t * p, uint32_t clock, uint32_t top) for (int compi = 0; compi < AVR_TIMER_COMP_COUNT; compi++) { uint32_t ocr = _timer_get_ocr(p, compi); - float fc = clock / (float)(ocr); + float fc = clock / (float)(ocr+1); p->comp[compi].comp_cycles = 0; // printf("%s-%c clock %d top %d OCR%c %d\n", __FUNCTION__, p->name, clock, top, 'A'+compi, ocr); -- 2.39.5