
MULTI-MODE COUNTER
SECTION 13
Page 13-1 RPC-320
DESCRIPTION
The 24 bit multimode counter is capable of up/down,
binary, divide-by-n, and quadrature inputs. C ount
frequency is DC to 20 M hz. The R PC-320 uses an LSI
Com puter Syste ms LS 7166. Its data sheet is foun d in
Appendix C.
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
1-2
External TTL level through P2-6 or
optically isolated through P3
3-4
Carry or borrow pulse from counter
5-6
Carry pulse from counter
7-8
Borrow pulse from counter
Signals connect to the counter via P2. Use the following
table to determine signal input to the LS7166.
P2
Function
N a m e
A IN
Count inp ut A
B IN
Count inp ut B
G N D
Ground
LOAD
L o a d c o un te r / la t ch ( LC T R / L L T C )
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.
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
f o ll ow i ng in th e pr o g ra m :
LINEB 6,1,8
The
counter
number is always 0 on the RPC -320.
LINEB is used to access specific registers within the
chip. Accessing control and status registers is shown
below. C ounter bank is 6.
100 A = LINEB(6,1) : REM Read OSR
200 LINEB6,1,X
L i ne 2 00 w r it e s t o O C C R , I C R , Q R, M C R , a n d IC R
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.
10 LINEB6,1,32
20 LINEB6,1,64+8
30 ONTICK 1,500
40 GOTO 40
500 PRINT COUNT(0)
510 RETI
L i ne 2 0 c a n b e sh o r te n ed s om e w h at . 6 4 s e le c ts th e IC R
(Input contr ol register ) and 8 enab les inputs. 72 could
have been used.