S7 SCL beginner here

Final(?) thought.

If anyone familiar with LAD is having problems getting their head around logical operations and assignments in SCL, just read it in reverse. Take Jesper's small piece of LAD as an example -
Start Stop output 
--| |--------|/|-------( )
|
output |
--| |-----|

Here the right-most element is the coil, Output. So that becomes the left-most element in our SCL statement -
Output := ...

And then you continue reading the LAD from right to left and building up the SCL statement accordingly -

Output := not Stop ...
Output := not Stop and (Start or Output);

Depends on how your brain's wired I suppose. Eventually you'll get used to thinking in both directions according to the application.

Regards

Ken
 
For information, see below the STL produced by two different toggle implementations, the first uses an If..then method, the second uses the assignment and logic method. They both produce 16 lines of STL.


Code:
FUNCTION_BLOCK FB1
VAR_INPUT
input:BOOL;	
END_VAR 
VAR_IN_OUT
OUTPUT:BOOL;
MEM:BOOL;
END_VAR   
BEGIN
OUTPUT := not OUTPUT and (INPUT and not MEM);
MEM := INPUT;
END_FUNCTION_BLOCK
 
	  SET   
	  SAVE  
	  =	 L	  0.1
	  A	 #OUTPUT
	  NOT   
	  =	 L	  0.2
	  A	 #MEM
	  NOT   
	  A	 #input
	  A	 L	  0.2
	  =	 #OUTPUT
	  A	 #input
	  =	 #MEM
	  A	 L	  0.1
	  SAVE  
	  BE	
 
 
FUNCTION_BLOCK FB1
VAR_INPUT
input:BOOL;	
END_VAR 
VAR_IN_OUT
OUTPUT:BOOL;
MEM:BOOL;
END_VAR   
BEGIN
IF input AND NOT Mem THEN 
  Output := NOT Output;
End_if ; 
Mem := Input ;
END_FUNCTION_BLOCK
 
	  SET   
	  SAVE  
	  =	 L	  0.1
	  A	 #MEM
	  NOT   
	  A	 #input
	  JCN   A7d0
	  A	 #OUTPUT
	  NOT   
	  =	 #OUTPUT
A7d0: CLR   
	  A	 #input
	  =	 #MEM
	  A	 L	  0.1
	  SAVE  
	  BE
 
...and to add another to make Ken's 20 replies here is my implementation. I prefer to use intermediate variables that describe the processing, hence I would use a separate variable for detecting the rising edge and then test that variable to perform the toggle. As Ken said, it depend how you brain is wired.

Code:
FUNCTION_BLOCK FB1
VAR_INPUT
input:BOOL;	
END_VAR 
VAR_IN_OUT
OUTPUT:BOOL;
MEM:BOOL;
END_VAR  
VAR
RisingEdge:BOOL;
end_var 
BEGIN
RisingEdge := INPUT AND NOT MEM;
MEM := INPUT;
IF RisingEdge THEN Output:= NOT Output; END_IF;
END_FUNCTION_BLOCK
 
(We'll get to that magic score of answers yet!

L D[AR2,P#0.0], (or can I just call you Pointer?),

Thanks for the examples. I'm not sure what evidence I once used to persuade myself that there was a memory saving associated with assignments compared to IF-THEN-ELSE's. Clearly these blocks of yours challenge my fundamental system of belief! Could I have just invented that idea and stuck with it? Was there ever any evidence or was it a leap of faith? Perhaps such a trivial example reduces the problem to zero. More investigation needed, but I doubt if I'll invest the time. Let's face it, if memory consumption is your top number one priority SCL is unlikely to be the weapon of choice anyway.

regards

Ken
 
...

i'll stay with

A #IN
FP #MEM
X #OUT
= #OUT


But, when is it really an advantage to use SCL, because until now i'm a good LAD and FBD programmer and a learning STL programmer. But SCL does interest me too...
 
Writing in SCL, we are writing code more like computer programming languages like C or Pascal.
The code snippet
If Output Then Output := False ;
Else Output := True ;
End_if ;

can be written as
output = not output;

(It works. Ihave used to store the status of a toggle push button.)
 
namboothiripad.mbs said:
output = not output;
(It works. Ihave used to store the status of a toggle push button.)
hi
I think this is going to make output toggel with every scan.

-----|\|----------()
q0.0 q0.0
 

Similar Topics

HI i would like to know how to get a variable that will store the amount of times a program has been executed. The issue is I have 3 DBs for 1 FB...
Replies
2
Views
99
Hi, I have an intermediate-advance knowledge of programming with TIA Porta in Ladder, would you recommend me to start learning SCL for it to...
Replies
11
Views
578
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
351
Hi everyone, I am new to this amazing world of PLC, well... I mean, in practice, since I already knew electronics, programming languages, IT, and...
Replies
7
Views
664
Hi all, This is my first post; I am new to PLC Controls stuff and English is not my native language, so I apologize in advance if something is...
Replies
4
Views
518
Back
Top Bottom