Datasheet
Chapter 13. Timer Module 13-7
Calculating Time-Out Values
move.w TMR0,D0;save the contents of TMR0 while setting
bset #0,D0 ;the 0 bit. This enables timer 0 and starts counting
move.w D0, TMR0 ;load the value back into the register, setting TMR0[RST]
T0_LOOP
move.b TER0,D1 ;load TER0 and see if
btst #1,D1 ;TER0[REF] has been set
beq T0_LOOP
addi.l #1,D2;Increment D2
cmp.l #5,D2;Did D2 reach 5? (i.e. timer ref has timed)
beq T0_FINISH;If so, end timer0 example. Otherwise jump back.
move.b #0x02,D0 ;writing one to TER0[REF] clears the event flag
move.b D0,TER0
jmp T0_LOOP
T0_FINISH
HALT;End processing. Example is finished
13.5 Calculating Time-Out Values
The formula below determines time-out periods for various reference values:
Time-out period = (1/clock frequency) x (1 or 16) x (TMRn[PS] + 1) x
(TRRn[REF])
When calculating time-out periods, add 1 to the prescaler to simplify calculating, because
TMRn[PS] = 0x00 yields a prescaler of 1 and TMRn[PS] = 0xFF yields a prescaler of 256.
For example, if a 54-MHz timer clock is divided by 16, TMRn[PS] = 0x7F, and the timer
is referenced at 0xABCD (43,981 decimal), the time-out period is as follows:
Time-out period = (1/54,000,000) x (16) x (127 + 1) x (43,981) = 1.67 S
The time-out values in Table 13-4 represent the time it takes the counter value in TCNn
value to go from 0x0000 to the default reference value, TRRn[REF] = 0xFFFF. Time-out
values shown for CLKIN are divided by 1 and by 16 (TMRn[CLK] is 01 or 10,
respectively).
Any clock source (CLKIN ÷ 1, CLKIN ÷ 16, or TIN) can be prescaled using TMRn[PS].
Table 13-4. Time-Out Values (in Seconds)—TRR[REF] = 0xFFFF
(162-MHz Processor Clock)
TMR[PS]
(Dec)
CLK = 10 (÷ 1) CLK = 01 (÷ 16)
TMR[PS]
(Dec)
CLK = 10 (÷ 1) CLK = 01 (÷ 16)
CLKIN (MHz) CLKIN (MHz)
54 40.5 32.4 54 40.5 32.4 54 40.5 32.4 54 40.5 32.4
0 0.019 0.026 0.032 0.001 0.002 0.002 128 2.505 3.340 4.175 0.157 0.209 0.261
1 0.039 0.052 0.065 0.002 0.003 0.004 129 2.524 3.366 4.207 0.158 0.210 0.263
2 0.058 0.078 0.097 0.004 0.005 0.006 130 2.544 3.392 4.240 0.159 0.212 0.265
3 0.078 0.104 0.129 0.005 0.006 0.008 131 2.563 3.418 4.272 0.160 0.214 0.267
4 0.097 0.129 0.162 0.006 0.008 0.010 132 2.583 3.443 4.304 0.161 0.215 0.269
5 0.117 0.155 0.194 0.007 0.010 0.012 133 2.602 3.469 4.337 0.163 0.217 0.271
