reset timer properly for more accurate timing

This commit is contained in:
Michael Moon 2010-09-16 21:42:24 +10:00
parent d56ff39cb3
commit 92eb4c97ca
1 changed files with 6 additions and 2 deletions

View File

@ -103,8 +103,12 @@ void setTimer(uint32_t delay)
// 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.
setTimerCeiling(getTimerCeiling(delay));
setTimerResolution(getTimerResolution(delay));
setTimerResolution(0); // stop timer
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 )