Parallel port D/A converter
Home
Up

Parallel Port experiments

Jim's webpage http://www.jimspage.co.nz/intro.html describes a smart & simple interfacing method for getting flightsim data via RS232 com port to another PC, where the data can be read with GWbasic and send to the parallel port.  I have tried this interface and it works very well. GWbasic commands for driving the parallel port are very simple:  " out 888, xxx  ", where 888 (378 hex) is the address of the parallel port data pins, and xxx is a number from 0 to 255 that will drive the data pins #2 - #9.  000 means all pins are low, and 255 means all pins are high. Anything in between will set the bits according the binary code.   

GWbasic can be run from a DOS box under Win98 and WinMe. I did not succeed in getting it to work under XP. For best  results, you better run GWbasic directly from the command prompt. To see what is happening on the parallel port, you can make a simple circuit like shown below, that should give you an visual indication when one of the parallel port data pins is high.


The parallel port has also other control pins.  # 1, 14, 16 and 17 can be used as outputs, under address 890 (37A hex) . Note that #1, #14 and #17 are inverted: i.e. sending a 0 will make it go high.

The parallel port can be used for driving relays, but you can also make it into a cheap Digital - Analog Converter (DAC), by letting the data pins drive an R-2R resistor network. For more accuracy, it is better to use a buffer in between the data pins and the resistor network.

For two DAC outputs from the same parallel port, you can drive two 8-bit latch IC's, where the data is latched into the buffer by a control signal from one of the control pins. A possible schematic is shown below. For IC spec, see here

  

The software writes data to the port, then control #14 (CK DAC1)  low - high - low, the data is latched in DAC1 and new DAC1 voltage is at output 1. Then the software writes data for DAC2 to the port, then controls #17 (CK DAC2)  low-high-low, the data is latched in DAC2 and new DAC2 voltage is at output 2. In this way, two independent DAC voltages can be achieved. Totally four DAC's could be used, each one's clock controlled by one of the 4 control pins.  

I build this circuit and wrote a program that runs a continuous loop, sending 0, 1, 2, ..255 for DAC1 and 255, 254, 253,...0 for DAC2. Both DAC's are clocked in each loop cycle.

10 OUT 888,0 : REM sets all data outputs low
20 OUT 890,11 : REM sets control pins #1,#14,#16,#17 low
30 FOR I = 0 TO 255 : REM starts loop, I will be used as DAC1 value
40 N = 255 - I : REM defines N that will be used as DAC2 value
50 OUT 888,I : REM sends value I to the parallel port data pins (in binary)
60 OUT 890,9 : REM sets control pin #14 high (others stay low) clocks value I into DAC1
70 OUT 890,11 : REM sets control pin#14 low (others stay low)
80 OUT 888,N : REM sends value N to the parallel port data pins (in binary)
90 OUT 890,3 : REM sets control pin #17 high (others stay low) clocks value N into DAC2
100 OUT 890,11 : REM sets control pin#17 low (others stay low)
110 NEXT I : REM continues for next value of I
120 GOTO 30 : REM will start the whole process all over again

Note: If you want to run this program, copy the text to notepad. then use "save as" and select "all files" and type a name like DACTEST.BAS This file can be loaded into GWbasic and run in a DOS window.

The measurement results are below:


DAC1 (upper waveform) and DAC2 (lower waveform) output when running in DOS box
Running in windowed mode will cause Windows to interrupt the program regularly


DAC1 and DAC2 output from command prompt: No more interrupts, runs smooth. 255 steps will finish in 10.4msec


DAC1 and DAC2 output when running the compiled program in command prompt. Runs twice as fast and very stable: 255 steps in 4.2msec


Parallel port experiment board.

This experiment shows that using parallel port for driving multiple DAC's is possible. Speed should not be a problem. I ran my program from a Pentium1  (200MHz) PC.

Back Next