Thursday, March 28, 2024

Parallel-Port Controller Using MATLAB

By Devanand T.

Many projects have been published in EFY on how to program a PC’s parallel port using C, C++ and Visual Basic. Here we attempt the same using MATLAB. The advantage of Matlab is that it does not require any special device driver to run in Windows XP. It has rich ‘help’ documents and a large number of user community on the Internet, including Kluid and Matlab Central, which makes even an absolute beginner create an application quickly.

Described here are two simple application programs in Matlab for controlling eight LEDs and a unipolar stepper motor through the parallel port. Since the files are bulky, you need a PC with at least 512MB RAM to run Matlab.

Parallel port

The parallel port of the PC is a 25-pin, D-type connector, commonly known as LPT (line printer terminal) port, having three different ports, namely, data port, control port and status port. Access to the parallel port is via 25-pin, D-type female connector (DB25) as shown below. This female connector is normally available at the back side of your PC.

Fig.1:25-pin parallel-port connector (DB25)
25-pin parallel-port connector (DB25)

In order to access any port, you should have its port ID, i.e., the base address of the port. Here the data port has its base address as ‘0378’ in hex format. The addresses of the three ports are in sequential order. So if the address of the data port is ‘0×378,’ the addresses of the status port and the control port will be ‘0×378+1’and ‘0×378+2,’ respectively.

Not all the 25 pins of the port are used for every application. Normally, the eight data lines (pins 2 through 9) along with the signal ground line are used. Pins 2 through 9 form the data port, thus making it an 8-bit wide port. It is a unidirectional port, i.e., it can be used only to output the data to the connected device. Pins 1, 14, 16 and 17 form the control port. It is a bidirectional port, i.e., it can be used both to input and output the data to and from a device. Pins 10 through 13 and 15 form the status port. It is a unidirectional port, i.e., it can be used only for data input from a device. The various pin functions of the parallel port are shown in Table I.

- Advertisement -

325_May-_-table--_--efy

Circuit description

Below is the combined interfacing circuit for controlling the LEDs and the stepper motor through the parallel port. Here, LED1 through LED8 are connected to pins 2 through 9, respectively, of the parallel port. You can check these pins for proper working by clicking ‘all on’ and ‘all off’ buttons from the software (refer Fig.3). All the eight LEDs will glow on clicking ‘all on’ button and turn off on clicking ‘all off’ button. Each individual LED can also be made to glow/turn off by ticking the corresponding checkbox. The LED control application program works without external power supply in the circuit.

Fig.2: Interfacing circuit for controlling the LEDs and the stepper motor
Interfacing circuit for controlling the LEDs and the stepper motor
Fig.3: Screenshot of the LED control program output
Screenshot of the LED control program output

There is another application program used to control the number of rotations, direction (clockwise or anticlockwise) and the rotational speed of the stepper motor. Optocoupler MCT2E ICs (IC2 through IC5) is recommended for interfacing the stepper motor to the parallel port. Each of these ICs has an internal LED and a photo-transistor.

- Advertisement -

The external circuitry of the internal LED and phototransistor of IC MCT2E differ. The internal LED is driven by the signal from the parallel port, whereas a separate 12V supply powers the photo-transistor. Therefore it completely isolates the parallel port from the rest of the interfacing circuit. This ensures the safety of the parallel port as it can get damaged in case of shorting of the external circuit.

Fig.4:Circuit for 12V power supply
Circuit for 12V power supply

IC ULN2003 (IC6) is used to drive the stepper motor. It is a high-voltage, high-current Darlington transistor array. It consists of seven NPN Darlington pairs that feature high-voltage outputs with internal common-cathode clamp diodes for switching inductive loads. The collector-current rating of a single Darlington pair is 500 mA. The Darlington pairs can be paralleled for higher current capability. Other applications of this IC include relay driver, lamp driver, display driver, line driver and logic buffer.

SHARE YOUR THOUGHTS & COMMENTS

Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components

Calculators