Chapter 10 analog i/o – Remote Processing RPC-52 User Manual
Page 29
CHAPTER 10
ANALOG I/O
Page 27
data point.
The pr ogram below take s 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 12 8K 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 n ot 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
reading s at rando m) if unuse d inputs are allowed to floa t.
To minimize noise, connect all unused inputs to ground.
A high impedance is, by definition, sensitive to voltage
pickup. Noise is minimized by running w ires 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 fo r 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 O NTIC K construct can be used to take
data in interv als from 0.0 1 to 327 secon ds. 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 re sistor value in ohms in ser ies with the inpu t.
Vi is the maximum input voltage. W hen the result of
your ca lculation is negative or zer o, a series r esistor is
not necessary.
NOTE: When an input voltage exc eeds + 5 or is less
than 0 volts, other channel values are affected.
Converting analog measureme nts
Inputs can be converted to engineering units of
measurem ent by performing scaling calculations in the
progr am. The A IN func tion retur ns values fr om 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).
E x am p le 1 : T o m ea su r e t he r es ul ts 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: Y ou want to measure a 0 to 200 PSI
pressure transducer w ith 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
Curr ent 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 curr ent loop is converted to 1 - 5V by placing
a 250 ohm resistor across the input of the chan nel to
ground.
Cur rent loop r eadings ar e conver ted to engineer ing units
by performing scaling as described earlier. Since the