
MULTI-MODE COUNTER SECTION 13
Page 13-2 RPC-320
The following program example returns a frequency.
Input signal 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 first frequency 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 necessary when higher accuracy 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 with this routine is periodically, a large
negative number is returned. This is because the
multimode counter has rolled over. This is corrected by
periodically reseting the CNTR or transferring PR to
CNTR. Refer to the data sheet, Appendix A for counter
operating modes.
This program sets up the LS7166 to cause an interrupt
when a pr eset number of counts is reached. 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.
Command Function
COUNT(0) Returns value in counter
COUNT 0,n Writes value to counter