Hardware Reference
In-Depth Information
The pulse accumulator system can be used to measure the signal frequency. The procedure
is as follows:
Step 1
Connect the unknown signal to the PT7 pin.
Step 2
Set up the PACA to operate in event-counting mode.
Step 3
Use one of the output-compare functions to create a 1-s time interval.
Step 4
Use a memory location to keep track of the number of pulse accumulator counter
overflow interrupts.
Step 5
Enable the PAOV interrupt.
Step 6
Disable the PAOV interrupt at the end of 1 s.
Example 8.14
Write a program to measure the frequency of a signal connected to the PT7 pin using the
algorithm described previously.
Solution: We use the OC0 function to create a 1-s delay. Fifty OC0 operations will be
performed, with each OC0 operation creating a 20-ms delay. The service routine for the
PACNT overflow interrupt will increase the overflow count by 1. Let paov_cnt represent
the PACNT overflow count. At the end of 1 s, the frequency is equal to the following
expression:
Frequency 5 paov_cnt 3 2 16 1 PACNT
The assembly program that implements this procedure is as follows:
#include
“c:\miniide\hcs12.inc”
org
$1000
oc_cnt
ds.b
1
paov_cnt
ds.b
2
; PACNT overflow count
frequency
ds.b
4
; signal frequency
org
$1500
lds
#$1500
movw
#paov_isr,UserPAccOvf
; set up PAOV interrupt vector
movb
#50,oc_cnt
; prepare to perform 50 OC0 actions
ldd
#0
std
PACNT
; let PACNT count up from 0
std
paov_cnt
; initialize PACNT overflow count to 0
std
frequency
; initialize frequency to 0
std
frequency 1 2
;
 
Search WWH ::




Custom Search