Confuse with For Statement in Siemens SCL

MOeZ

Lifetime Supporting Member
Join Date
Nov 2009
Location
singapore
Posts
101
Hello all,

I am Confusing with below equation. i express with blue color .Please kindly explain me below FOR ..., Where can i find good SCL manual for beginners???

y_index : INT := 10;
i : INT;

FOR i := 1 TO 32 DO
IF M(y_index,i) = TRUE; :unsure: when i = y_index
THEN Total := Total + 1;:unsure: Total := Total + 1???
END_IF;
END_FOR;

Many Thanks
 
SCL source code of IF block

Post the SCL source code for the FB as an attachment.

VAR_INPUT
Start : BOOL;
Manual : BOOL;
ActVal : INT;
END_VAR
VAR
Manual_FM : BOOL;
over : BOOL;
under : BOOL;
equal_to : BOOL;
Setpoint_man : INT := 1000;
Setpoint : INT;
Deviation : INT;
y_index : INT := 12;
Total : INT;
END_VAR

VAR_TEMP i : INT; END_VAR

BEGIN
//Simple IF branch
IF Start THEN Setpoint := 1200; END_IF;
IF Manual THEN
Setpoint := Setpoint_man;
Q4.0 := TRUE;
END_IF;

//Branch with THEN...ELSE
IF ActVal > Setpoint
THEN Deviation := ActVal - Setpoint;
ELSE Deviation := Setpoint - ActVal;
END_IF;


//Branch with ELSIF
IF ActVal > Setpoint
THEN over := TRUE;
under := FALSE;
equal_to := FALSE;
ELSIF ActVal < Setpoint
THEN under := TRUE;
over := FALSE;
equal_to := FALSE;
ELSE equal_to := TRUE;
over := FALSE;
under := FALSE;
END_IF;


//Edge evalaution (rising edge)
IF Manual AND NOT Manual_FM
THEN (*rising edge*);
END_IF;
Manual_FM := Manual; //Correct edge memory bit

//Counting bits set to "1"
Total := 0;
FOR i:=1 TO 32 DO
IF M[y_index,i] = TRUE
THEN Total := Total + 1;
END_IF;
END_FOR;

END_FUNCTION_BLOCK
 
After read some manual, my understanding is
IF M[y_index,i] = TRUE
// y_index = byte address
// i = bit address
// so If Memory Bit M10.1 to 32 is TRUE as y_index is start from 10
// Total = Total + 1

Am i Correct?

Thanks!
 
Your first post used round brackets, your second post used square brackets ?? Cut and paste is your friend.

M[BYTENO, BITNO] accesses Marker M bits.
 
Your first post used round brackets, your second post used square brackets ?? Cut and paste is your friend.

M[BYTENO, BITNO] accesses Marker M bits.

I didn't notice round and square bracket until you pointing out. that was my mistake! first post i type it all. second post i cut and paste it. Thanks!
 

Similar Topics

Hi friends; I attache two image in which one is the refrence table at run time and second is logic at run time. In the logic %R10 shows 78.5...
Replies
2
Views
1,923
im really confuse about these Binary, Control, status, Integer in the allen bradley program, i just dont see the point why they have to use it, im...
Replies
3
Views
6,380
D
I am using the RSlogix500, and want to show the BCD data. What I am going to do is to shift tens, hundreds and thousands digits to the first four...
Replies
4
Views
4,092
dong2
D
Hey everyone, I am trying to right an expression in FTView and getting syntax errors. If {[PLC]System.Auto} Then 1 OR If {[PLC]System.Estopped}...
Replies
2
Views
562
Hey everyone, I am sending an email from a red lion. If I just use 1 of the case statements without the full switch statement, the email works...
Replies
2
Views
1,740
Back
Top Bottom