This is only a preview of the July 1997 issue of Silicon Chip. You can view 30 of the 96 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "A Flexible Interface Card For PCs":
Items relevant to "Points Controller For Model Railways":
Items relevant to "Simple Waveform Generator":
Items relevant to "Colour TV Pattern Generator; Pt.2":
Articles in this series:
Articles in this series:
Articles in this series:
Purchase a printed copy of this issue for $10.00. |
This addressable interface card provides eight
opto-isolated inputs and eight relay outputs.
A flexible interface
card for PCs
This addressable interface card provides
eight opto-isolated inputs and eight relay
outputs. It is addressed from the parallel
port of your computer and you can have
more than one card, each with a different
address, hooked to the same port.
By RICK WALTERS
Got a control application for your
computer that can’t be done with your
existing hardware? Perhaps you want
to design a security system around an
older computer. Whatever the reason,
there are a host of applications for
this input/output card which can be
connected to any PC with a standard
parallel port. That means it can be
used with old PC XTs, 286 or 386
machines which might otherwise
be gathering dust. And of course, it
can be used with 486 and Pentium
machines as well.
You could have up to eight of these
cards daisy chained and connected to
one parallel printer port on a PC. The
cards can be set up with an address
from 1 to 8, making them individually
addressable, or if the need arises, two
or more can be coded with the same
address in a master-slave setup.
Capabilities
This interface card is capable of
monitoring eight opto-isolated input
lines. The inputs to the PC port are
normally high and are taken low (via
the opto-isolator) when the card input
line is grounded. These eight input
lines and ground are accessible via a
9-pin “D” female connector.
The card can also switch eight
relays. Each relay has changeover
July 1997 23
PARTS LIST
1 PC board, code 07107971, 177
x 125mm
8 PC-mount relays (RLY1-RLY8)
(Altronics S-4160; Jaycar SY4066)
1 D25 PC-mount male connector
1 D25 PC-mount female connector
1 D25 male connector (solder cup
or IDC)
1 D9 PC-mount female connector
1 D9 male connector (solder cup
or IDC)
1 8 x 2-pin strip
1 shunt for above
1 3-pin terminal block (5.08mm
pitch)
Semiconductors
1 74HC137 decoder (IC1)
2 74HC573 8-bit latch
(IC2,IC3)
1 74HC02 quad NOR gate
(IC4)
1 ULN2803 octal buffer (IC5)
8 4N28 opto-isolators (O1-O8)
9 1N914 small signal diodes
Capacitors
2 100µF 25VW PC electrolytic
3 0.1µF monolithic ceramic
1 .01µF MKT polyester
2 .001µF MKT polyester
Resistors (0.25W, 1%)
2 47kΩ
1 10kΩ
8 4.7kΩ
1 47kΩ SIP (8 resistor 9 pin)
Fig.1 (right): the circuit uses a BCD
decoder (IC1) and an 8-bit latch (IC2)
to control the eight relays. Eight optoisolators are coupled to 8-bit latch IC3
to drive PortB and PortC of the
parallel connector CON1.
confuse you by calling it card 0 we
have labelled them cards 1 to 8. If the
output which goes low is jumpered
to pin 2 of IC4a, and remembering
that pin 4 is high, we then have both
inputs of IC4a low, which means that
its output will be high. This will latch
the data present on PortA (pins 2-9
of CON1) into IC2 and output it on
pins 12-19.
Pins 12 to 19 of IC2 connect directly to IC5, an octal (eight) buffer.
This chip accepts 5V logic levels
at its input and has open-collector
outputs which can switch up to 50V
0.5A loads.
Operating the relays
(SPDT) contacts and depending on the
type used, the contacts may be rated
6A at 240VAC and 12A at 28VDC (Altronics S-4160) or 3A at 12V (Jaycar
SY-4066). All relays are accessed via
a 25-pin “D” female connector. Note
that the PC board tracks and the connector are not rated for 240VAC and
they would not carry this current but
if high currents were to be switched,
connections could be made straight
to the relay pins.
These features make the card
suitable for a wide range of interface
applications.
capacitor. Thus if pin 4 of IC4b goes
high, the latch pin will immediately
go high then return to a low level
as the 10kΩ resistor discharges the
capacitor. This is how we select the
card from the parallel port.
The three input lines can only
address outputs 0 - 7 so rather than
Circuit description
The full circuit is shown in Fig.1.
IC1 is a 74HC137 latched one-of-eight
active-low decoder. This means that
any BCD (binary coded decimal) code
which is present on the three input
lines (A,B,C) will cause the output
corresponding to this code to change
from its normal level of +5V (high) to
0V (low). The eight outputs are pins
7 and 9 to 15.
While the latch enable, pin 4, is
high, the outputs will change in sympathy with the input code but once
the latch pin is low, the input code
is stored or latched. This allows us
to select one of the outputs, latch it,
then alter the code on the input lines
while that output stays selected.
To this end, the latch enable pin
is AC-coupled through the .001µF
24 Silicon Chip
The I/O Card is addressed from the
parallel port of your computer and
you can have more than one card,
each with a different address, hooked
to the same port. Note that this is the
prototype card and some changes
have been made, as can be seen from
the component overlay diagram of
Fig.4. The current artwork uses a 16pin chip for IC1.
OK, so how do we operate the
relays? The procedure is to apply
the code for the particular relays
(see Table 1) to PortA then apply the
card select code to PortC, taking pin
1 (which is normally high) low, then
back high again.
Reading the eight inputs is not quite
so straightforward. In the newer PCs,
the PortA lines are bidirectional; ie,
they can be used for inputs as well as
outputs. With the older-style machines
they can only be used as output lines.
Fortunately, the PortB and PortC lines
can be used as inputs but we have to
use them both to get our eight lines.
Now you will realise why it was necessary to latch the PortC data in IC1.
The eight inputs (pins 2-9) of IC3
are pulled high with 47kΩ resistors
and each resistor has an opto-isolator output connected between it and
ground. If the LED in the opto is lit the
transistor will pull the pin low. This
will be the case if the corresponding
diode is grounded.
Unfortunately, computer boffins
count from zero, unlike normal human beings who were taught to start
from one. This means that diode D1
controls input port D0 and so on. We
could label the IC pins D1-D8, but we
prefer to draw ICs the way you will
find them in the data book, otherwise
there could be even more confusion.
With the I/O card de-selected, pin 1
of IC4a will be low and therefore pin
July 1997 25
Fig.2: the top trace shows the strobe pulse at pin 4 of IC4.
The middle trace is the differentiated pulse which is
present at pin 4 of IC1. This latches the card address
when it is high. The bottom trace is the integrated pulse
at pins 8 & 9 of IC4. You can see that the capacitor has not
charged up to the 2.5V necessary to change the output.
Fig.3: these scope waveforms show how the card
opto-isolator inputs are read. The strobe goes high and
stays high long enough for the input of IC4c to pass
through the logic switching threshold. Note that the
time constant here is 10 times longer than the latch
enable time constant for IC2.
The LED test jig is used to verify the operation of the eight relays.
Table 1: Port A Code To Energise Relays 1, 5 & 8
BCD Value
128
64
32
16
8
4
2
1
Data Line
D7
D6
D5
D4
D3
D2
D1
D0
Relay 1
Relay 2
Relay 3
Relay 4
Relay 5
Relay 6
Relay 7
Relay 8
Total
1
0
0
0
1
0
0
1
128
+16
The value to apply to PORTA is 10010001 binary or 145 decimal.
26 Silicon Chip
+1
= 145
10 of IC4c and pin 1 (the output enable) of IC3 will be high. This means
that pins 12-19 of IC3 will be floating
and therefore at the logic levels on the
PortB & PortC pins. When pin 1 of IC3
is taken low the logic levels present
on the D (data) inputs are transferred
to the Q pins.
To read the inputs the first step is to
select the card as described previously. Under normal conditions, when we
select the card and toggle the relays,
the time constant of the integrator at
the input of IC4c prevents any change
in its output (see the scope waveforms
of Fig.2).
This time, after selecting the card,
we set all the lines of PortB and PortC
high, except PortC pin 1, which is
held low as we now want to charge
the capacitor on pins 8 & 9 of IC4c
and take its output low (see the
scope waveforms of Fig.3). The 47kΩ
resistor and this capacitor form an
integrator, at the input of IC4c, which
will take 10 times longer to reach the
logic switching level than the latch
enable network on IC2.
Once IC4c changes state, the
logic levels at IC3’s inputs will be
transferred to its outputs which are
connected to PortB and PortC and
this binary value can be read by the
computer software. D9 ensures that
the outputs of IC3 are quickly disabled
when PortC pin 1 goes high.
In practice, the computer software
drives the card and you don’t really
Fig.4: the component overlay for the PC board. The card selection jumper is to
the right of IC1. For convenience, all the input-output connections to the card
are made with D connectors.
have to think about the circuit machinations in order to be able to use it.
Building the card
The component overlay of the PC
board is shown on Fig.4.
You can begin by checking the etch
pattern on the PC board with the full
size artwork of Fig.6. Fix any faults
that might be present before you start
installing the parts.
Fit and solder the 23 links, followed
by the resistors and diodes. Next,
insert the ICs along with the resistor
network (black dot adjacent to pin 1)
noting that IC1, IC2, IC4 and IC5 face
one edge of the board and the rest
face the other edge. The last group is
the capacitors, connectors and relays.
Check all the soldering again once
you have finished as it is quite easy to
miss a row of IC pins or one resistor
network pin.
Testing it
For the big test you will need a 25way D cable to connect your computer
printer port to the card and a power
supply which can deliver 5V and 12V.
Connect the power supply to CON4,
checking that the +5V on the supply
goes to the correct connector terminal.
Set the jumper to C1. Connect the
male end of the cable to the computer
printer socket, the female end to the
card and turn on the power supply.
Relay test
It is possible that several relays will
click in, depending on the logic levels on the output of IC2. If nothing is
heard don’t despair. Load BASIC into
your computer and type in lines 10100 of the program shown in Listing
1. You need not type the comments
(lower case); they are only there to
explain what each line does.
When you run it, each relay should
energise in turn, with a 1-second delay between steps. If your relays don’t
step at all, first check that you have
selected card one.
Next, check the voltage at pin 2 of
IC4. It should be 0V. If you remove
Fig.5: use this circuit to make up
a jig for checking relay operation
on the board.
OUT PORTC,10 from line 50 and
run the program again, both pin 2
and pin 3 of IC4 should be low and
consequently pin 1 should be high.
Fig.5 shows the circuit of a LED
array which can be connected to a
July 1997 27
Fig.6: actual size artwork for the PC board. Check your PC board’s copper tracks for defects before you start assembly.
LISTING 1
10 CLS: KEY OFF: DEFINT A, B, C
‘define A, B, C as integers
20 PORTA = &H378: REM &H378 is for LPT1. use &H278 for LPT2
30 PORTB = PORTA + 1: PORTC = PORTB + 1 ‘define port addresses
40 OUT PORTA,0: OUT PORTC,10
‘turn all relays off, take C0 high
50 OUT PORTC,11: OUT PORTC,10
‘select card one, C0 low then high
60 FOR A = 0 TO 7
‘relays are coded 1, 2, 4, 8, 16, 32, 64, 128
70 OUT PORTA,2^A
‘select relay 1 to 8 in turn
80 OUT PORTC,11: OUT PORTC,10
‘select card one, strobe high then low
90 B$ = RIGHT$(TIME$,2): WHILE RIGHT$(TIME$,2) = B$: WEND ‘wait one second
100 NEXT A
110 OUT PORTA,0: OUT PORTC,11
‘turn all relays off
120 OUT PORTB,120: OUT PORTC,5
‘take input lines high
130 FOR A = 1 to 200: NEXT
‘delay for IC4c increase value if necessary
140 LIN = 0: B = INP(PORTB): C = INP(PORTC)
‘read port input values
150 IF (B AND 128) THEN BIN = B - 135 ELSE BIN = B + 121 ‘complement bit 8
160 CIN = C AND 14
‘mask high bits and C0
170 IF (C AND 2) = 0 THEN CIN = CIN + 2 ELSE CIN = CIN - 2 ‘complement bit 2
180 IF (C AND 8) = 0 THEN CIN = CIN + 8 ELSE CIN = CIN - 8 ‘complement bit 8
190 CIN = INT (CIN/2): TIN = 255 - (BIN + CIN)
200 FOR A = 0 TO 7: IF TIN/2^A = 1 THEN LIN = A + 1 ‘find low line
210 NEXT
220 LOCATE 24,20: PRINT “Line”;LIN;
‘print it
230 GOTO 140 ‘loop
28 Silicon Chip
25-way D-connector to check relay
operation. This is much more effective than trying to listen for relays
clicking.
Input test
Now add the remaining lines (110230) of Listing 1 and run the program
again. After the relays stop sequencing, the number 0 should appear at
the bottom of the screen. Ground the
cathodes of D1-D8 in turn and the
corresponding line number should
show on the screen.
Pressing the Ctrl and C or Ctrl and
Break keys together will get you out
of the loop. The fun and games in
lines 150-190 compensate for the logic
inversion of B7, C1 and C3 on CON1.
If you have problems with this section you will have to ground the diode
and check that the corresponding data
input on IC3 goes low. With pin 1 of
IC3 low, the Q output should mimic
the D input. If this is working, then
check for open circuit tracks between
IC3’s Q outputs and the corresponding
SC
pin on CON1.
|