Chapter 9
16-bit Timer
Up/Down Counting IX - 51
9.6.2 Setup Example
■ Up/Down Counting Setup Example
The binary counter counts up when the external input signal(TM8AIO) is “H” and counts down when it is “L” at
timing of the timer 8 count clock. The count clock is IOCLK, and the oscillator frequency is set to 10 MHz, 6
multiplication and IOCLK=MCLK/2. A setup procedure with a description of each step is shown below.
The binary counter counts up when the TM8AIO pin is set to “H”, and counts down when the TM8AIO pin is set
to “L”. The binary counts up or down according to the condition of the pin.
Setup Procedure Description
(1) Stop the counter
TM8MD(0x0000A200)
bp6: TMLDE=0
bp7: TMCNE=0
(1) Set the TMLDE flag and the TMCNE flag of the timer 8
mode register (TM8MD) to the timer 8 counting.
(2) Select the count clock source
TM8MD(0x0000A200)
bp2-0: TMCK2-0=000
(2) Select the count clock source (IOCLK) by the TMCK2-0
flag of the TM8MD register.
(3) Select the timer up/down
TM8MD(0x0000A200)
bp9-8: TMUD1-0=10
(3) Set the TMUD1-0 flag of the TM8MD register to “10”;
and, select up counting when the TMnAIN pin is at “H”
level and down counting when the TMnAIN pin is input
at “L” level input.
(4) Set the timer counter clear enabled
TM8MD(0x0000A200)
bp11: TMCLE=1
(4) Set the TMCLE flag of the TM8MD register to “1” to
enable the clear operation of the TM8BC register. The
TM8BC counter is cleared.
(5) Set the input pin (pin function)
P3MD(0x0000A033)
bp6: P36M=1
(5) Set the P36M flag of the port 3 output mode register
(P3MD) to “1” to set the port to pin function.
(6) Set the input pin (I/O function)
P3DIR(0x0000A023)
bp0: P36D=0
(6) Set the P36D flag of the port 3 I/O control register
(P3DIR) to “0” to set the port to the input pin.
(7) Initialize the timer 8
TM8MD(0x0000A200)
bp6: TMLDE=1
(7) Set the TMLDE flag of the TM8MD register to “1” to
initialize the timer 8. The value of the binary counter
(TM8BC) is initialized to 0x0000. Reset the TMLDE flag
to “0” after setting.
(8) Start the timer operation
TM8MD(0x0000A200)
bp7: TMCNE=1
(8) Set the TMCNE flag of the TM8MD register to “1” to
operate the timer 8.