MULTI-MODE COUNTER
The following program example returns a frequency.
Input signal is at "A IN" .
100 LINEB 6,1,32
110LINEB 6,1,72 : REM enable inputs
120ONTICK 1,500
130IDLE
140GOTO 130
500A=COUNT(0) : REM get count
510
520PRINT "Frequency = ",A
530B=A
530RETI
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.
10 | LINEB 6,1,132 | : REM write to CNTR | |
20 | COUNT | 0,1000 | |
30 | LINEB | 6,1,8 | : REM transfer PR to CNTR |
40LINEB 6,1,72 : REM enable A/B counters
50ONITR 500
100 | PRINT COUNT(0) : REM print progress |
110 | GOTO 100 |
500PRINT "In Interrupt"
510RETI
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.
SECTION 13
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 |
Page