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 45-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/45) x (16) x (127 + 1) x (43,981) = 1.67 S
The time-out values in Table 13-5 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 BCLKO are divided by 1 and by 16 (TMRn[CLK] is 01 or 10,
respectively).
Any clock source (BCLKO ÷ 1, BCLKO ÷ 16, or TIN) can be prescaled using TMRn[PS].
The BCLKO frequency depends on the prescaler value (TMRn[PS]) and on the PLL clock
setting, as described inChapter 7, “Phase-Locked Loop (PLL).”
Table 13-5. Calculated Time-out Values (90-MHz Processor Clock)
TMR[PS] TMR[CLK] = 10 (System Bus Clock/16) TMR[CLK] = 01 (System Bus Clock/1)
Decimal Hex 45 MHz 30 MHz 22.5 MHz 45 MHz 30 MHz 22.5 MHz
0 0 0.0233 0.03495 0.0466 0.00146 0.00218 0.00291
1 1 0.0466 0.06991 0.09321 0.00291 0.00437 0.00583
2 2 0.06991 0.10486 0.13981 0.00437 0.00655 0.00874
3 3 0.09321 0.13981 0.18641 0.00583 0.00874 0.01165
4 4 0.11651 0.17476 0.23302 0.00728 0.01092 0.01456
5 5 0.13981 0.20972 0.27962 0.00874 0.01311 0.01748
Fr
eescale S
emiconduct
or
, I
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
nc...
