MULTI-MODE COUNTER
DESCRIPTION
The 24 bit multimode counter is capable of up/down, binary,
The COU NT function and statement are used to read from and wr ite to the counter . L INE B is used to program the chip for various op erating mode s.
An interrupt, using ONITR, may be detected on a carry, borr ow, or either event. The eve nt is jumper selectable through W8. When the counter is used, external interrupts (see Chapter 12) may not be used.
W8 P in | Description |
External TTL level through | |
| optically isolated through P3 |
Carry or borrow pulse from counter | |
Carry pulse from counter | |
Borrow pulse from counter |
Signals connect to the counter via P2. Use the following table to determine signal input to the LS7166.
P2 | Function |
Name |
|
A IN | Count inp ut A |
B IN | Count inp ut B |
GND | Ground |
LOAD | Load counter/latch (LCTR/LLTC) |
GATE | Gate/reset counter (ABGT/RCTR) |
Input lines (A IN), (B IN), LOAD, and GATE are pulled to + 5V through a 10K resistor .
PROGRAMMING
The LS7166 is capable of several operating modes, all of which are not discussed here. See Appendix C for this chips operating modes. W hat are shown are exam ples of how to program this chip.
NOTE: Be sure to initialize the counter chip before using COU NT com mands. Failure to do so returns m eaningless results.
The COU NT function returns the current counter value.
SECTION 13
Specifically, RPBASIC w rites a 2 to the MCR (M aster Control Register), reads the 3 counter bytes from the OL (Output latch), and converts it to the proper internal BASIC form at.
100 A = COUNT(0)
COUNT statement writes a 24 bit number to the PR (Preset r egister) only. Its syntax is:
200 COU NT 0, D
To transfer this number to the counter, execute the following in the program:
LINEB 6,1,8
The counter number is always 0 on the RPC
LINEB is used to access specific registers within the chip. Accessing control and status registers is shown below. C ounter bank is 6.
100A = LINEB(6,1) : REM Read OSR
200LINEB6,1,X
Line 200 writes to OCCR, ICR, QR, MCR, and ICR register s. W hich registe r selected is determ ined by bits 6 and 7 in the byte written to the chip.
Program examples
This code resets the counter and enables the inputs. The count is printed once a second. To see the count change, momentarily bring " A IN" or "B IN" on P2 to ground.
When " B IN" is gr ounded, the count decrem ents.
10LINEB6,1,32
20LINEB6,1,64+8
30ONTICK 1,500
40GOTO 40
500PRINT COUNT(0)
510RETI
Line 20 can be shortened somewhat . 64 selects the ICR (Input contr ol register ) and 8 enab les inputs. 72 could have been used.
Page