
CHAPTER 10 ANALOG I/O
Page 27
data point.
The program below takes about 2. 4 mS per data point.
10 DIM A(254)
20 FOR X=0 TO 254
30 A(X) = AIN(0)
40 NEXT
This next program saves data above MTOP . M TOP was
previously set by CONFIG MTOP to 30000. However,
if you have 128K or m ore RA M, you can P OKE into
segment 1 or higher. It takes approximately 3.6 mS per
data point and is not affected by the mem ory locatio n to
save to.
10 A = 30000
20 FOR X=0 TO 999
30 POKE W0,A,AIN(0)
40 A=A+2
50 NEXT
Data is retrieved using the PEEK W command
Reducing n oise
An input channel can appear to be noisy (change
readings at random) if unuse d inputs are allowed to float.
To minimize noise, connect all unused inputs to ground.
A high impedance is, by definition, sensitive to voltage
pickup. Noise is minimized by running wires away from
AC power lines. A low impedance voltage source helps
to reduce noise pick up. Shielded cable can help reduce
noise from high impedance sources. Make sure the
shield is not used for pow er gr ound. Using the sh ield
for power ground defeats its purpose.
Data logging on a timer tick
Some applications require that data is read at fixed
intervals. The ONTIC K construct can be used to take
data in intervals from 0.0 1 to 327 seconds. T he exam ple
below takes 1 sample per second until 100 samples have
been obtained.
10 DIM A(100)
20 ONTICK 1,500
30 REM THE REST OF YOUR PROGRAM
40 REM CONTINUES
80 GOTO 30
500 A(N) = AIN(3)
510 N=N+1
520 IF N = 100 THEN ONTICK 0,500
530 RETI
MEASURING HIGHER VO LTAGES
Voltages higher than + 5V can be measured by inserting
a series resistor to the input. A resistor can be
connected directly to the STB-20.
The table below shows resistor values for typical input
voltages.
Maximum
Input Voltage Resistor
6 20K
12.5 150K
24 380K
The following formula is used to determine the series
resistance necessar y for a m aximum voltage input:
Rs = Vi * 20000 - 100000
Rs is the resistor value in ohms in ser ies with the input.
Vi is the maximum input voltage. When the result of
your calculation is negative or zer o, a series r esistor is
not necessary.
NOTE: When an input voltage exceeds + 5 or is less
than 0 volts, other channel values are affected.
Converting analog measureme nts
Inputs can be converted to engineering units of
measurement by performing scaling calculations in the
program. The AIN function retur ns values from 0 to
1023. To change these numbers into something more
meaningful, use the following formula:
var = K * AIN(n)
n is the analog channel to read. K is the scaling
constant. K is obtained by dividing the highest number
in the range of units by the maximum AIN count (1023).
Example 1: To measure the results of an A/D
conversion in volts and the voltage range is 0 to 5V,
divided 5 by 1023 to obtain K.
K = 5/1023
K = .004887
Your program could look something like:
1000 C = .004887 * AIN(N)
Example 2: You want to measure a 0 to 200 PSI
pressure transducer with a 0 to + 5V output. Divide 200
by 1023 to obtain the constant K.
K = 200 / 1023
K = .1955
The code can then look like:
1000 B = .1955*AIN(0)
Measuring 4-20 mA current loops
Current loops is a convenient way to transmit a value
and still assure the integrity of the signal. If the line
should break, a 0 volt (or nearly so) is returned.
A 4-20 ma current loop is converted to 1 - 5V by placing
a 250 ohm resistor across the input of the chan nel to
ground.
Current loop r eadings are conver ted to engineer ing units
by performing scaling as described earlier. Since the
Kommentare zu diesen Handbüchern