This is only a preview of the January 1992 issue of Silicon Chip. You can view 43 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 4-Channel Guitar Mixer":
Articles in this series:
Items relevant to "Experiments For Your Games Card":
Articles in this series:
Articles in this series:
Articles in this series:
|
~
COMPUTER EXPERIMENTS
=INJ#-
By DARREN YATES
Experiments for
your games card
You may not have realised it but you can do
much more with your PC's game card than just
play games. In this article, we'll show you how
you can use it to detect various inputs and
provide a few GWBASIC routines so that you
can start experimenting.
If you have a good look at the computer adverts in SILICON CHIP, you
will notice that there are all manner
of plug-in cards available that you
can install in your PC to make it do
just about anything.
There are clock cards, memory
cards, video driver cards, I/O cards
and diagnostic cards, plus a host of
others. There are even cards that will
allow your computer to act as a facsimile machine.
However, many people think of the
humble games card as a "keep the
kids happy" item. That's little unfair because, for just $30 or less, a
games card can be a very cheap alter-
a
native to some of the dedicated input
cards currently available.
A typical example of the current
generation of games cards is the one
on offer from Rod Irving Electronics.
It sells for just $29 and has inputs for
two joysticks via DB15 sockets. It's
also easy to install-you just whip the
top off your computer and plug it into
one of the expansion ports on the
motherboard.
Let's see what's involved in using
one of these cards.
SILICON CHIP
+5V
X·PLANE
CONTROL OF~,__._..
JOYSTICK
2.2k
TRIGGER
1/41558
OUTPUT
Card circuitry
The games card contains four !Cs, a
handful of passive components and
little else. Our main
centre of interest on
!'
the board is an NE558
quad timer IC, which
is basically four inde-
This games control
card is available
from Rod Irving
Electronics & sells for
just $29. It plugs into
an expansion slot on
the motherboard &
has inputs for two
joysticks via DB15
sockets.
42
pendent 555 timers in the one package. This IC interfaces to the joystick
controls, while the rest of the card
can be accessed only by the computer.
Fig.1 shows a partial circuit diagram of the NE558 quad timer IC circuitry. In reality, this part of the circuit is replicated four times to cover
the controls in both joysticks, so we'll
just look at one section.
If we take a look at the average
joystick, it contains two variable resistors (potentiometers) and a couple
of switches. The two potentiometers
Fig.1: the input control circuitry for
the games card. There are four such
circuits to cover all the controls on
the joysticks.
take care of direction, one in the xplane and the other in the y-plane.
The two pushbutton switches,
which most joysticks have, allow us
to blow F18s out of the sky and other
things. We can use these inputs too,
as we shall explain shortly.
By moving the joystick around, we
move the wipers of the potentiometers
and thus change their resistance values. As shown in Fig.1, each potentiometer forms an RC time constant
with a 2.ZkQ resistor and a .0lµF
capacitor, and so this time constant
X
s1
I
( tlV_I_ \ • 1
2
\
\._ 9 _
+SV
s21
lL 3
I10 __
GJ!D_ G_!!!I_
4
,5
11 _
X
L-I- - -.,
6
12 __ 13_
GND
S41
Y
7
I14-
08
I
01:.;'
S31
y
Fig.2: the pinout details for the DB15
sockets on the card. The joystick
potentiometers can be replaced with
resistive sensors, while the switches
can be replaced with relay contacts.
varies according to the resistance of
the control.
In normal operation, the computer
sends a signal to the trigger input of
the 558 timer and the capacitor charges
up via the joystick pot and the 2.2kQ
resistor. During this time, the computer clocks an 8-bit counter. When the
capacitor voltage reaches the threshold voltage, the output of the timer
changes state and the computer stops
counting.
The value in the counter when it
finishes counting is available in a register and we can access this number
using a couple of simple GWBASIC
commands.
Obviously, the larger the value set
by the potentiometer, the longer it
take for the .0lµF capacitor to charge
up and the larger the value in the
counter. This gives us a type of analog
to digital (AID) converter.
In fact, it is really a resistance to
digital converter since it is the resistance, and not voltage, that is changing.
larly, one side of each of the switch
inputs is connected to the circuit
ground.
This is all the information we need
to adapt the card for other applications. In fact, we can replace the joystick with just about any resistancevarying device we choose and we will
give you a few examples.
Temperature measurement
If we replace the joystick with a
thermistor, we can produce a very
simple but effective thermometer.
Fig.3 shows the circuit diagram for
this. You simply connect the thermistor leads to pins 1 & 3 of the DB15
socket. Now isn't that easy?
The circuit works because the resistance of the thermistor changes with
temperature, which also changes the
time constant of the timer circuit.
Thus, the value in the counter will be
proportional to the temperature.
The small BASIC routine in Listing
1 prints the value on the screen. The
STICK(0) functi_on in GWBASIC returns
the counter value for the x-plane controller of the first joystick, which is
where our thermistor is located.
This program is quite small since it
just gives an on-screen reading, but
could easily be expanded to record
temperature over time, save data to
disc, or do other jobs.
Light measurement
By using a light dependent resistor
PIN1-----.
TH1
NTC
0815
SOCKET
Fig.3: the replacing one of the
joystick controls with a
thermistor, we have a simple
thermometer. The small BASIC
routine in Listing 1 prints the
value on the screen.
PIN1-----~
L0R1
0815
ORP12
SOCKET
PIN6
osi~o1
(0SE CAT Z-4801
Fig.4: by using an LDR instead
of a thermistor, we can monitor
changes in light level.
(LDR) instead of a thermistor, we can
measure changes in light level. Fig.4
shows the circuit details. Note that,
this time, the sensor has been connected between pins 1 & 6 (ie, to the
y-plane input).
If you now look at the program
shown in Listing 2, you can see that it
is identical in structure to Listing 1
except that the STICK(0) statement has
become STICK(l). The program thus
looks at the y-plane control of the
joystick where our LDR is located.
You could use this simple set-up to
monitor light levels in a greenhouse
or for any other application where
LISTING 1 - TEMPERATURE MEASUREMENT PROGRAM
10 REM Temperature Measurement
20 REM copyright 1991 SILICON CHIP magazine
30 CLS: KEY OFF
40 LOCATE 1,26:PRlNT"SILICON CHIP THERMOMETER"
50 T =STICK(0)
60 LOCATE 3,30: PRINT"Temperature = ";
70 PRINTT
80 GOTO 50
DB15 sockets
The pinout diagram for the DB15
sockets on the card is shown in Fig.2.
Pins 1 & 9 are the +5V supply pins
which we can use to power our
projects, provided we only draw low
currents. Pins 4, 5 & 12 are the ground
pins.
As we can see in Fig.1, because one
side of each pot is tied to the +5V
supply rail, the number of input connections required is reduced. Simi-
LISTING 2 - LIGHT MEASUREMENT PROGRAM
10 REM Light Measurement
20 REM copyright 1991 SILICON CHIP magazine
30 CLS: KEY OFF
40 LOCATE 1,26:PRINT"SILICON CHIP LIGHTMETER"
50 T =STICK(1)
60 LOCATE 3,30: PRINT"Light Reading = ";
70 PRINTT
80 GOTO 50
JANUARY 1992
43
Experiments for your games card 0B15 SOCKET
TD GAMES
CARD
PIN 1 0 - - - - - - - - ,
PIN 2
LDR1
DRP12
SECTOR 0
PIN 3. ,-_---,0----
-
PIN 6,0--+--
---,
SECTOR 1
PIN 110--
MINI REED
SWITCH
(DSE CAT P-7 856)
SECTOR 4
RS1
SECTOR 6
RS3
LDR2
DRP12
+ --
Fig.5: these sensors & the
program shown in Listing 3 can
be combined with the games
card to produce a simple 8sector burglar alarm. The reed
switches can be used to monitor
doors & windows, while the
LDRs monitor light level
changes. The thermistor can be
used as a fire monitor.
----,
SECTOR 2
PIN 1 3 n - - - + - - - ~
SECTOR 3
house burglar alarm
TH1
NTC
SECTOR 7
RS4
measurements of light level are necessary.
The beauty of this system is that we
require next to no hardware at all
apart from some wire, an LDR and a
DB15 male plug.
Home burglar alarm
We can now expand on the ideas
presented so far and make an 8-sector
house alarm.
The games card has eight inputs
altogether: the four variable resistor
control inputs plus the four switch
inputs. We haven't used the switch
inputs before but again these are very
easy to use.
The switch inputs can only detect
two states - ie, open and closed - and
so they are ideal for relays, pushbut-
ton switches, reed switches, etc.
The circuit diagram for the house
alarm is shown in Fig.5. It contains three LDRs, four reed relay
switches and one thermistor input, all of which are connected
to a single DB15 connector.
The reed relay switches replace the
joystick buttons and can be used to
monitor windows or doors; one section has a small magnet while the
other section contains the relay. When
the window is lifted, the relay opens
and it's then simply a matter of using
a suitable GWBASIC program to detect
this happening.
The LDRs detect light level changes,
while the thermistor detects changes
in temperature (eg, due to a fire) . Note
that we're not interested in the exact
values here - just detecting a change
is good enough!
Listing 3 shows the BASIC program
for the house alarm. If we go through
it, the program proper begins at line
50. Now if we look at the circuit diagram, we can see that each sensor has
LISTING 3 - HOUSE ALARM PROGRAM
1O REM House Alarm Project
20 REM copyright 1991 SILICON CHIP magazine
30 CLS: KEY OFF: DIM A(?)
40 LOCATE 1,2'7 :PRINT"SILICON CHIP HOUSE ALARM"
50 FOR NUMBER = 0 TO 3
60 VSECJOR(NUMBER)=STICK(NUMBER)
70 SSECTOR(NUMBER)=STRIG(NUMBER*2)
80 IF ABS(OLDVSECTOR(NUMBER)-VSECTOR(NUMBER})>4 THEN
PRINT TIME$": Sector"NUMBER"alarm .... "
90 IF SSECTOR(NUMBER)=-1 T_HEN PRINT TIME$":
Sector"NUMBER+4"alarm .... "
100 OLDVSECTOR(NUMBER)=VSECTOR(NUMBER)
110 NEXT NUMBER
120 GOTO 50
44
SILICON CHIP
been given a sector number.
Lines 60 and 70 allow the computer to check all of the inputs; ie, the
four switches and the four directional
control inputs. The variable VSECTOR
contains the count for each of the four
sensors and these are obtained by using the STICK(x) statement, where "x"
represents the sector number.
GWBASIC also has a very useful function called STRIG which allows us to
check if a particular button has been
pressed at any time since we last
looked at it. If it has, the function
returns a value of " -1 ", otherwise it is
"0". Line 90 checks this and prints
out an alarm message, along with the
time at which it occurred.
STRIG statement
The reason for the STRIG(NUMBER * 2)
argument is that we are only interested in looking at the STRIG(0),
STRIG(2), STRIG(4) and STRIG(6) arguments. If you have a GWBASIC manual,
you may like to look this up for yourself.
Line 80 checks to see if there is a
difference of 5 or more in the last two
readings from the variable sensors. If
there is, it prints the alarm message.
Note that because the sensor resistance values can vary widely, the counter can cycle from 0 to its maximum
count of 255 a number of times. This
can cause false alarm messages in
some circumstances if the counter
stops near its maximum ·or minimum
count. For example, if the counter
stops on 255 on one cycle and on 0
the next, a false alarm message will be
printed even though there is only a
difference of one count.
This problem could be solved with
fancier software.
The program continually loops
through each sensor until we press
"control-break".
Conclusion
Although this has only been a brief
introduction and the examples we
have given are only very simple, it
should whet your appetite and encourage you to experiment. There are
many other possible project ideas if
you are prepared to use more hardware and spend some time writing
the software. It's all up to your imagination.
SC
|