10
8.
Program Example for Pulse Width Measurement Function
of Pulse Width Count Timer
This section gives a program example for the pulse width measurement function of the
pulse width count timer.
n Program Example for Pulse Width Measurement Function
l
Processing description
•
Measures the "H" width of a pulse input to the PWC pin (pulse width measurement function).
•
Generates an interrupt when pulse width measurement completes and continues
measurement.
•
The following shows the relationship between the RLBR register value and the measured
pulse width when the source oscillation is 10 MHz and the 4 t
oscillation) count clock is selected.
l
Coding example
DDR3
PCR1
PCR2
RLBR
EN
IE
IR
BF
ILR2
INT_V
IRQ5
INT_V
;-----Main program---------------------------------------------------------------------------------------------------------------------------------------------------------------
;-----Interrupt processing routine---------------------------------------------------------------------------------------------------------------------------------------------
WARI
;--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
178
CHAPTER 8 PULSE WIDTH COUNT TIMER (PWC)
Pulse width = (256 – RLBR register value)
EQU
000DH
EQU
0014H
EQU
0015H
EQU
0016H
EQU
PCR1:7
EQU
PCR1:5
EQU
PCR1:1
EQU
PCR1:0
EQU
007DH
DSEG
ABS
ORG
0FFF0H
DW
WARI
ENDS
CSEG
:
MOV
DDR3,#00000000B
CLRI
CLRB
EN
CLRB
IE
MOV
A,RLBR
MOV
ILR2,#11110111B
MOV
RLBR,#0E9H
MOV
PCR2,#10000100B
MOV
PCR1,#10100000B
SETI
CLRB
IR
PUSHW
A
XCHW
A,T
PUSHW
A
MOV
A,RLBR
:
User processing
:
POPW
A
XCHW
A,T
POPW
A
RETI
ENDS
END
inst
×
×
4/10 MHz (measurement range: 1.6 µs to 409.6 µs)
4
; Address of the PWC pulse width control register 1
; Address of the PWC pulse width control register 2
; Address of the PWC reload buffer register
; Define the counter operation enable bit.
; Define the interrupt request enable bit.
; Measurement completion interrupt request flag bit
; Buffer full flag bit
; Address of the interrupt level setting register 2
; [DATA SEGMENT]
; Set interrupt vector.
; [CODE SEGMENT]
; Stack pointer (SP) etc. are already initialized.
; Set P35/PWC pin as an input.
; Disable interrupts.
; Stop counter operation.
; Disable interrupt request output.
; Clear buffer full flag (PCR1: BF).
; Set interrupt level (level 1).
; Counter reload value (interval time)
; Select the pulse width measurement function, 4 t
; Enable counter operation, disable WTO pin output, enable interrupt
request output, clear underflow (01
clear measurement completion interrupt request flag (IR).
; Enable interrupts.
; Clear interrupt request flag.
; Read pulse width measurement value and clear BF flag.
(t
: divide-by-four source
inst
, and "H" pulse,
inst
→ 00
) interrupt request flag (bit 2),
H
H
MB89620 series