fix timer bug- if delay is smaller than TICK_TIME but counter has passed delay when timer is set, it will wait a whole TICK_TIME before firing instead of setting comparator to fire at correct time
check next_step_time instead of delay in comparison Reported-by: Markus Amsler <markus.amsler@oribi.org>
This commit is contained in:
parent
553f3a50a6
commit
00fc05a49b
8
timer.c
8
timer.c
|
|
@ -31,9 +31,9 @@ ISR(TIMER1_CAPT_vect) {
|
||||||
clock_counter_10ms -= 10;
|
clock_counter_10ms -= 10;
|
||||||
clock_flag |= CLOCK_FLAG_10MS;
|
clock_flag |= CLOCK_FLAG_10MS;
|
||||||
|
|
||||||
clock_counter_250ms += 10;
|
clock_counter_250ms += 1;
|
||||||
if (clock_counter_250ms >= 250) {
|
if (clock_counter_250ms >= 25) {
|
||||||
clock_counter_250ms -= 250;
|
clock_counter_250ms -= 25;
|
||||||
clock_flag |= CLOCK_FLAG_250MS;
|
clock_flag |= CLOCK_FLAG_250MS;
|
||||||
|
|
||||||
clock_counter_1s += 1;
|
clock_counter_1s += 1;
|
||||||
|
|
@ -99,7 +99,7 @@ void setTimer(uint32_t delay)
|
||||||
// "fire" ISR- maybe it sets a new timeout
|
// "fire" ISR- maybe it sets a new timeout
|
||||||
timer1_compa_isr();
|
timer1_compa_isr();
|
||||||
}
|
}
|
||||||
else if (delay <= TICK_TIME) {
|
else if (next_step_time <= TICK_TIME) {
|
||||||
OCR1A = next_step_time & 0xFFFF;
|
OCR1A = next_step_time & 0xFFFF;
|
||||||
TIMSK1 |= MASK(OCIE1A);
|
TIMSK1 |= MASK(OCIE1A);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue