88
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
5.1 Setting of Interval Timer
To set the 16-bit timer/event counter as an interval timer, first set the timer clock select register 0 (TCL0) and the
16-bit timer mode control register (TMC0). The clear mode of the 16-bit timer is set by TMC0 and the interval time
is set by TCL0.
After that, set the value of the compare register (CR00) from the setup time and count clock. Determine the setup
time by using the following expression:
Setup time = (Compare register value + 1)
×
Count clock cycle
This section shows two examples of setup times of the interval timer: 10 ms and 50 ms.
(a) Interval of 10 ms
<1>
Setting of TMC0
Selects a mode in which the timer is cleared and started on coincidence between TM0 and CR00.
Setting of TCL0
Select the f
X
/2 mode in which an interval time of 10 ms or more can be set and the resolution is
the highest.
Setting of CR00
<2>
<3>
10 ms = (N + 1)
×
N = 10 ms
×
8.38 MHz/2 – 1 = 4.1899
(1) Program list
CR00 = #41899
TCL0 = #00100000B ; Selects count clock f
X
/2
TMC0 = #00001100B ; Clears and starts 16-bit timer/event counter when TM0 and CR00 coincide
(b) Interval of 50 ms
<1>
Setting of TMC0
Selects a mode in which the timer is cleared and started on coincidence between TM0 and CR00.
Setting of TCL0
Select the f
X
/2
3
mode in which an interval time of 50 ms or more can be set and the resolution is
the highest.
Setting of CR00
<2>
<3>
50 ms = (N + 1)
×
N = 50 ms
×
8.38 MHz/2
3
– 1 = 52374
(1) Program list
CR00 = #52374
TCL0 = #01000000B ; Selects count clock f
X
/2
3
TMC0 = #00001100B ; Clears and starts 16-bit timer/event counter when TM0 and CR00 coincide
1
8.38 MHz/2
1
8.38 MHz/2
3