Panasonic F77G Cell Phone User Manual


 
VI - 37
Chapter 6 8-bit Timers
Simple Pulse Width Measurement
6-9-2 Setup Example
Set up Example of Simple Pulse Width Measurement by 8-bit Timer (Timers 0, 4 and 5)
The pulse width of 'L" period of the external interrupt 2 (IRQ2) input signal is measured by timer 0. The
clock source of timer 0 is selected to fosc.
An example setup procedure, with a description of each step is shown below.
(1) Set the TM0EN flag of the timer 0 mode
register (TM0MD) to stop timer 0 counting.
(2) Set the TM0PWM flag of the TM0MD register
to "0" and TM0MOD flag to "1" to enable the
timer operation during "L" period to be
measured.
(3) Set the clock source to fosc by the TM0CK2-0
flag of the TM0MD register.
(4) Set the timer 0 compare register (TM0OC) to
the bigger value than ("L"period of measured
pulse width / the cycle of fosc).
At that time, the timer 0 binary counter
(TM0BC) is initialized to x'00'.
(5) Set the interrupt level by the IRQ2LV1-0 flag
of the external interrupt 2 control register
(IRQ2ICR).
If interrupt request flag is already set, clear all
interrupt request flags.
(6) Set the REDG2 flag of the IRQ2ICR register to
"1" to specify the interrupt valid edge to the
rising edge.
Setup Procedure
(1) Stop the counter.
TM0MD (x'3F54')
bp3 :TM0EN = 0
(2) Set the pulse width measurement
operation.
TM0MD (x'3F54')
bp4 :TM0PWM = 0
bp5 :TM0MOD = 1
(3) Select the count clock source.
TM0MD (x'3F54')
bp2-0 : TM0CK2-0 = 000
(4) Set the compare register.
TM0OC (X'3F52') = x'FF'
(5) Set the interrupt level
IRQ2ICR (x'3FE4')
bp7-6 :IRQ2LV1-0 = 10
(6) Set the interrupt valid edge.
IRQ2ICR (x'3FE4')
bp5 :REDG2 = 1
Description
[ Chapter 3. 3-1-4 Interrupt Flag Setup ]