Specifically that the function you are looking for is: FB_CTRL_LIN_INTERPOLATION
However this is a paid library, so I would suggest that if this is a one-off or simple project it may be relevant to write your own version.
Below is a simple version of an interpolation program I have used before, however I would recommend that rather than just copy/pasting you examine:
- What your code should do if target value is above/below range?
- Does you code need to handle misordered arrays?
- How do you catch div/0 errors?
Raw : REAL;
PairCnt : INT := 0;
PairArr : ARRAY [1..MAX_PAIRS, 0..1] OF REAL;
i : UDINT;
Out : REAL;
// Default value just in case no pairs exist
Scale := 0;
FOR i := 1 TO ( MAX_PAIRS - 1 ) DO (* -1 for looking at i+1 *)
IF Raw > PairArr[ i, 0 ] AND_THEN
Raw < PairArr[( i+1 ), 0 ] THEN
Out := ((( Raw - PairArr[ i, 0 ])/( PairArr[( i+1 ), 0 ] - PairArr[ i, 0 ])) * (PairArr[( i+1 ), 1 ] - PairArr[ i, 1 ])) + PairArr[ i, 1 ];
ELSE
Out := PairArr[( i+1 ), 1 ];
END_IF
END_FOR