Chapter 8
8-bit Timer
8-bit Timer VIII - 19
8.3.2 Setup Example
Timer Operation Setup Example (Timer 0 to Timer 5)
Here is an example that the periodic interrupt of Timer 0 is generated to execute the timer function. An interrupt is
generated every 250 cycles (200 µs) by selecting SYSCLK/2 (at f
sysclk
= 2.5 MHz operation) as a clock source.
The setup procedure and the description of each step are shown below.
Step Setting Symbol Description
1 Disable the timer counter TM0MD.TM0EN = 0 Disable the timer count operation.
2 Disable the interrupt TM0ICR.TM0IE = 0 Disable the timer interrupt.
3
Set the timer mode register TM0MD.TM0PWM = 0
TM0MD.TM0MOD = 0
Select the normal timer operation.
4 TM0MD.TM0CK1-0 = 01 Select the clock source.
5
Set the prescaler CK0MD.TM0PSC1-0 = X0
CK0MD.TM0BAS = 1
Select SYSCLK/2.
6
Set the interrupt cycle TM0OC = 0xF9 Set the cycle of timer interrupt.
Setup value: 249 (0xF9)
7 Set the interrupt level TM0ICR.TM0LV1-0 Refer to [3.1.3 Maskable Interrupt Control Register Setup].
8 Enable the interrupt TM0ICR.TM0IE = 1
9 Enable the timer counter TM0MD.TM0EN = 1 Enable the timer count operation.