Integrated Microcontroller Reference Manual

DMA Timers (DTIM0–DTIM3)
MCF52211 ColdFire® Integrated Microcontroller Reference Manual, Rev. 2
22-10 Freescale Semiconductor
move.l #0x0000,D0;writing to the timer counter with any
move.l DO,TCN0 ;value resets it to zero
move.l #0xAFAF,DO ;set the timer0 reference to be
move.l #D0,TRR0 ;defined as 0xAFAF
The simple example below uses Timer0 to count time-out loops. A time-out occurs when the reference
value, 0xAFAF, is reached.
timer0_ex
clr.l DO
clr.l D1
clr.l D2
move.l #0x0000,D0
move.l D0,TCN0 ;reset the counter to 0x0000
move.b #0x03,D0 ;writing ones to TER0[REF,CAP]
move.b D0,TER0 ;clears the event flags
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
22.4.2 Calculating Time-Out Values
Equation 22-1 determines time-out periods for various reference values:
Eqn. 22-1
When calculating time-out periods, add 1 to the prescaler to simplify calculating, because
DTMRn[PS] equals 0x00 yields a prescaler of 1, and DTMRn[PS] equals 0xFF yields a prescaler of 256.
For example, if a 66-MHz timer clock is divided by 16, DTMRn[PS] equals 0x7F, and the timer is
referenced at 0xFBC5 (64453 decimal), the time-out period is:
Eqn. 22-2
Timeout period 1 clock frequency()1 or 16()× DTMRn[PS] 1+()× DTRRn[REF] 1+()×=
Timeout period
1
66 10
6
×
--------------------
16 127 1+()64453 1+()××× 2.00 s==