Text preview for : e004020.pdf part of Elector Universal paralel I/o for PC



Back to : e004020.pdf | Home

COMPUTER

Universal Parallel 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 12V
D11 3

K1
RE1

IC2 78L05
R9 820 9 C2 100 25V C3 100n C4 100n 11

IC4b 1 IC4c 1 IC4d 1

4 D1 6 R1 22 8

5V

5

K9

1N4001

12V
RE2 D2 R2 22

K2

D10

IC4e 10 1 IC4f 1
12

The UPIO software and hardware (a board attached to the PC's parallel port) allows you control up to eight relay outputs using a Windows-style user interface designed for user-friendliness. UPIO also allows you read back logic states on input lines.

13

12V IC4 = 74LS05 12V IC4a 2 1
1 11

K3
RE3

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 tristate 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 execution. The third essential component is a power driver type ULN2803 (IC1) which enables output relays Re1-Re8 to be actuated 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 approximately 12 volts DC. An on-board regulator 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. Obviously, the mains adaptor should be able to supply the necessary current (all relays may be actuated at the same time!).

K11
D9 R3

D3

IC3 74HCT574
C1 C1 EN 470 25V 1

1N4001

22

12V
D4 10 +VS 11 12 13 14 15 16 17 18 R5 22 D5 RE5 R4 22 RE4

K4

K10
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 10 11 12 13 14 15 16 17 18 STROBE D0 D1 D2 D3 D4 D5 D6 D7

9 8 7 6 5 4 3 2

1D

12 13 14 15 16 17 18 19

8 7 6 5 4 3 2 1

I8 I7 I6 I5 I4 I3 I2 I1

O8 O7 O6

12V

K5

IC1

O5 O4

ULN O3 2803
O2 O1 VEE 9

12V
1

K6
RE6

5V
D6 R6

IC5a
EN 1

R10 4x 10k 2 3 4 5

22

K13

18 16 14 12

2 4 6 8 C10 C13 R7 22

12V
D7 RE7

K7

12V
4x 22n 1

K8
RE8

5V
D8 R8 22

IC5b
EN 19

R11 4x 10k 2 3 4 5

K12 5V

9 7 5 3

11 13 15 17 C6 C9

20

C5 100n

14

C15 100n

20

C14 100n

IC3
10

IC4
7

IC5
10

IC5 = 74HCT241
4x 22n

002011 - 11

Figure 1. UPIO circuit diagram.

20

Elektor Electronics

4/2000

COMPUTER
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 Figure 2. The ready-made board is available through our Readers Services as item 002011-1. A PCB-mount `blue ribbon' 36-way Centronics 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 (connected directly to the relay contacts) allow the user to select N.C. (normally closed) or N.O. (normally open) type contacts. The digital inputs are divided over two 4-way SIL connectors, K12 and K13.

Tailor-made process control
Originally, the author supplied rather simple control software. By means of a `program-style file', created by the application, 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.

H1

H2

K8

K7

K6

K5

K4

K3

K2

D8

D7

D6

D5

D4

D3

D2

D1

RE8

RE7

RE6

RE5

RE4

RE3

RE2

COMPONENTS LIST
K12

R8 C6 C7 C8 C9 R11 K13 C10 C11 C12 C13 R10
H4

R7

R6

R5

R4

R3 C1 IC2

R2 D9 C3

RE1

R1

Resistors: R1-R8 = 22 R9 = 820 R10,R11 = SIL array 4 x 10k Capacitors: C1 = 470F 25V radial C2 = 100F 25V radial C3,C4,C5,C14,C15 = 100nF C6-C13 = 22nF 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-A0002B201 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)

IC1 C5 D10 D11 C2 C15 K9 R9 IC5

K11 IC3 IC4 C14

C4

+
0 K10 002011-1 1-110200
ROTKELE )C(
H3

Figure 2. PCB design for the UPIO hardware (board available ready-made).
4/2000 Elektor Electronics 21

K1

(C) ELEKTOR

002011-1

COMPUTER
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 principles. Under DOS and Windows 3.1, it used to be relatively easy to control PC hardware directly using higher programming languages like BASIC or Pascal. All that was needed at that time was the odd IN/OUT instruction in BASIC, or its PORT equivalent in Pascal. erties used in the example program (a Delphi 2 application) will be given below. The really essential procedures are OpenDriver 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 programmers 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. not be edited because the LPT component 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.
(002011-1)

Design and software editing: L. Lemmens Text editing: J. Buiting

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.

Figure 3. Screendump showing the UPIO control software in action.
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 locations. 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 (shareware) LPT component called TVicPort written by Victor Ishikeev. This component is available in versions for Delphi (version 2 through 5), Java Builder (version 1, 3 and 4), Visual BASIC (version 6), Borland 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 component. A brief discussion of the methods and prop22

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
Elektor Electronics 4/2000