This is only a preview of the November 1993 issue of Silicon Chip. You can view 33 of the 96 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Build A Jumbo Digital Clock":
Items relevant to "High Efficiency Inverter For Fluorescent Tubes":
Articles in this series:
Articles in this series:
Items relevant to "Stereo Preamplifier With IR Remote Control; Pt.3":
Articles in this series:
Items relevant to "Computer Bits":
|
COMPUTER BITS
BY DARREN YATES
More experiments for your games card
Games cards are more than just entertainment
adaptors – they can provide a simple interface
between the outside world & your PC. In this
article, we turn your games card into an 8-bit
A/D converter using an op amp & a transistor.
When we came out with the first
“Experiments for Your Games Card”
article in January 1992, we looked
mainly at using the existing circuitry
on the card to accept analog resistive
devices such as light-dependent resistors (LDRs) and thermistors.
Going back briefly to what we discussed, the games card essentially
contains four 555 timers (in the one
chip) which are connected up as monostables. The circuit in Fig.1 gives the
general idea. The setting of the joystick
provides the current which charges
the .01µF capacitor. The computer
then keeps a record of how long the
monostable output is high, once it has
been triggered, by incrementing an
8-bit register.
Fig.2 shows the pin-outs of the DB15
joystick adaptor socket. As you can
see, it allows up to four analog inputs
(via the joytick controls) and four digital inputs (via the fire buttons). Also
included are two +5V supply rail pins
and a number of GND pins.
Last time, we showed you how to
connect an LDR or a thermistor into
the card to measure light and temperature. This allowed us to measure
analog signals “of sorts”. The reason
we say this is that using this method,
you can’t just apply an analog voltage
directly onto the input and that all
comes down to the fact that we have
to charge up a capacitor in the 555
circuit on the card.
Since a capacitor charges up linearly with current and not voltage, this
70 Silicon Chip
makes it a bit difficult. Also, if the
capacitor doesn’t rise above +3.3V
(ie. 2/3Vcc), the 555 will never reach
its threshold and switch off after it
has been triggered. It is this turning
off which tells the computer to stop
counting. If we did feed a direct analog
Fig.1: the input control circuitry for
a typical games card. There are four
such circuits to cover all the controls
on a joystick.
voltage into the joystick inputs, the
circuit would not respond until the
capacitor’s voltage rose above +3.3V.
However, we can solve that with the
simple circuit shown in Fig.3. Using
one op amp and a transistor, we can
turn the joystick input into a modest
fractional 8-bit analog-to-digital converter or ADC. And since the joystick
port comes with four analog inputs,
this gives up to four channels.
Putting it simply, the op amp and
transistor form a vol
tage-to-current
converter which turns our analog input voltage into a current which then
charges up the 555’s .01µF capacitor.
VR1 adjusts the output current to obtain the best display. Notice that we are
obtaining the 5V supply for the circuit
from the games card (pin 1). The op
amp used is an LM358 dual package
so by using just another transistor, you
can get a second channel.
By using BASIC’s STICK command,
it’s a simple case of reading off the
8-bit number from that command to
retrieve the digital code produced by
the games card.
Low-frequency scope
Fig.2: the pin connection details for
the DB15 sockets on a games card.
Putting this into practice, we wrote
a small program to use the card as a
low-frequency oscilloscope. Because
QBasic is quite slow and the STICK
command even slower, the upper frequency limit is only 10Hz. This is because QBasic can only take 40 readings
from the joystick every second –even
with a 40MHz 386DX. This necessitates the use of a 100µF capacitor on
the input so that low-frequency signals
are not reduced in amplitude.
Be that as it may, the display in
Fig.4 shows the results of the program. Even though 10Hz is a low
frequency, the circuit is still useful
because it can be used to measure
long term changes in circuit voltages,
PIN 1
to take a look at QBasic.
Even though QBasic is
47k
only an interpreter, it is a
big improvement on GWBasic and it has an easy-toQ1
22k
8
2
BC558
use screen editor and no
line numbering!
1
100
IC1a
16VW
LM358
The STICK command
3
makes
programming the
4
PIN 3
games card quite easy
68k
PIN 4
and takes the work out of
having to count up registers and examine inputs
Fig.3: this simple circuit functions as a voltage
to current converter & connects to one of the
and all the nitty gritty. It
joystick pot inputs.
works as follows. When
you want to take a reading
for an all-up cost of about $2 in parts! of the joystick port, you have to use
The maximum input signal is 400mV the STICK(0) statement. When the
p-p for a sinewave and 200mV for a program implements STICK(0), it not
squarewave. Any more than this and only records the x-input from the
the joystick counter register gives first joystick, it also takes a record of
erroneous results.
all joystick inputs. The good thing
With the components specified, about this is that if you decide to use
there is a range of about 80 to 170 on all four inputs as ADCs, this system
the 8-bit range. It still has 8-bit reso- won’t travel any slower.
lution – but not over the full range of
STICK(0) holds the x-input from
0 to 255. No, this isn’t eight bits but Joystick A, STICK(1) the y-input from
it’s not bad for $2.
joystick A, STICK(2) the x-input from
joystick B and STICK(3) the y-value
Programming
from B, but you must use STICK(0)
Since January 1992, DOS 4.01 and first. For example, let’s say we wanted
DOS 5 have gone by the wayside and to take 640 samples from the last two
we’ve moved into the era of DOS 6. joystick analog inputs; ie, the x and y
This means that many machines will inputs from joystick 2 and store them
have QBasic instead of GWBasic, al- in an array for future use. These correthough the following tips are equally spond to the commands STICK(2) and
valid in both. However, if you’re still STICK(3). A simple BASIC routine is
working with GWBasic, you may want as follows:
VR1
10k
Fig.4: this sample display of the output screen is for a 5Hz 100mV RMS
sinewave input signal. The on-screen instructions tell you how to expand or
compress the x & y axes (note: instructions not shown here for the y axis).
DIM SAMPLE1(640),SAMPLE2(640)
FOR NUMBER = 1 TO 640
TEST=STICK(0)
SAMPLE1(NUMBER)=STICK(2)
SAMPLE2(NUMBER)=STICK(3)
NEXT NUMBER
Note that we must first perform a
STICK(0) command before we can
get information from STICK(2) or
STICK(3). By using DEFINT SAMPLE1,
SAMPLE2, you can speed up the program by 5-10% since operation on a
single-byte integer variable is faster
than floating-point variables.
To save these arrays as a file, you
could use the following routine:
OPEN [FILENAME.EXT] FOR OUTPUT AS #1
FOR NUMBER = 1 TO 640
PRINT#1,SAMPLE1(NUMBER)
PRINT#1,SAMPLE2(NUMBER)
NEXT NUMBER
CLOSE #1
The data is then saved in the following format:
SAMPLE1(1)
SAMPLE2(1)
SAMPLE1(2)
SAMPLE2(2)
SAMPLE1(3)
and so on. By replacing the OUTPUT
and PRINT statements with INPUT,
you can retrieve this information
out of the file, for use in another
program. In fact, this is a very basic
model of how audio signals can be
retrieved from extremely noisy sign
als using noise averaging techniques.
The stored data is fed through an
algorithm which manages to remove
the noise component and retrieve the
original signal. You may even want to
try having a crack at it if you have the
relevant information.
The program CRO.BAS produced
the diagram in Fig.4 and can be run
from QBasic or, if you have access,
on a BASIC compiler. This will speed
things up to a degree, particularly if
you use Turbo Basic from Borland.
If push comes to shove, you could
probably get it to work on GWBASIC
provided you add in the line numbers.
The listing is too long to include
here but we can provide a copy of
the file on disc, as well as a complied
version called CRO.EXE. If you would
like a copy, write to SILICON CHIP, PO
Box 139, Collaroy, NSW 2097. The cost
is $10 (incl. p&p) and payment can be
made either via cheque on by quoting
a credit card number. Please indicate
whether you require a 5.25-inch or
SC
3.5-inch disc.
November 1993 71
|