This document discusses interfacing analog and digital devices to a PC's parallel port for input and output. It provides code examples in BASIC to interface single-chip analog-to-digital and digital-to-analog converters. The analog-to-digital converter allows measuring two analog voltages and converting them to digital values. The digital-to-analog converter takes a digital value from the PC and outputs a proportional analog voltage. Both circuits use simple components and require minimal programming knowledge to implement.
This document discusses interfacing analog and digital devices to a PC's parallel port for input and output. It provides code examples in BASIC to interface single-chip analog-to-digital and digital-to-analog converters. The analog-to-digital converter allows measuring two analog voltages and converting them to digital values. The digital-to-analog converter takes a digital value from the PC and outputs a proportional analog voltage. Both circuits use simple components and require minimal programming knowledge to implement.
the PC for amateur use and direct interfacing, the parallel port is probably the simplest. With eight data wires, several control wires and bidirectional capability, it offers a convenient way to get information in and out of a PC. The examples in the next two sections use an older software language, BASIC or GWBASIC to get information in and out. Newer languages can be used, but several varieties of BASIC are available on the Internet at no cost. The learning curve for someone who has never used a programming language is very short — usually a matter of a few minutes. The two examples that follow interface single chip analog-to-digital and digital-to- analog converters to the parallel port of a PC. Single-Chip Dual-Channel A/D In this analog world, often there is need to measure an analog voltage and convert it to a digital value for further processing in a PC. This single chip converter and accompa- nying software performs this task for two analog voltages. Circuit Description The circuit consists of a single-chip A/D converter, U2, and a DB-25 male plug (Fig A). Pins 2 and 3 are identical voltage inputs, with a range from 0 to slightly less than the supply voltage VCC (+5 V). R1, R2, C3 and C4 provide some input isolation and RF bypass. There are Fig A — Only two chips are used to provide a dual-channel voltmeter. PL1 is four signal leads on U2. DO is the connected through a standard 25-pin cable to your computer printer port. U2 converted data from the A/D out to requires an 8-pin IC socket. All resistors are ¼ W. You can use the A/D as an SWR display by connecting it to a sensor such as the one shown in Chapter 19 of this the computer; DI and CS are control Handbook (Tandem Match Wattmeter project). A few more resistors are all that are signals from the computer, and CLK needed to change the voltmeter scale. The 50-kΩ Ω resistors from 2:1 voltage is a computer-generated clock signal dividers, extending the voltmeter scale on both channels to almost 10 V dc. sent to pin 7 of U2. The +5-V supply is required. It may be obtained from a +12-V source and regulator U1. Current resistors, is shown in the figure. modify it, make sure you resave it as drain is usually less than 20 mA, so Resistor accuracy is not important, an ASCII file. It can be imported into any 5-V regulator may be used for since the circuit is calibrated in the QBasic and most other BASIC U1. The power supply ground, the accompanying software. dialects. circuit ground and the computer The program was written to be ground are all tied together. If you Software understandable rather than to be already have a source of regulated The software, A2D.BAS, can be highly efficient. Each line of basic code 5 V, U1 is not needed. found on the Handbook CD. It has a comment or explanation. It can In this form the circuit will give you includes a voltmeter function and an be modified for most PCs. The printer two identical dc voltmeters. To SWR function. It is written in port used is LPT1, which is at a hex extend their range, connect voltage GWBASIC and saved as an ASCII address of 378h. If you wish to use dividers to the input points A and B. file. Therefore, you can read it on LPT2 (printer port 2), try changing the A typical 2:1 divider, using 50-kΩ any word processor, but if you address to 278h. To find the ad-
5.68 Chapter 5
Chapter 5.pmd 68 8/3/2007, 8:45 AM
dresses of your printer ports, run FINDLPT.BAS (also included on the Handbook CD). A2D.BAS was written to run on computers as slow as 4.7-MHz PC/ XTs. If you get erratic results with a much faster computer, set line 1020(CD=1) to a higher value to increase the width of the computer- generated clock pulses. The software is set up to act as an SWR meter. Connecting points A and B to the forward and reverse voltage points on any conventional SWR bridge will result in the pro- gram calculating the value of SWR. Initially the software reads the value of voltage at point A into the computer, followed by the voltage at point B. It then prints these two values on the screen, and computes their sum and difference to derive the SWR. If you use the project as a voltmeter, simply ignore the SWR reading on the screen or suppress it by deleting lines 2150, 2160 and 2170. If the two voltages are very close to each other (within 1 mV), Fig B — Only three wires and a ground lead are needed to connect the the program declares a bad reading converter to your PC. for SWR. Calibration Lines 120 and 130 in the program independently set the calibration for Circuit Description address, run FINDLPT.BAS. the two voltage inputs. To calibrate a This project is the complement of The program takes the value channel, apply a known voltage to the parallel port A/D converter AIN from the keyboard (line 230), input point A. Read the value on the described earlier. It takes a digital converts it to a number between PC screen. Now multiply the con- number from the computer, and 0 and 255, and then sends it out stant in line 120 by the correct value converts it to a voltage from 0 to 5 as a serial word to the DIA chip. If and divide the result by the value V dc. Only one chip, the MAX 512, you would like to use the project you previously saw on the screen. is required. It operates from a 5-V with another program, use your Enter this constant on line 120. supply and is connected to the other program to set AIN to the Repeat the procedure for input point computer by a standard DB-25 value you want to generate, and B and line 130. parallel port connector. The chip then run this program as a sub- may be ordered from Digi-Key, routine. D to A CONVERTERS — Allied Electronics and other ham At the end of the program is the CONTROLLING ANALOG DEVICES suppliers as MAX512CPD-ND. The clock pulse subroutine. In the event The complement to A/D convert- voltage regulator in Fig B provides your computer is too fast for the ers is D/A (digital-to-analog) convert- the 5 V source required to power converter chip, you can stretch the ers. Once there is a digital value in the chip. clock pulses by changing CD in line your PC, a D/A will provide an 5010 to a value greater than the analog voltage proportional to the Software default value of 1. digital value. Normally the actual The software needed to run value is scaled. As an example, an the chip, D2A.BAS, can be found Applications 8-bit converter allows a maximum on the Handbook CD. It is about This circuit provides the capability count of 255. If the converter is set 60 lines long, fully commented of setting a voltage under computer up with a +5 V dc reference voltage, and written in GWBASIC, so it control. It can be calibrated to a maximum value digital value of may be readily modified. The match the power supply and the 255 would result in a D/A output parallel port address is defined on actual chip used. Tests with several value of 5 V. Lower digital inputs line 105 as PORTO=&H378. Your chips showed an error of 25 mV or would give proportionally lower computer may use a different less over the range of 0 to 5 V dc voltages. address. To find the correct output. — Paul Danzer, N1II