e004020.pdf

(168 KB) Pobierz
002011-UK UPIO
COMPU TER
Input/Output for PCs
Hardware design by D. Aggelos
Here’s a simple project with Windows control software that allows you to
control up to eight relays or other actuators, and read back an equal
number of input lines, all by means of the parallel port on your PC.
12V
K1
The UPIO software and hardware (a
board attached to the PC’s parallel port)
allows you control up to eight relay out-
puts using a Windows-style user interface
designed for user-friendliness. UPIO also
allows you read back logic states on input
lines.
3
IC4b
4
12V
IC2
1
RE1
D1
D11
78L05
5V
5
IC4c
6
1
R1
22
K9
1N4001
R9
9
IC4d
8
12V
K2
1
C2
C3
C4
D1 0
IC4e
RE2
100µ
25V
100n
100n
11
10
D2
1
13
IC4f
12
R2
22
Circuit description
The circuit that belongs with the UPIO
program is very simple and consists of a
few low-cost and easy to find parts. The
circuit diagram is given in Figure 1. A tri-
state buffer type 74HCT241(IC5) arranges
all input contact reading. An 8-bit latch
type 74HCT574 (IC3) is used to preserve
the output state during instruction exe-
cution. The third essential component is
a power driver type ULN2803 (IC1) which
enables output relays Re1-Re8 to be actu-
ated and de-actuated.
Because the LPT input port consists of
just four bits (one nibble), two subsequent
readings are required from the HCT241 to
obtain the whole (8-bit wide) input word.
Supply power comes from an external
mains adaptor with an output of approxi-
mately 12 volts DC. An on-board regula-
tor type 78L05 (IC2) provides the HCT
and LS ICs with a 5-volt supply rail. Note
that the ULN2803 and relays are powered
from the unregulated 12-V supply. Obvi-
ously, the mains adaptor should be able
to supply the necessary current (all relays
may be actuated at the same time!).
1
K3
12V
IC4 = 74LS05
12V
RE3
K11
D3
IC4a
2
D9
1
R3
22
IC3
1N4001
74HCT574
K4
1
C1
12V
11
C1
K10
1
470µ 25V
RE4
EN
D4
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
1
2
3
4
5
6
7
8
9
STROBE
D0
D1
D2
D3
D4
D5
D6
D7
10
9
1D
12
13
14
15
16
17
18
19
8
I8
+VS
O8
11
12
13
14
15
16
17
18
R4
22
8
7
I7
O7
K5
7
6
I6
O6
12V
6
5
I5
O5
IC1
5
4
RE5
I4
O4
D5
4
3
ULN
I3
2803
O3
3
2
I2
O2
R5
22
2
1
I1
O1
10
11
12
13
14
15
16
17
18
VEE
K6
9
12V
1
5V
D6
RE6
IC5a
R10
EN
1
4x 10k
R6
22
2
3
4
5
K13
K7
18
2
12V
16
4
6
8
RE7
14
D7
12
C10
C13
R7
22
12V
K8
4x 22n
5V
1
RE8
IC5b
R11
D8
EN
19
4x 10k
R8
22
2
3
4
5
K12
9
11
5V
7
13
15
17
5
3
20
C5
14
C15
20
C14
C6
C9
IC3
IC4
IC5
10
100n
7
100n
10
100n
IC5 = 74HCT241
4x 22n
002011 - 11
Figure 1. UPIO circuit diagram.
20
Elektor Electronics
4/2000
Universal Parallel
138911045.047.png 138911045.048.png 138911045.049.png 138911045.050.png 138911045.001.png 138911045.002.png 138911045.003.png 138911045.004.png 138911045.005.png 138911045.006.png 138911045.007.png 138911045.008.png 138911045.009.png
 
