Perform linear interpolation of discrete values
This FP instruction renders the value y at position x by performing a linear interpolation based on the neighboring reference points Pw(xw, yw) and Pw+1(xw+1, yw+1). In this example, w is the nearest reference point whose x value is smaller than the input value s1_x, i.e. the function connects the individual reference points in series and renders the output value d_y based on the input value s1_x.
Input
Input value
On 16-bit PLC types: (INT, DINT, REAL)
On 32-bit PLC types: (INT, DINT, UINT, UDINT, REAL, LREAL)
Apply the first element of the user-defined DUT, i.e. the number of xy values, to this input. See description of DUT structure below.
Output
Result
On 16-bit PLC types: (INT, DINT, REAL)
On 32-bit PLC types: (INT, DINT, UINT, UDINT, REAL, LREAL)
Application examples:
Linearizing measured values, e.g. with non-linear sensors
Rendering a heater’s flow temperature y in relation to the outside temperature x
if the area specified using the index modifier exceeds the limit.
if the number of reference points is outside the range of 2–256.
if s2_xyData is out of range.
if the x values of the reference points are not in ascending order.
if the area specified using the index modifier exceeds the limit.
if the number of reference points is outside the range of 2–256.
if s2_xyData is out of range.
if the x values of the reference points are not in ascending order.
If the input value x is smaller than the x-coordinate of the first reference point (P1: x< x1), the output y is set to the first reference point’s y-coordinate (output y = y1, horizontal dashed line in the graph’s upper left corner).
If the input value x is greater than the x-coordinate of the last reference point (P8: x > x8), the output y is set to the last reference point’s y-coordinate (output y = y8, horizontal dashed line in the graphic’s upper right corner).
DUT for the xy value pairs (reference points P1, P2, ...):
The reference points (P1, P2, ...) are copied to the function via an DUT-type variable that contains the number of reference points and the xy value pairs (number; x1, x2, ...; y1, y2; ...).
Element: Variable of the data type ARRAY[1..z] OF INT (on 16-bit PLC types: INT, DINT, REAL; on 32-bit PLC types: (INT, DINT, UINT, UDINT, REAL)) or ARRAY[0..z-1] of INT (on 16-bit PLC types: INT, DINT, REAL; on 32-bit PLC types: (INT, DINT, UINT, UDINT, REAL)) that contains the x values. Here z represents the place marker for the number of reference points (see entry 1).
Element: Variable of the data type ARRAY[1..z] OF INT (on 16-bit PLC types: INT, DINT, REAL; on 32-bit PLC types: (INT, DINT, UINT, UDINT, REAL)) or ARRAY[0..z-1] of INT (on 16-bit PLC types: INT, DINT, REAL; on 32-bit PLC types: (INT, DINT, UINT, UDINT, REAL)) that contains the y values. Here z represents the place marker for the number of reference points (see entry 1).
FP_SCALE supports the following data types:
On 16-bit PLC types (FP-Sigma, FP-X): INT, DINT, REAL
On 32-bit PLC types (FP7): INT, DINT, REAL, UINT, UDINT
Corresponding F instructions: F282_SCAL, F283_DSCAL, F354_FSCAL
With a Data Unit Type (DUT) you can define a data unit type that is composed of other data types. A DUT is first defined in the DUT pool and then processed like the standard data types (BOOL, INT, etc.) in the list of global variables or the POU header.
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
bStart: BOOL:=FALSE;
iInput: INT:=50;
xy_data: xy_data_dut;
iScaledOutput: INT:=0;
@'': @'';
END_VAR
When the variable bStart is set to TRUE, the function is carried out.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_CONTACT,,bStart,4,2,6,4,);
B(B_F,FP_SCALE!,,17,1,25,6,,?DEN?Ds1_x?Ds2_xyData?AENO?Cd_y);
B(B_VARIN,,iInput,15,3,17,5,);
B(B_VAROUT,,iScaledOutput,25,3,27,5,);
B(B_VARIN,,xy_data.iNumberOfValues,15,4,17,6,);
L(1,0,1,6);
L(1,3,4,3);
L(6,3,17,3);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF (bStart) then
FP_SCALE(s1_x := iInput,
s2_xyData := xy_data.iNumberOfValues,
d_y => iScaledOutput);
END_IF;