
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. Differential mode, 0 to + 5V input
CONFIG AIN chan,0,1
chan can be 0, 2, 4, or 6. The input may range from 0
to + 5V. However, if the (-) input is more positive than
the (+ ) input, the result w ill always be zero. The result
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. Differential, ±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 initialized, the AIN function 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 numbers to a voltage, use the
following formulas:
5V Unipolar: A = 0.0 0122 * AIN(chan nel)
±5 Bipolar: A = 0.00244 * AIN (channel) - 5
The AIN function requir es about 1 m s to convert 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 ON TICK 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 interrupts after 100 samples.
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 resistor value in ohms in ser ies with the input.
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.
Comentários a estes Manuais