COMPU TER
The PCB
The PCB for this project was redesigned
to reflect Elektor style and standards from
artwork originally supplied by the author.
The resulting design is shown in Fig-
ure 2. The ready-made board is available
through our Readers Services as item
002011-1.
A PCB-mount ‘blue ribbon’ 36-way Cen-
tronics socket is used at the input to
allow easy connection to your PC’s
printer port. At the ‘output’ side of the
board, 3-way screw terminal blocks (con-
nected directly to the relay contacts)
allow the user to select N.C. (normally
closed) or N.O. (normally open) type con-
tacts. The digital inputs are divided over
two 4-way SIL connectors, K12 and K13.
Tailor-made
process control
Originally, the author supplied rather sim-
ple control software. By means of a ‘pro-
gram-style file’, created by the applica-
tion, it was possible to produce a simple
‘Output Flow’ with user-defined timing. In addition,
output states could be checked by reading up to
eight contact-type inputs. Together with the output
control this allows ‘Hold’ or ‘One-Shot’ action to be
implemented, both are well-established features in
flow control systems.
H2
D8
D7
D6
D5
D4
D3
D2
D1
COMPONENTS LIST
R8
R7
R6
R5
R4
R3
R2
R1
C1
K12
C6
C7
C8
C9
Resistors:
R1-R8 = 22
R9 = 820
IC1
IC2
D9
R10,R11 = SIL array 4 x 10k
C3
D10
R11
K11
C4
C2
K13
C10
C1 1
C12
C13
IC3
Capacitors:
C1 = 470 µ F 25V radial
C2 = 100
IC4
K9
+
C14
F 25V radial
C3,C4,C5,C14,C15 = 100nF
C6-C13 = 22nF
µ
0
R10
K10
002011-1
H4
Semiconductors:
D1-D8 = 1N4148
D9,D11 = 1N4001
D10 = LED
IC1 = ULN2803
IC2 = 78L05
IC3 = 74HCT574
IC4 = 74LS05
IC5 = 74HCT241
Miscellaneous:
K1-K8 = 3 way PCB terminal
block, raster 5mm
RE1-RE8 = PCB mount relay, 12V,
e.g., Siemens V23040-A0002-
B201
K9 = 2-way PCB terminal block,
raster 5mm
K10 = 36-way Centronics
connector, PCB mount
K11 = 3-way SIL pinheader with
jumper
K12,K13 = 4-way SIL-header
PCB, order code 002011-1 , see
Readers Services page and
Elektor website.
Disk, contains all project software,
order code 002011-11 , see
Readers Services page and
Elektor website (free download
for subscribers)
Figure 2. PCB design for the UPIO hardware (board available ready-made).
4/2000
Elektor Electronics
21
138911045.010.png 138911045.011.png 138911045.012.png 138911045.013.png 138911045.014.png 138911045.015.png 138911045.016.png 138911045.017.png 138911045.018.png 138911045.019.png 138911045.020.png 138911045.021.png 138911045.022.png 138911045.023.png 138911045.024.png 138911045.025.png 138911045.026.png 138911045.027.png 138911045.028.png 138911045.029.png 138911045.030.png 138911045.031.png 138911045.032.png 138911045.033.png 138911045.034.png 138911045.035.png 138911045.036.png 138911045.037.png 138911045.038.png 138911045.039.png 138911045.040.png 138911045.041.png 138911045.042.png 138911045.043.png 138911045.044.png
COMPU TER
Talking to ports
under Windows 95/98/NT
Having played around with the original software for
a while it was felt that this was rather unrefined
and unreliable. So our staff designer Luc Lemmens
set out to write an improved control program for the
UPIO hardware. Let’s look at the underlying prin-
ciples.
Under DOS and Windows 3.1, it used to be rel-
atively easy to control PC hardware directly using
higher programming languages like BASIC or Pas-
cal. All that was needed at that time was the odd
IN/OUT instruction in BASIC, or its PORT equiva-
lent in Pascal.
erties used in the example program (a
Delphi 2 application) will be given below.
not be edited because the LPT compo-
nent is missing. Also, because of various
problems we do not recommend using
the original ‘.exe’ file.
As a matter of interest only, the circuit
diagram was originally designed using
‘Protel’ schematic capture, while
‘Advanced Schematics’ software was
used for the PCB design. Both the circuit
diagram and the PCB artwork were
redesigned by Elektor Electronics for the
purpose of this article.
The really essential procedures are Open-
Driver and CloseDriver which, you
guessed it, open and close the TVicport
respectively. The logic variable (property)
ActiveHW flags if the port is open or
closed, or, in actual fact, if the driver is
available or not.
The property LPTNumPorts indicates
the number of printer ports in the system,
while LPTNumber determines which LPT
is being controlled by the driver. Finally,
LPTBaseAddress shows the base address
of that particular port. The component
also has a property called Pin , an array of
25 logic variables (bits) representing the
logic levels (states) found on hardware
port pins. By means of this array pro-
grammers have easy access to the pins
on the printer port. You only have to be
cautious which pin is input or output
only, or bi-directional.
(002011-1)
Design and software editing: L. Lemmens
Text editing: J. Buiting
Figure 3. Screendump showing the UPIO
control software in action.
HWTest and
the example program
The HWTest program as supplied on the
project disk illustrates the practical use of
this component in many ways. In fact,
we’d say it is a perfect starting point for
your own applications.
Naturally the example program (also
supplied on disk) was derived from
HWTest. The 8 relays on the UPIO board
may be switched on and off by ticking the
relevant boxes. The ticks in the panel
below the relay boxes indicate if a digital
input is high or low. If the PC contains
several printer ports, the thumbwheel
switch allows a different port to be
selected. As a matter of course, the
printer port control will only work if the
driver has been successfully loaded by
pressing the ‘Open Driver’ button. A
screendump of the UPIO control program
is shown in Figure 3.
In later versions of the Windows GUI, (release
95 and later), the user is increasingly ‘isolated’ from
the hardware, and it is no longer possible (and even
forbidden under Windows 95) to communicate
directly with various registers and memory loca-
tions. This kind of ‘Smalltalk’ is completely left to
the operating system in conjunction with various
device drivers. Writing your own device drivers is
arduous to say the least, so it is often better to go
on the Internet and see if someone else discovered
the wheel for you. In this case we landed at
www.entechtaiwan.com where we found a (share-
ware) LPT component called TVicPort written by
Victor Ishikeev. This component is available in ver-
sions for Delphi (version 2 through 5), Java Builder
(version 1, 3 and 4), Visual BASIC (version 6), Bor-
land C++ and MS Visual C++ in Windows 95/98
and Windows NT.
As could be expected in this day and age of
object-oriented programming, the printer port is no
more than an object with all sorts of properties and
responding to all sorts of events . Using this concept
the programmer has easy access to the object (in
this case the printer port), while control is exerted
via methods associated with the relevant compo-
nent. A brief discussion of the methods and prop-
Tools used for the project
For the original UPIO.exe application, the
author used Borland Delphi development
environment (Version 1-16 bits), which
generates the ‘.dpr’ application program
files, the ‘.pas’ unit files, the ‘.opt’ and
‘.res’ files. All original files for the UPIO
project, as well as the refurbished version
of the control software may be found on
a floppy disk with order code 002011-11.
It should be noted that the source code
file as we received it from the author is
supplied ‘for information only’ — it can
22
Elektor Electronics
4/2000
138911045.045.png 138911045.046.png
Zgłoś jeśli naruszono regulamin