Calculating the linear relationship -21, Calculating the linear relationship – Rockwell Automation 1746-XXXX SLC 500 4-Channel Analog I/O Modules User Manual User Manual

Page 83

Advertising
background image

Publication 1746-UM005B-EN-P - June 2004

Programming Examples 6-21

Calculating the Linear Relationship

Use the following equations to express the linear relationship between
the input value and the resulting scaled value:

Scaled value = (input value x slope) + offset

Slope = (scaled max. - scaled min.) / (input max. - input min.)

(8192 - 0) / (16384 - 3277) = 8192/13107

Offset = scaled min. - (input min. x slope)

0-3277 (8192/13,107) = -2048

Scaled value = (input value x (8192/13017)) - 2048

This equation can be implemented using integer math capabilities of
the SLC 500 system. Three example programs are shown. The first
runs on any SLC 500 processor and the second uses the scaling
instruction available on the SLC 5/02 and later processors. The third
program uses the SCP (scale with parameters) instruction available
only with SLC 5/03 (OS302 or later), SLC 5/04 (OS401 or later), and
SLC 5/05.

In the first example program the analog input value is checked against
the minimum and maximum allowable input values.

If the input is out-of-range, the output value is set to its minimum or
maximum value. If the input value is in range the output value is
determined by scaling the input. To scale an analog input, follow
these steps:

1. Multiply the input by the scaled range

Scale range=(scaled max. - scaled min.).

2. Divide the 32 bit result by the input range

Input range=(input max. - input min.).

3. Add in the offset value (in this case negative). The final value is

then moved to the analog output channel 0.

The multiply operation will generate an overflow bit and minor error
flag whenever the results exceed 16 bits. Since the divide is carried
out on the 32 bit result in the math register, the overflow does not
present a problem. The minor error flag has to be cleared before the
end of the program scan to avoid a system error.

Advertising