beautypg.com

Analog i/o chapter 10 – Remote Processing RPC-52 User Manual

Page 30

background image

ANALOG I/O

CHAPTER 10

Page 28

measur ement r ange is 1 to 5V , the count ran ge is
reduced by 20% to 818. T he constant K is computed as:

K = 5/818
K = .006188

The abo ve equation is as suming the 4-20 ma loop is
returning a value that represents a range of 0 to 5V. As
i n t he p re v io u s e x am p le , i f p r es su r e w e r e m e as ur e d:

K = 200/818
K = .24449

There is one addition factor. Since the lowest value read
is 1 V, this offset is subtracted from all readings. A 1 V
offset is 1/5 of 1023 counts, or 205. The program line
then becomes:

200 A=.006112*(AIN(N)-205)

Note that if the current loop line breaks, a negative value
is returned.

CALIBRATION

The A /D comes fa ctory ca librated for a 0 to 5V inpu t.
This span can be changed by adjusting R1. You can
adjust the span to 5.12V. T his is useful when the input
is 0 - 5V and you want to know when the input is over-
range.

To calibrate or adjust the voltage reference:

1.

Connect the voltmeter ground to any even
numbered pin on J1. Make sure there ar e no
other connections to the analog ground.

2.

Connect the voltmeter ' + ' lead to U5, pin 6.

3.

Adjust R1 for 5.00 VDC or other voltage as
desired. Do not exceed 5.2 V.

ANALOG OUTPUT

The tw o analog outpu t channels shar e the PW M outpu ts
at the digital port. Analog output 0 is controlled by
PWM 0 and output 1 by PWM 1. When a PW M output
is used by an opto channel, it should not be used as an
analog outpu t.

To make sure PWM is not used by an opto channel, set
the following jumper s:

W6[1-2]

P W M 0

W7[1-2]

P W M 1

One channel may be used as a PW M output while the
other is used as an analog output. Both outputs are
independently programmable as to duty cycle but not
frequency.

Analog output is generated from the PWM outputs by
simply plac ing a low pas s filter in the outp ut. T he result
is an output with a 10K series resistance. The filter
capacitor is 10 Mfd . T hese values p rovide r easonable

ripple filtering and response over the PWM ' s output
frequency.

T h e 10 K ou tp u t r e si st a nc e m ay b e h ig h fo r so m e
devices. Check the device you are interfacing to. If the
impedance is less than 1 Meg ohm, and certainly 100K,
then the accuracy and maximum output will be affected.
If the full 5 volt range is not necessary, then the lower
impedance may not be a problem. The output may be
buffered using an external OP amp.

To m ake sure the output voltage is at the desire d level,
the output can be connected to the analog input. Then,
by reading the voltage the output can be adjusted to the
desired level. The m aximum output voltage will be
reduced when using this method, however.

The outpu t voltage is pro portional to th e PW M cha nnel' s
duty cycle. Thus, the output voltage will change in steps
of 1/25 5, o r appr oximately 20 mv/ step. This effec tively
makes the analog output act like an 8 bit D/A converter.

The accuracy of the output depends upon the accuracy of
the + 5 V supply. When the supply is exactly 5 volts,
the output will go nearly to + 5 and ground at the
extrem e range s. W hen the output is loa ded, + 5 volts
may not be reached. With the output loaded at 100K,
output voltage is reduced by about 10%.

Programming

The PWM statement is used to set the output voltage.
CON FIG PW M can be used to set the output and
frequency on power up.

The output voltage is proportional to the duty cycle:

Vo = Vcc - (Vcc * duty cycle / 255)

For exam ple, a duty cycle of 80 produces an output of
3.43 volts. This assumes the power supply (Vcc) was
exactly 5 volts and the output was not loaded. The
following example r amps both outputs:

100 FOR N=0 TO 255
110 PWM 0,N
120 PWM 1,N
130 NEXT
140 GOTO 100

The outputs will ramp from + 5 volts to ground then
return to + 5V to repeat the cycle.