With 8 MHz E clock, basic time unit T is 0.125
s.
Prescaler changes time unit for timer module (input capture, output compare,
timer overflow) to
![]()
prescaler.
For example, PR2:0 = 011 => prescaler = 8, so TCNT is incremented
every 1
s.
When reading input capture, elapsed time =
![]()
prescaler
T.
For example, PR2:0 = 011 and TC2 - TC1 = 12,500, then
elapsed time =
ms
Want OC to do something after time X seconds, what to add to TCx?
For example, to create 1 kHz square wave, half-period is 500
s. If
prescaler is 8, then add:
and TCx = TCx + 500
For example, to have pulse width modulation on OC1 with 500 Hz frequency and 80% duty cycle, with prescaler = 2:
500 Hz => 2 ms, so add to TC7:
For 80% duty cycle, add
to TC1.