Chapter 8 analog i/o – Remote Processing RPC-2350 User Manual

Page 45

Advertising
background image

CHAPTER 8

ANALOG I/O

8-3

The input range is -2.5V to + 2.5V. The result from an
AIN function is 0 for -2.500V , 2048 for 0. 000V, and
4095 for + 2.4998V.

4. D ifferential, ±2.5V input

CONFIG AIN chan,0,0

The input r anges fr om -2. 5V to + 2.5 V. The r esult is
the difference of the two voltages. AIN will return 0
for a difference of -2.500V , 2048 for a difference of
0.000V, and 4095 for a difference of 2.498V.

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)

±2.5

Bipolar:

A = 0.00244 * AIN (channel) - 5

The A IN func tion requir es about 500 m icro-Sec onds to
conver t a channel of d ata. Additional tim e is needed to
store the data. Saving data to a single dimension array
takes 500 m icro-sec onds longer than saving to a sim ple
variable.

Data logging 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

0-5V range

Rs = Vi * 40,000 - 100, 000

0-2.5V r ange

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: When an input voltage exceeds its voltage

range, other channels values are affected.

The 100K ohm re sistor is R15. This is a 2% part. Y ou
may w ant to add a tr im res istor in ser ies with a fixed to
obtain higher accuracy.

Since input impedance is higher , noise incr eases. A
capacitor at the appropriate channel at W13 will reduce
noise.

CONVERTING ANALOG
MEASUREMENTS TO REAL WORLD
UNITS

Inputs are converted to engineering units of measurement
by performing scaling calculations in the program. The
AIN function returns values from 0 to 4095. To change
these numbers into something more m eaningful, use the
following formula:

var = K * AI N (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 (4095).
var result is in real wor ld units (PSI, p ounds, inch es,
volts, etc.)

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,

Advertising