
MULTI-MODE COUNTER
SECTION 13
Page 13-2 RPC-320
The following program example returns a frequency.
I np u t s ig n al is at " A IN " .
100 LINEB 6,1,32
110 LINEB 6,1,72 : REM enable inputs
120 ONTICK 1,500
130 IDLE
140 GOTO 130
500 A=COUNT(0) : REM get count
510 C=A-B : REM figure change from last time
520 PRINT "Frequency = ",A
530 B=A
530 RETI
The fir st frequen cy read will always be a bit off. This is
because of the time required to initialize ONTICK.
Subsequent readings are more accurate.
Accuracy is increased by stretching readings to every 10
seconds. This is neces sary w hen higher accura cy is
needed.
Other factors affecting accurate readings in this program
include serial communications and ONITR statement. If
ONITR is in process, ONTICK is delayed until ONITR
is finished.
The problem w ith this routine is periodically, a large
negative number is returned. This is because the
multimode counter has rolled over. This is corrected by
periodica lly reseting the CN TR or transfer ring P R to
CN TR. Refer to the data sheet,
Appendix A
for counter
operating mo des.
This program sets up the LS7166 to cause an interrupt
when a pr eset numb er of cou nts is reach ed. W8[7-8] is
jumpered to interrupt on a borrow.
10 LINEB 6,1,132
20 COUNT 0,1000 : REM write to CNTR
30 LINEB 6,1,8 : REM transfer PR to CNTR
40 LINEB 6,1,72 : REM enable A/B counters
50 ONITR 500
100 PRINT COUNT(0) : REM print progress
110 GOTO 100
500 PRINT "In Interrupt"
510 RETI
Line 10 sets OCCR to divide by N. Line 50 enables
interrupts. Line 100 prints the counter. When pulses
are applied to the A input, the count will go down. When
1000 pulses are detected at A input, the message in line
500 is printed.
COMMANDS
The table below lists commands used with the counter.
Comm and
Function
COU NT(0)
Returns value in counter
C O UN T 0, n
Writes value to counter