L INEAR I N T E R P O L AT I O N OF N ONLINEAR I NPUTS

L INEAR I N T E R P O L AT I O N OF N ONLINEAR I NPUTS

In some PLC applications, the analog input signal received does not have a linear relationship with the signal being measured. That is, the ratio of change in the measurement variable is not the same throughout the measure-

ment range. For example, a pressure transducer measuring hydraulic pressure (see Figure 11-61) may not provide a signal that is a linear representation of psi changes versus voltage changes (and therefore input

counts). Sometimes the system that is being controlled creates these nonlinearities. The use of look-up tables and linear interpolation methods based on premeasured values can circumvent nonlinearity problems. In

linear interpolation, the PLC stores known measured values in a table and then refers to this table during the reading of every measurement (analog counts) to determine the value of the variable (e.g., psi). It calculates this

value by interpolating between the known measured values of the variable below and above the actual analog count reading. The more known values in the table, the more accurate the interpolated values will be.

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC System Programming C HAPTER 3 Programming

and Implementation 11

Pressure Variable (psi)

Actual known value measurements

psi B Interpolated value of psi

psi A

Analog

Count A

Count B

Counts

Measurement

Figure 11-61. Nonlinear input signals from a pressure transducer.

To provide an example of this type of application, we will use a system with

a pressure transducer that provides a 0 to +10 VDC output. The range of the pressure measurement is from 0 to 1000 psi. Measurement tests have shown that the relationship associated with the transducer’s measurement is nonlin- ear. Figure 11-62 illustrates the difference between a linear curve and the actual nonlinear measurements. The analog input module transforms the 0 to

10 VDC signal into counts ranging from 0 to +4095. Table 11-28 shows the test counts for different psi pressure values.

Let’s assume that the control algorithm requires the input measurement to

be converted to engineering units (in this case, psi). Since we cannot perform this conversion based on a linear equation, we must obtain the psi values by estimating a pressure according to an input count reading. The PLC performs this linear interpolation by looking through tables (groups of contiguous registers) for a psi value equivalent to the counts. The two tables the PLC uses are the psi measurement table and its corresponding count value table. The psi table starts at register 3100, and the count table starts at register 3000. Table 11-29 shows these two tables, along with the corresponding pointer values. The pointer (register 4000) points at a register in the table according to a specified offset (table-to-register instruction). For instance, if the pointer value is 3 (reg 4000 = 3), then it points to psi register 3102 and count register 3002. The contents of the pointer register are in decimal, while the other registers are in octal. Figure 11-63 shows the flowchart for the look- up and interpolation procedures.

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC System Programming C HAPTER 3 Programming

and Implementation 11

Y psi = 1000 X Counts 4095

Figure 11-62. (a) Linear behavior and (b) actual nonlinear measurements.

Table 11-28. Sample psi measurements and corresponding counts.

Table 11-29. Look-up tables for psi and count values.

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC System Programming C HAPTER 3 Programming

and Implementation 11

START

START

Move value from

table to register Read

analog input

Is

counts

table count

Yes Increment pointer

value > input

counts?

P for next table value

Is input count Yes

Then psi is

No

equal to 0

Save pointer (P)

position and

No

decrement for low

value (P–1) Set pointer P to

second table

Move table to

location

registers for P and

P–1 index for psi and counts

Go to subroutine to look-up table

and interpolate

Perform math interpolation and store in result register

END Return

(a)

(b)

Figure 11-63. (a) Main program look-up procedure and (b) interpolation subroutine.

Table 11-30 shows the register assignment table for this example, and Table 11-31 shows the internal output assignment. The analog input module, with address 070, is the only real input.

Table 11-30. Register assignment.

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC System Programming C HAPTER 3 Programming

and Implementation 11

Table 11-31. Internal output assignment.

Figure 11-64 shows the method used to interpolate psi values based on the contents of each register used. The PLC program shown in Figure 11-65 implements the linear interpolation by finding the high and low counts and psi values. Using the two pointers, the PLC obtains the high and low values for the counts and psi through table-to-register instructions. The PLC pro- gram compares its current analog counts with the count values in the table registers to find a table location with a greater value. This comparison starts with the lowest count values in the table. If the actual value (analog counts) is more than the value pointed to by the pointer, the PLC increments the pointer (adds 1) and tests a new table value. Once the program finds a register in the table that contains a value greater than the analog reading, it stores the pointer value associated with this register in register 4050, thus pointing to the register at pointer P in Figure 11-64. Then, the value contained in register 4050 is decreased by one and stored in register 4000 to point to the register at point P – 1 in Figure 11-64. These two registers (4000 and 4050) point to the low psi/low counts and high psi/high counts, respectively, which will be used to complete the interpolation.

In the software program presented, we have considered that the actual count value may be 0 counts. When the count value is 0, the equivalent psi is 0 and the program does not perform the subroutine shown in Figure 11-66. If it did perform the subroutine, the program would enter into a loop error.

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC System Programming C HAPTER 3 Programming

and Implementation 11

(psi)

psi

Actual Counts – Low Counts = Computed psi – Low psi

Register

High Counts – Low Counts

High psi – Low psi

P 4450 points to high psi

4150 holds computed psi P–1

40 points to low psi

Counts

High Counts Counts Counts

Low

Actual

4550 Computed psi = (Actual Counts – Low Counts)(High psi – Low psi) + Low psi

Count Register

High Counts – Low Counts

Figure 11-64. Interpolation method.

psi read

XFER IN

Slot 7 Rack 0 Reg 4100 Length 1

psi read

CMP 0 counts

psi = 0 counts

Reg K 0

psi = 0 counts

Reg K0 Reg 4150 Length 1

psi = 0 counts

Pointer P – 1 = 2

Reg K2 Reg 4000 Length 1

psi = 0 counts

Sub interpolation

GO SUB 10

Figure 11-65. Main program.

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC System Programming C HAPTER 3 Programming

and Implementation 11

Reg 3000 Length 1

4000 Reg 40 Get High Psi

CMP

Done 1101

MOVE for P TBL REG

High Cts ≥ input Cts

Pointer 4050 Reg 4450

Input Cts – Low Cts

ADD

Inc Pointer P – 1

Reg 4600 High Psi – Low Psi

SUB 1206

High Cts ≥ Input Cts

Found High Psi

Reg 4450

Go To 1200

– Reg 40 = Reg 4601

Numerator Multiplication

High Cts ≥ Input Cts

Reg 4601 x Reg 4600 =

MOVE

Store High Pointer P

Reg 4602

Scale 0 High Cts – Low Cts

Reg 4000

SUB 1210

Reg 4050 Length 1

Reg 4550 – Reg 4500 = Reg 4603

Numerator

Store Pointer P – 1

Reg 4604 Scale 0

Result + Low Cts

(continued at right) Figure 11-66. Interpolation subroutine.

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC System Programming C HAPTER 3 Programming

and Implementation 11