EasyManua.ls Logo

Panasonic MN101L Series

Panasonic MN101L Series
563 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Chapter 8
8-bit Timer
VIII - 30 Simple Pulse Width Measurement
8.7.2 Setup Example
Setup Example of Simple Pulse Width Measurement by 8-bit Timer
Here is an example that Timer 0 measures "Low" pulse width of the input signal of IRQ0.
SYSCLK/2 is selected as a clock source for Timer 0.
The setup procedure and the description of each step are shown below.
The internal enable is set while the sampled signal at the count clock, which is External Interrupt 0 (IRQ0) input,
is "Low" level.
TM0BC starts counting up from "0x00" after the internal enable is set. Timer 0 continues counting up while IRQ0
is "Low", and stops counting up when the sampled signal of IRQ0 becomes "High" level. At the same time,
"Low" period of IRQ0 input can be detected by reading the value of TM0BC in the interrupt process.
Step Setting Register Description
1 Disable the timer counter TM0MD.TM0EN = 0 Disable the timer count operation.
2
Set the timer mode register TM0MD.TM0PWM = 0
TM0MD.TM0MOD = 1
Select the pulse width measurement function.
3 TM0MD.TM0CK1-0 = 01 Select the prescaler as the clock source.
4
Set the prescaler CK0MD.TM0PSC1-0 = X0
CK0MD.TM0BAS = 1
Select SYSCLK/2.
5
Set the compare register TM0OC = 0xFF Set the value larger than that of the "Low" period of measured
pulse width.
6 Set the interrupt level TM0ICR.TM0LV1-0 Refer to [3.1.3 Maskable Interrupt Control Register Setup].
7 Set the interrupt valid edge IRQ0ICR.REDG0 = 1 Set the external interrupt valid edge.
8 Enable the interrupt TM0ICR.TM0IE = 1 Enable the external interrupt.
9 Enable the timer counter TM0MD.TM0EN = 1 Enable the timer count operation.

Table of Contents

Related product manuals