Chapter 8 analog i/o, Acquiring analog data, Measuring higher voltages – Remote Processing RPC-2300 User Manual
Page 25

CHAPTER 8
ANALOG I/O
RPC-2300
Page 23
channel 0 would use J7 pin numbers 1 and 3.
Single ended inputs 2-7 are available.
input
specifies single ended or differential. 0 =
differential, 1 = single ended.
range
is voltage input. 0 = ±5V and 1 = 0 to + 5V.
Below are sample syntaxes for the CON FIG AIN
command:
1. Single ended mode, 0-5V input
CONFIG AIN chan,1,1
The input voltage is from 0 to 5 volts. The result from
the AIN function is 0 for 0.000V and 4095 for
+ 4.9988V.
chan
may range from 0 to 7, if no other
channels are used for differential inputs.
2. D ifferential mode, 0 to + 5V input
CONFIG AIN chan,0,1
chan
c a n b e 0, 2 , 4 , o r 6. T h e in p ut m ay r a ng e fr o m 0
to + 5V. H owever, if the (-) input is more positive than
the (+ ) input, the result w ill always be ze ro. The r esult
from the AIN function is 0 for a difference of 0.000V
and 4095 for a difference of 4.9988V.
3. Single ended, ±5V input
CONFIG AIN chan,1,0
The input ranges from -5V to + 5V. The r esult from an
AIN function is 0 for -5.000V , 2048 for 0. 000V, and
4095 for + 4.9988V.
4. D ifferential, ±5V input
CONFIG AIN chan,0,0
The input ranges from -5V to + 5V. T he result is the
difference of the two voltages. AIN will return 0 for a
difference of -5.000V, 2048 for a difference of 0.000V,
and 4095 for a difference of 4.9988V.
ACQUIRING ANALOG DATA
Once the analog input is initialize d, the AIN fu nction is
used to acquire data. The syntax is:
S = AIN(ch)
Where:
ch
= channel number, 0-7
This command reads the voltage and returns a number
from 0 to 4095 to the variable S. The number returned
corresponds to the voltage input and the
type
the channel
was configured for.
To convert the returned num bers to a voltage, use the
following form ulas:
5V Unipolar:
A = 0.0 0122 * AI N(chan nel)
±5
Bipolar:
A = 0.00244 * AIN (channel) - 5
The A IN func tion requir es about 1 m s to conver t a
channel of data. Additional time is needed to store the
data. Saving data to a single dimension array takes 500
micro-seconds longer than saving to a simple variable.
Datalogging on a timer tick
Some application require that data be taken at fixed
intervals. The O N TIC K construct can be used to take
data in intervals from 0.01 to 655. 35 seconds. The
program below takes 100 samples on 2 channels every
10 seconds.
10 DIM F(100,2)
20 ON TICK 10 GOSUB 50
30 ..this is a dummy loop
40 GOTO 30
50 F(I,0) = AIN(0)
60 F(I,1) = AIN(1)
70 INC I
80 IF I = 100 THEN ON TICK 10 GOSUB
90 RETURN
Line 80 shuts off interr upts after 100 sam ples.
MEASURING HIGHER VOLTAGES
Input voltages higher than 5V are measured by placing a
resistor in series with the input. Use the following
formula to determine the required series resistance:
Rs = Vi * 20,000 - 100, 000
Rs is the re sistor value in ohms in ser ies with the inpu t.
Vi is the maximum input voltage. If the result of your
calculation is 0 or negative, a series resistor is not
necessary.
NOTE: If an input voltage exceeds + 5.0V or is less
than -5.0V, other channels will be in error.