reset timer properly for more accurate timing
This commit is contained in:
parent
d56ff39cb3
commit
92eb4c97ca
8
timer.c
8
timer.c
|
|
@ -103,8 +103,12 @@ void setTimer(uint32_t delay)
|
||||||
// we also then calculate the timer ceiling required. (ie what the counter counts to)
|
// we also then calculate the timer ceiling required. (ie what the counter counts to)
|
||||||
// the result is the timer counts up to the appropriate time and then fires an interrupt.
|
// the result is the timer counts up to the appropriate time and then fires an interrupt.
|
||||||
|
|
||||||
setTimerCeiling(getTimerCeiling(delay));
|
setTimerResolution(0); // stop timer
|
||||||
setTimerResolution(getTimerResolution(delay));
|
TCNT1 = 0; // reset timer
|
||||||
|
GTCCR = MASK(PSRSYNC); // reset prescaler - affects timer 0 too but since it's doing PWM, it's not using the prescaler
|
||||||
|
|
||||||
|
setTimerCeiling(getTimerCeiling(delay)); // set timeout
|
||||||
|
setTimerResolution(getTimerResolution(delay)); // restart timer with proper prescaler
|
||||||
}
|
}
|
||||||
|
|
||||||
// delay( microseconds )
|
// delay( microseconds )
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue