Trying to enhance my Siemens SCL abilities

You are a freak! Haven't messed with indexing before or much with Arrays so this is all very cool stuff!!!!

This will keep me busy for awhile :)

One more quick one and I'll leave you guys alone I promise

I have approximately 6 linear equations that I need to solve for, heres my terrible interpretation
EQ6_Calc := (AverageVal < 5.000000e+001 AND AverageVal > 1.600000e+001) -5.000000e-001 * AverageVal + 3.800000e+001 // If Cylinder Position is less than 50% and greater than 16%, use equation #6 ( Y = -.5*x+38) X = Average Cyl
EQ5_Calc := (AverageVal > -2.000000e+000 AND AverageVal < 1.600000e+001) -2.222000e-001 * AverageVal + 3.355600e+001 // If Cylinder Position is greater than -2 and less than 16%, use equation #5 ( Y = -.2222*x+33.556) X = Average Cyl
EQ4_Calc := (AverageVal > -2.600000e+001 AND AverageVal > -2.000000e+000) -1.000000e+000 * AverageVal + 3.200000e+001 // If Cylinder Position is greater than -26 and less than -2, use equation #4 ( Y = -1*x+32) X = Average Cyl
Then I want to write these values to an analog output, (depending which one is active) known as EDS_SP. These calculations required over 25 networks in LAD, amazing how much simplier doing math is in SCL. My syntax is terrible!
 
Try this (compiles but not tested)

Code:
FUNCTION_BLOCK FB1508
VAR_INPUT
Cyl1 : REAL;
Cyl2 : REAL;
Cyl3 : REAL;
Cyl4 : REAL;
Cyl5 : REAL;
Cyl6 : REAL;
Offline1:BOOL;
Offline2:BOOL;
Offline3:BOOL;
Offline4:BOOL;
Offline5:BOOL;
Offline6:BOOL;
END_VAR
VAR_OUTPUT
AverageVal : REAL;
LinearisedOP:REAL;
END_VAR
VAR
Data:ARRAY[0..15] OF BOOL;
iIndex AT Data:INT;
rUpperLimit:ARRAY[1..6] OF REAL:=50.0, 16.0, -2.0, -22.0, -30.0, -40.0;
rLowerLimit:ARRAY[1..6] OF REAL:=16.0, -2.0, -22.0,-30.0, -40.0, -50.0;
rM:ARRAY[1..6] OF REAL:= -0.5, -0.2222, -1.0, -1.5, -2.0, -3.0;
rC:ARRAY[1..6] OF REAL:= 38.0,  33.556, 32.0, 30.0, 28.0, 27.0;
i:INT;
k:INT;    
END_VAR    
BEGIN
Data[8]:=OffLine1;
Data[9]:=OffLine2;
Data[10]:=OffLine3;
Data[11]:=OffLine4;
Data[12]:=OffLine5;
Data[13]:=OffLine6;
CASE iIndex OF
    1:  Cyl1:=Cyl2;
    2:  Cyl2:=Cyl1;
    4:  Cyl3:=Cyl1;
    8:  Cyl4:=Cyl1;
    16: Cyl5:=Cyl1;
    32: Cyl6:=Cyl1;
    3:  Cyl1:=Cyl3;Cyl2:=Cyl3;
    5:  Cyl1:=Cyl2;Cyl3:=Cyl2;
    9:  Cyl1:=Cyl2;Cyl4:=Cyl2;
    17: Cyl1:=Cyl2;Cyl5:=Cyl2;
    33: Cyl1:=Cyl2;Cyl6:=Cyl2;
    6:  Cyl2:=Cyl1;Cyl3:=Cyl1;
    10: Cyl2:=Cyl1;Cyl4:=Cyl1;
    18: Cyl2:=Cyl1;Cyl5:=Cyl1;
    34: Cyl2:=Cyl1;Cyl6:=Cyl1;
    12: Cyl3:=Cyl1;Cyl4:=Cyl1;
    20: Cyl3:=Cyl1;Cyl5:=Cyl1;
    36: Cyl3:=Cyl1;Cyl6:=Cyl1;
    24: Cyl4:=Cyl1;Cyl5:=Cyl1;
    40: Cyl4:=Cyl1;Cyl6:=Cyl1;
    48: Cyl5:=Cyl1;Cyl6:=Cyl1;
END_CASE;    
AverageVal := (Cyl1 + Cyl2 + Cyl3 + Cyl4 + Cyl5 + Cyl6
              - MIN(In1:=Cyl1, In2:=Cyl2,In3:=Cyl3,In4:=Cyl4,In5:=Cyl5,In6:=Cyl6)
              - MAX(In1:=Cyl1, In2:=Cyl2,In3:=Cyl3,In4:=Cyl4,In5:=Cyl5,In6:=Cyl6))/4.0;
k:=1; //default value
FOR i:=1 TO 6 DO
    IF rUpperLimit[i]<= AverageVal AND AverageVal <= rLowerLimit[i] THEN k:=i;  END_IF;        
END_FOR;                  
LinearisedOP := (AverageVal * rM[i]) + rc[i];  //Y = mx+C        
END_FUNCTION_BLOCK:
 
Thanks a bunch for your help!!!

The last one you posted - there is an error I can't seem to figure out. I is somehow 7 and is throwing everything off. I think I see how it works.
k:=1; //default value
FOR i:=1 TO 6 DO
IF rUpperLimit<= AverageVal AND AverageVal <= rLowerLimit THEN k:=i; END_IF;
If I = 7, it doesn't know what to do because we specify 1 to 6. Also, the array with the different limits and M & B is 1 to 6 and it won't know what values to use for that either.

My ladder portion calculates the SP to be 33.59%ish with an average cylinder value of .2%ish, using equation #5 (Y= -.2222*X+33.556) while the SCL version is -7.42ish.
K still contains the default value of 1, while I has a 7 in it, which tells me that the comparisons must not be working because K := I if satisfied
 
Last edited:
Typos. k is the remembered value to use.

Code:
IF rUpperLimit[i][COLOR=Red][B]>[/B][/COLOR]= AverageVal AND AverageVal[B] [COLOR=Red]>[/COLOR][/B]= rLowerLimit[i]

and

LinearisedOP := (AverageVal * rM[[B]k[/B]]) + rc[[B]k[/B]];  //Y = mx+C
 
Last edited:
I feel pretty good, I was able to find the compare errors

This is a very neat way to program. I still have lots to learn though

Thanks again!!!!
 
min_max@scl

Just to finish the unfinished task of post No. 2.☯

Code:
FUNCTION FC25 : void

VAR_input
Ai:ARRAY[1..3] OF INT;
END_VAR

VAR_output
Ai_max:INT;
Ai_min:INT;
END_VAR




VAR_TEMP
    x:INT;
    y:INT;
    konst:int;
   END_VAR

BEGIN
konst:=3;
//calculation for the max value
x:=1;
y:=2;
WHILE y<=konst DO
   IF Ai[x]> Ai[y] THEN
    y:=y+1;
   ELSE 
     x:=y;
     y:=y+1;
   END_IF;
END_WHILE;
  Ai_max:=Ai[x];
       
//calculation for the min value
x:=1;
y:=2;
WHILE y<=konst DO
   IF Ai[x]< Ai[y] THEN
    y:=y+1;
   ELSE 
     x:=y;
     y:=y+1;
   END_IF;
END_WHILE;
     Ai_min:=Ai[x]; 


END_FUNCTION
 
Truth table data:
Code:
Cases for One of 6 Disabled
6 5 4 3 2 1
===========
0 0 0 0 0 1 = 1
0 0 0 0 1 0 = 2
0 0 0 1 0 0 = 4
0 0 1 0 0 0 = 8
0 1 0 0 0 0 = 16
1 0 0 0 0 0 = 32
Cases for Two of 6 disabled
6 5 4 3 2 1
===========
0 0 0 0 1 1 = 3
0 0 0 1 0 1 = 5
0 0 1 0 0 1 = 9
0 1 0 0 0 1 = 17
1 0 0 0 0 1 = 33
0 0 0 1 1 0 = 6
0 0 1 0 1 0 = 10
0 1 0 0 1 0 = 18
1 0 0 0 1 0 = 34
0 0 1 1 0 0 = 12
0 1 0 1 0 0 = 20
1 0 0 1 0 0 = 36
0 1 1 0 0 0 = 24
1 0 1 0 0 0 = 40
1 1 0 0 0 0 = 48
Cases for one of 8 disabled
8 7 6 5 4 3 2 1 
===============
0 0 0 0 0 0 0 1 = 1
0 0 0 0 0 0 1 0 = 2
0 0 0 0 0 1 0 0 = 4
0 0 0 0 1 0 0 0 = 8
0 0 0 1 0 0 0 0 = 16
0 0 1 0 0 0 0 0 = 32
0 1 0 0 0 0 0 0 = 64
1 0 0 0 0 0 0 0 = 128
Cases for two of 8 disabled
8 7 6 5 4 3 2 1
===============
0 0 0 0 0 0 1 1 = 3
0 0 0 0 0 1 0 1 = 5
0 0 0 0 1 0 0 1 = 9
0 0 0 1 0 0 0 1 = 17
0 0 1 0 0 0 0 1 = 33
0 1 0 0 0 0 0 1 = 65
1 0 0 0 0 0 0 1 = 129
0 0 0 0 0 1 1 0 = 6
0 0 0 0 1 0 1 0 = 10
etc...
 

Similar Topics

I can't seem to get the Panel View Plus 7 standard edition to downgrade to V_11, when I check the AB downloads and compatibility websites for this...
Replies
1
Views
141
Hi I used to be able to launch PLCsim without any problem. Now it tells me " STEP 7 Professional Licence is required to simulate this PLC"...
Replies
15
Views
537
Hello! When trying to load the hardware configuration I get error 0050-133 2 2458, check the diagnostic buffer. When checking the buffer, it says...
Replies
4
Views
192
We have a keg check weigher that that lost a fight to a forklift. The scale was previously a Systec IT3000, which was the only PROFIBUS slave...
Replies
5
Views
678
Back
Top Bottom