Understanding Simatic S7-SCL code

arocon

Member
Join Date
Oct 2006
Location
Dubai
Posts
171
Could anybody please tell me what algorithm use following S7-SCL code. I understand it is a value as input then making output. But i want to know what formula it has been used .

FUNCTION FC572 : VOID

TITLE = 'Lookup'

NAME : Lookup

// Block Parameters
VAR_INPUT
// Input Parameters
Input : REAL;
X1 : REAL;
Y1 : REAL;
X2 : REAL;
Y2 : REAL;
X3 : REAL;
Y3 : REAL;
X4 : REAL;
Y4 : REAL;
X5 : REAL;
Y5 : REAL;
X6 : REAL;
Y6 : REAL;
X7 : REAL;
Y7 : REAL;
X8 : REAL;
Y8 : REAL;
END_VAR

VAR_OUTPUT
// Output Parameters
Output : REAL;
Lower_Limit : BOOL;
Upper_Limit : BOOL;
END_VAR

VAR_TEMP

END_VAR

// Statement Section

IF Input <= X1 THEN
Output := Y1;
Lower_Limit := TRUE;
Upper_Limit := FALSE;
RETURN;
END_IF;

IF Input <= X2 THEN
Output := Y1 + ((Input - X1) / (X2 - X1) * (Y2 - Y1));
Lower_Limit := FALSE;
Upper_Limit := FALSE;
RETURN;
END_IF;

IF Input <= X3 THEN
Output := Y2 + ((Input - X2) / (X3 - X2) * (Y3 - Y2));
Lower_Limit := FALSE;
Upper_Limit := FALSE;
RETURN;
END_IF;

IF Input <= X4 THEN
Output := Y3 + ((Input - X3) / (X4 - X3) * (Y4 - Y3));
Lower_Limit := FALSE;
Upper_Limit := FALSE;
RETURN;
END_IF;

IF Input <= X5 THEN
Output := Y4 + ((Input - X4) / (X5 - X4) * (Y5 - Y4));
Lower_Limit := FALSE;
Upper_Limit := FALSE;
RETURN;
END_IF;

IF Input <= X6 THEN
Output := Y5 + ((Input - X5) / (X6 - X5) * (Y6 - Y5));
Lower_Limit := FALSE;
Upper_Limit := FALSE;
RETURN;
END_IF;

IF Input <= X7 THEN
Output := Y6 + ((Input - X6) / (X7 - X6) * (Y7 - Y6));
Lower_Limit := FALSE;
Upper_Limit := FALSE;
RETURN;
END_IF;

IF Input < X8 THEN
Output := Y7 + ((Input - X7) / (X8 - X7) * (Y8 - Y7));
Lower_Limit := FALSE;
Upper_Limit := FALSE;
RETURN;
END_IF;

Output := Y8;
Lower_Limit := FALSE;
Upper_Limit := TRUE;


END_FUNCTION

Thank you.
 
The code is rather clunky and would have been better written as a loop but it interpolates between points.

The code scans down the list of Xn values until it finds an Xn entry that is less than Input. By subtracting Xn from Input you are left with a value of X in excess of Xn this is then divided be the value of Xn+1 - Xn and then multiplied by Yn+1 - Yn. This partial result is then summed with Xn to provide a result.

I wrote a similar block that reads in an array of XY points to provide a non-linear interpolation of a linear function. I also wrote a complimentary inverse function that allows you to do a YX lookup on the same data.

Nick
 

Similar Topics

I am using Allen Bradley PLC for Ethernet/IP communication. I send any explicit msg request (Get attribute or Set attribute), I observed packet...
Replies
0
Views
70
Took a new job and the controls schemes are fairly old and I'm used to Allen Bradley and Siemens. I'm looking to replace a pair of Superior...
Replies
1
Views
105
Hello Team, I am desperate for some help with an assessment I have as part of a Level 3 general engineering course. I am in a role that is much...
Replies
9
Views
345
Good day is there somewhere i can see the situation and compatibility regarding different firmware revisions. I have a 2711-K5A5, series H and...
Replies
4
Views
212
Good Evening , I should know more about Solid State Relays . I have a system with 8) 120 vac Vibrators . These Solid State Relays have...
Replies
24
Views
2,052
Back
Top Bottom