This is only a preview of the February 1990 issue of Silicon Chip. You can view 51 of the 104 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. Articles in this series:
Articles in this series:
Articles in this series:
Articles in this series:
Articles in this series:
Articles in this series:
Articles in this series:
|
COMPUTER BITS
By STEVE PAYOR
Where computing meets electronics:
some ideas on inter£acing
Just how do you go about interfacing external
hardware to an IBM PC or PC-compatible? It's
really not all that difficult. Here we show you how
the IBM parallel printer socket can be used as a
general purpose interface.
There comes a time in every computer enthusiast's life when he or
she wishes it could do more than
just sit on the desk looking pretty. If
only it could actually do something,
like turn on a light, measure a
voltage, operate a machine tool,
etc.
But before you go looking for a
commercial interface card, consider what you might be able to
achieve with your existing hardware.
The games port
For example, the Apple II games
port can input the analog value of
four variable resistors, which don't
necessarily have to be the pots in a
joystick - they could be LDRs,
phototransistors, thermistors etc.
Also provided in the one socket are
A 36-PIN SOCKET AND A HANDFUL of resistors are all you need to make a
perfectly useable PC-driven function generator. The difficult part is writing
good, fast software to run it.
68
SILICON CHIP
three bits worth of LS TTL input,
four LS TTL output bits with a
- STROBE pulse, and a + 5V supply
for powering external equipment.
In the author's experience, this is
sufficient to perform at least half of
the laboratory/process control
tasks that Apple Ils -are currently
being used for - given some clever
programming.
Even a small amount of machine
code can go a long way. For example, you can write an extended version of the inbuilt analog input timing routines to obtain more than the
usual 8-bit resolution. The analog
inputs use 555-type RC timing circuits and so the games port can be
used for precision measurement of
external resistors or capacitors.
About 3 or 4 decimal digits appears
to be the limit of accuracy, which is
on par with most cheap digital
multimeters.
There are a wealth of low-cost
commercial devices on the market,
from graphics tablets to scanners,
which interface solely through the
Apple games socket.
The IBM games port can also input the analog value of four
variable resistors, although extending the precision beyond 8 bits is
quite tricky. This is because any
long machine code timing loops will
be affected by a host of internal
goings-on, the most obvious of
which is the DOS real-time clock interrupt. The BIOS and other system
programs in your machine may also
do a number of other things which
will affect timing loops - especially if they have been "enhanced"
over the original IBM specification.
The IBM games port can also input the digital value of four switches but no output bits are
provided as such.
The parallel printer port
The IBM parallel printer port is a
goldmine of interface bits, both input and output, and the remainder
of this article is concerned with
how to use this port as a general
purpose interface.
Since the "Centronics" parallel
interface standard has been
adopted by most printer manufacturers, you will find that all brands
of computers will provide similar
facilities to the IBM, though you
may have to do some detective work
to find out the actual machine addresses for the various I/O bits and
bytes.
Just to whet your appetite, we
will conclude this article with a
useful, practical example, namely
an 8-bit programmable voltage
source/signal generator which is so
simple it will cost you less than the
price of a suitable connector.
Port addresses
Most IBM-compatible parallel
printer cards can be set to respond
as either LPT1: or LPT2: . These
devices appear within the microprocessor's 1/0 address space as
three separate 8-bit ports, which
we will subsequently refer to as
PORT.A, PORT.Band PORT.C. The
actual machine addresses of these
ports are as follows:
PORT.A
PORT.B
PORT.C
LPTl:
378(Hex)
379(Hex)
37 A(Hex)
LPT2:
278(Hex)
279(Hex)
27 A(Hex)
In order to use these ports for
general purpose 1/0, we need to
know which bits of these three
ports are connected to the outside
world. Details may vary slightly
from computer to computer, so obtaining a circuit diagram of your
printer card is highly desirable.
Another useful source of information is the manual which comes
with your printer. This will contain
an appendix describing the parallel
interface signals.
Table 1 was prepared by tracing
through the circuit diagram of a
PORT.A
PORT.B
BIT
SIGNAL
NAME
INPUT
OUTPUT
D7
D6
D5
D4
D3
D2
D1
DO
D7
D6
D5
D4
D3
D2
D1
DO
These bits may be input
but all you will get is
the value currently
residing in the output
latch, unless the
interface is genuinely
bi-directional. (Check
circuit diagram.)
Latched TTL push-pull
outputs with 2. 2nF
slow-down capacitors
-D7
D6
D5
D4
D3
BUSY
-ACK
PE
SLCT
-ERROR
D2
D1
DO
-D3
D2
not available
not available
D7
D6
D5
D4
PORT.C
TTL inputs,
no pull-up resistor
-SLCT IN
-INIT
-D1
-AUTO FEED
-DO
-STROBE
not available
not available
May be used as inputs
if corresponding output
bits are set to "1 "
Open-collector TTL output
with 4. 7kn pull-up resistor
Open-collector TTL output
with 1Okn pull-up resistor
Open-collector TTL output
with 4. 7kn pull-up resistor
Open-collector TTL output
with 4. 7kn pull-up resistor
and 2.2nF slow-down
capacitor
TABLE 1: THESE ARE ALL THE 1/0 bits available from a typical IBM parallel
printer port. The "signal name" column lists the signals by the names used in
most printer manuals. A " - " sign in front of the name means that the signal
is inverted. Refer to Fig.1 or your printer manual for the pin connections to
25-pin or 36-pin connectors.
typical IBM PC ·'clone" of Asian
origin. As far as we know, this
would be the most typical circuit
you are likely to encounter.
As you can see, the eight PORT .A
bits are mostly intended as outputs,
while five of the PORT.B bits are
available as inputs. Four of the
PORT.C bits can be used as inputs
or outputs.
Note that some of the bits are inverted between the internal data
bus and the outside world. For example, if you input bit D7 of
PORT.B, it will appear as a "1"
when its input signal line is grounded (logic "0").
The open-collector PORT.C bits
can be used as inputs by first setting the corresponding output bits
to "1". This enables the inputs to be
taken low as required. A sample
program will clarify the use of
these open-collector bits.
Assume we wanted to input the
status of a simple pushbutton
switch connected between the
- STROBE signal line and ground.
The following statements in
GWBASIC will do this:
PORT.C = &H37 A
BIT.0 = 1
OUT PORT.C,4
X = INP[PORT.C) AND BIT.0
The OUTput statement writes
to the output bits of
PORT.C, which appear as "1111"
externally, since D3, Dl & DO are
inverted. The DO signal line can
"0100"
FEBRUARY1990
69
DATA BITS - - - - - - - ,
SLCT
PE
BUSY
-ACK
24
-
-
07
23
06
22
-
05
21
-
-
04
20
-:-
03
19
18
02
DO - STROBE
01
17
16
15
-
-:-
-SLCT
IN
SIGNAL GROUNDS
- INIT - ERROR
-AUTO FEED
i
DATA BITS
-STROBE
DO
01
02
03
04
..,""
05
06
07
<
I
/;;
::,
"'
w
c..
...=l ...<
c:,
::,
"'
SIGNAL
GND
I
FRAME
GND
NC
0
2
3
4
9
10
11
12
13
14
15
impedance of the TTL outputs. Unfortunately, the pull-up and pulldown internal resistances of the
TTL outputs are not equal, resulting in a non-linearity error of
- ½LSB or - 5mV at mid-scale.
The minimum output voltage (for
a digital input of 0) is almost exactly
0.1 V, as determined by the "low"
level TTL output. The maximum
output voltage can be adjusted by
the trimpot so that an output of 2.65
volts is obtained for a digital input
of 255. Thus each step will correspond to 10mV.
The output impedance is almost
exactly lkO, and a token amount of
filtering is provided by a .0047µ.F
capacitor. A more "serious" digital
audio waveform generator would
use more elaborate filtering. A 3 or
4-section LC filter would reduce the
distortion content from 0.5% to
about 0.1 %.
16
Performance
-:' - - - - - - SIGNAL GROUNDS _ _ _ __
_
_,
~
I
i1~~AL
I
FIG.1: THESE DIAGRAMS SHOW THE pin connections for the various
IBM parallel port signals as they appear from the wiring side of a
25-pin "D" connector and a 36-pin "Centronics" connector. Beware some cheap printer cables may not include all the auxiliary signals.
Luckily, however, all manual T-switches switch the entire 36 wires
regardless of whether they are used or not.
now be taken low by pressing the
pushbutton switch. After the INPut
statement, X will be 1 if the switch
is closed, and O if the switch is
open.
This is a very easy way to interface a switch, or an opto-isolator,
since a 4. 7k0 pull-up resistor is
already supplied internally (how
convenient)!
A simple waveform
generator
Suppose you wish to use your
computer to synthesise arbitrary
waveforms, from DC levels to complex audio tone bursts? No problem. Analog voltages can always
be obtained using a D-A converter
IC but, just for demonstration pur70
S ILICON CHIP
poses, we chose to "show off" just a
little by making our own from a
handful of resistors.
Fig.2 shows how a binaryweighted resistor network can be
hung directly off the TTL data bits
to produce an analog output
voltage. The exact values of the
resistors are fairly critical, but if
you check the resistors with a
digital multimeter and put the ones
closest to the ideal values towards
the top of the· ladder, the output
voltage steps should be within
½ LSB without any further trimming.
Note that the resistors do not
form an exact binary sequence, as
we have subtracted 400 from all of
them to compensate for the internal
We wrote a demonstration program in TURBO BASIC to test the performance of this simple AID converter. As you can see from the
oscilloscope photograph, the output
is indeed quite linear.
The program is too long to be
listed in its entirety here, but the
basic technique is to set up an integer array of data bytes, then output them repeatedly to PORT.A as
fast as possible. Note that it is
necessary to disable the DOS realtime clock interrupt whilst the
waveform is being output, otherwise short pauses will occur
throughout the waveform at a rate
of 18.2Hz.
The waveform pictured has one
complete cycle of a sine wave,
made up of 256 samples, followed
by a linear ramp from O to 255. A
sample rate of 20k per second was
achieved by the compiled TURBO
BASIC program on a bog-standard
4.77MHz PC-XT.
The simplicity of this function
generator is little short of amazing
but as always, there is -a hidden
price. You really need to be a competent programmer to get useful
performance out of it.
If anything, this simple project is
a classic example of the modern
trend that microprocessors have
brought to electronics in general -
CENTRONICS
PIN NO.
(9)
HIGH QUALITY JAPANESE 500mA Hr
(2.773k)
2.7k
68!l
*
OUTPUT
1k!l
07
(5.585k)
5.6k
*
( 8)
06
.0047
5.6k
(7)
3.3k
(11.21k)
0.1V TO 2.65V
IN 10mV STEPS
PENLIGHT NICAD BATTERIES
FOR UNDER $2.00 EACH???
A 7.2V multipurpose "Six Pack" that's
easily reduced in size, or dismantled.
Individually insulated cells.
Bulk buyer enquiries welcome .
UNREPEATABLE PRICE!
5.fik
$10.90 per pack
2k
05
(22.46k)
( 6)
04
(5)
03
22k
470!l
27k
18k
180k
( 4)
02
(3)
01
.,.
* MAY NEED SOME ADJUSTMENT
ALL RESISTORS ¼W 1%
(2)
UNBELIEVABLY LOW PRICE
$5.90 ea
DO YOU WANT A REALLY LOUD SIREN
FOR YOUR ALARM?
180k
180k
Comes with circuit
and instructions.
Then have a look at this READY MADE and TESTED UNIT.
All you need is a 6-14V supply and add a horn speaker to
obtain an output of 110-125dB. NOW THAT'S LOUD!
180k
00
As used in a well-known, expensive commercial siren that
costs over $70.00.
(19) TO (30)
GNO INCLUSIVE
High power bridge design.
Comes with circuit
and instructions.
---i_
-:-
FIG.2: THIS IS THE CIRCUIT DIAGRAM for the simple 8-bit D-A
converter described in the text. Exact resistor values are shown in
parentheses. Standard 1 % resistors will do fine if you check them with
a digital multimeter first. Try to get the resistors for the two most
significant bits within ± 0.5% or better.
ONLY $11.80 ea
Metal horn speaker
to suit $13.50
Grab some while you can at this glveaway price.
SOLID STATE RELAY BARGAIN
fhese units are from BRAND NEW but unused equipment.
Zero voltage switching. More than 2.f.KV isolation.
Can switch inductive loads.
3-32V DC input from logic.
10A Max rating.
24-240V load rating.
$21.90 ea
10+ $19.90
Priced at about '/, of their real value.
You had better be quick!
!SINGLE CHANNEL UHF REMOTE CONTROL!
Don't waste your time ano money.
This is a proven, reliable and
GUARANTEED design.
5A switch and indicator relays.
Very slim and rugged transmitter.
ONLY $57.90
COMPLETE TRANSMITTER
AND RECEIVER KIT
HOW'S THAT FOR VALUE?
MASTHEAD AMPLIFIER FOR TV
See Silicon Chip May '88
High performance protected unit with 1 BdB gain.
Easily covers VHF, UHi' and FM.
Very easy to construct.
Prewound inductor supplied.
ONLY $29.90
for the amplifier and the power
and signal combiner unit.
THIS IS HOW OUR PROTOTYPE digital function generator performed when
driven by a compiled TURBO BASIC program running on a 4.77MHz PC-XT.
The sample rate here is approximately 20k samples/sec. Total non-linearity is
within ½LSB, which translates to roughly 0.5% distortion.
hardware is being replaced by software. Thoughts typed on a keyboard can replace the soldering
iron (well, almost). All that is need-
ed is a little interfacing and a lot of
imagination.
We'll have more on this subject
[lti
in future issue.
NOW THAT'S CHEAP
OATLEY
ELECTRONICS
PO BOX 89, OATLEY, NSW 2223.
PHONE (02) 579 4985
MAJOR CREDIT CARDS ACCEPTED
P + P $2·$4 (Aust); NZ add $2.00.
Distributors: Slightly higher prices may apply.
MELBOURNE: ELECTRONICS WORLD. (03) 723 3860
BRISBANE: KINGSWAY ELECTRONICS. (07) 390 2399
|