Hardware Reference
In-Depth Information
8.7.6 Pulse Accumulator Applications
The pulse accumulator has a few interesting applications, such as interrupting after N
events, frequency measurement, and pulse duration measurement.
Example 8.13
Suppose certain events are converted into pulses and connected to the PT7 pin. Write a pro-
gram so that the pulse accumulator generates an interrupt to the HCS12 when N events have
occurred. Assume that N is less than 65,536.
Solution: By writing the two's complement of N into PACNT, it will overflow after N events
and generate an interrupt. The assembly program is as follows:
#include
“c:\miniide\hcs12.inc”
N
equ
1350
org
$1500
lds
#$1500
; set up stack pointer
movw
#paov_isr,UserPAccOvf
; set up PAOV interrupt vector
ldd
#N
; place the two's complement in PACNT
coma
;
comb
;
addd
#1
;
std
PACNT
;
movb
#$52,PACTL
; enable PACA, event counting mode, active
; edge is rising
cli
; enable PAOV interrupt
;
. . .
swi
paov_isr
movb
#PAOVF,PAFLG
; clear the PAOVF flag
end
The C language version of the program for CodeWarrior C compiler is as follows:
#include “c:\cwHCS12\include\hcs12.h”
#define NN 1350
void main(void) {
PACNT 5 , N 1 1;
PACTL 5 0x52;
//enable PACTL, event count mode,
increment on rising edge
asm(“cli”);
//enable PACNT overflow interrupt
// . . .
}
interrupt void paovISR(void) {
PAFLG 5 PAOVF;
//clear the flag and return
}
 
Search WWH ::




Custom Search