# Simple & Cheap Analog to Digital Converter

9,029

14

1

## Introduction: Simple & Cheap Analog to Digital Converter

From the times were ADC were expensive and rare, comes a hardware-software solution for data acquisition for PCs. Based on the old Joystick port from the IBM-compatible, a technique of triggering a monostable multivibrator a resistive transducer (thermistor, photocell, strain gauge, etc) and then counting how much cycles it passes before the output of the multivibrator goes high is quite simple to implement on most PC platforms and on most languages. A VisualBasic and Qbasic sample files are shown.

## Step 1: The Joystick Port

For years many home IBM compatible PCs came with a Joystick port that had X axis, Y axis, A & B buttons signal pins. The small DB-15 connector can be accessed at address 200h & 201h. The joystick itself was just two potenciometers and two buttons. Inside the motherboard of the PC, two retriggerable monostable multivibrators (RMM for short) with fixed capacitors and IN/OUT pins were located. The RC time constant was set by the potenciometers and the capacitors. To start the signal conversion, you would make a WRITE to port address 200h and then start counting until you get a bit HIGH by doing a READ to port address 200h. This could be implemented in any language (basic, pascal, c).

## Step 2: Joystick Port in VB

This is a sample code I used to test my junkyard joystick:

Private Sub Timer1_Timer()
Dim V, H As Integer

Out &H201, &HFF
For H = 1 To 3000
If (Inp(&H201) And &H1) / &H1 = 0 Then Exit For
Next H
Horizontal.Text = H

Out &H201, &HFF
For V = 1 To 3000
If (Inp(&H201) And &H2) / &H2 = 0 Then Exit For
Next V
Vertical.Text = V

If (Inp(&H201) And &H10) / &H10 = 0 Then Shape1.FillColor = &HFF
If (Inp(&H201) And &H20) / &H10 = 0 Then Shape2.FillColor = &HFF

If (Inp(&H201) And &H10) / &H10 = 1 Then Shape1.FillColor = &HC0C0C0
If (Inp(&H201) And &H20) / &H20 = 1 Then Shape2.FillColor = &HC0C0C0

Shape3.Left = H
Shape3.Top = V

End Sub

The program only works if you have a real joystick attached to your PC. The Horizontal and Vertical Text boxes will show a value related to X and Y movements of your stick. Also a square will move around within a bigger box to represent your movements. Pressing the A and B buttons will turn read the gray circles. The sample compiled EXE file, the source code and the INPOUT32.DLL library are in the .RAR file.

## Step 3: Implement It Using the Parallel Port Under DOS

The 74 LS 123 is what I used to get the same system as the joystick port. It has two RMM. In the PDF file you can see the datasheet and a simple circuit to attach to your parallel port. I am a Qbasic fan (because it is widely available) so the code is written in it. The procedure is the same as in the VB sample:

LPTdata = &H378
LPTstatus = LPTdata + 1: LPTcontrol = LPTdata + 2

YMAXX = 500

SCREEN 2
LINE (9, 1)-(630, 170), , B, &H3333
VIEW (10, 2)-(629, 169)
WINDOW (0, YMAXX)-(620, 0)

MAXX = 620

DIM D(MAXX)

WHILE INKEY\$ = ""
OUT LPTcontrol, &H1
OUT LPTcontrol, &H0
FOR Y = 1 TO YMAXX
IF (INP(LPTstatus) AND &H10) / &H10 = 1 THEN EXIT FOR
NEXT Y

LOCATE 23, 1
PRINT USING "####"; Y

LINE (0, 0)-(MAXX, YMAXX), 0, BF

FOR I = 1 TO MAXX
LINE (I, D(I - 1))-(I, D(I))
D(I - 1) = D(I)
NEXT I
D(MAXX) = Y

WEND

One output pin is used to Trigger the MMR and one input pin to read the output of it.

## Step 4: Attaching the Ciruit to LPT

The system is implemented as half hardware and half software. The conversion of a variable resistance into a time delay is then used to count pulses and this count is our desired value.
The qbasic file will plot to screen the signal and then scroll it right.

## Step 5: Use It!

This is a common IC but other monostables can also be used. Many folks that live in places were ADC are hard to find, might like to use this circuit as a school project to plot temperature or any other stuff as long as you can make the MMR change its delay when your sensor does.

## Discussions

I enjoy finding simple circuits. Nowadays, you can find a DAC in about any microprocessor. But back in the '90s, this would have been an elegant solution. Try measuring skin resistance and repackage this instructable as a computer based lie detector. You will get huge hits. Very few people can understand analogue engineering these days.