S7 SCL beginner here

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
FUNCTION FC007: VOID

VAR_INPUT
START :BOOL;
STOP :BOOL;
END_VAR

VAR_OUTPUT
GESTART: BOOL;
END_VAR

BEGIN
IF START = true THEN
GESTART := true
ELSE
GESTART := false
END_IF;

END_FUNCTION




I wrote this

A lot of mistakes,

this is my first testprogram, what can I do to let it work ?
 
Combo, when you use ":=" in SCL it is the same as using "SET" in STL. As far as i know, the "=" in STL or the "-()" in ladder does not exist in SCL. So when you set a coil, you have to rest the coil. Your program will work, but the output GESTART will only be active as long as the START input is "high"

use this:

IF START = true THEN
GESTART := true;
ELSIF STOP = true THEN
GESTART := false;
END_IF;

Now the output GESTART will stay active, even if the START input is set to "low". GESTART will become "low" when the input STOP becomes "high".
 
Hey

THANKS TO YOUR CODE I UNDERSTOOD WHAT TO DO

FUNCTION FC007: VOID
VAR_INPUT
START :BOOL;
STOP :BOOL;
END_VAR
VAR_OUTPUT
GESTART: BOOL;
END_VAR
BEGIN
IF START = TRUE THEN
GESTART := TRUE;
ELSE
GESTART := FALSE;
END_IF;
END_FUNCTION


Why = when it's an IF statement and not := ?


Garcia said:
Combo, when you use ":=" in SCL it is the same as using "SET" in STL. As far as i know, the "=" in STL or the "-()" in ladder does not exist in SCL. So when you set a coil, you have to rest the coil. Your program will work, but the output GESTART will only be active as long as the START input is "high"

use this:

IF START = true THEN
GESTART := true;
ELSIF STOP = true THEN
GESTART := false;
END_IF;

Now the output GESTART will stay active, even if the START input is set to "low". GESTART will become "low" when the input STOP becomes "high".
 
And how

And houw do you write a toggle in scl for example...

In STL:

A #INPUT
FP #MEM
X #OUTPUT
= OUTPUT


Somthing in a way of counting ?? +1 and -1 ??
 
":=" is an assignemt operation, "=" is a comparison operation.

An overview of all operations is given in the SCL manual on page 11-2.
 
Okay

Okay, I understand

Do u know why I can't monitor ? :::
debuggr.JPG


Garcia said:
":=" is an assignemt operation, "=" is a comparison operation.

An overview of all operations is given in the SCL manual on page 11-2.
 
Sorry if I am a little anal here, but in Garcia's code, the start button has precedence. In most cases the stop button shall have precedence.
I suggest this:

IF STOP = true THEN
GESTART := false;
ELSIF START = true THEN
GESTART := true;
END_IF;

And combo, in your latest code you simply have GESTART := START. STOP has no function.
 
If (input) And Not (Mem) Then 
If Output Then Output := False ;
Else Output := True ;
End_if ;
End_if ;

Mem := Input ;


edit: Forgot an endif :oops:
 
Last edited:
Combo,

A SCL manual can be found here.

It would be easier if u first read the manual, then tried experimenting.

Have fun reading.

Greets
Jeebs
 
1) The Ken Rule About Boolean Assignments in SCL.

NEVER use IF-THEN-ELSE to assign a simple Boolean state. I would only use IF-THEN-ELSE for more complex arrangements, perhaps where entirely different actions or values are being selected. If you find yourself using True and False in the IF-THEN-ELSE structure, stop and think about it. There's usually a better way to code it.

It is much easier to write an assignment as follows -

GESTART := START and not STOP;

This uses less memory and is much less ambiguous. You can also add further logical or relational conditions on the right-hand side, for example -

GESTART := START and not STOP and (TT101A >= 127.5);

2) One-shots

The one-shot is a function that is missing from the IEC definition of ST, so you won't find it in SCL. Three options are either to write it in SCL as Jesper showed; or recode in this style -

OUTPUT := not OUTPUT and (INPUT and not MEM);
MEM := INPUT;

or write it as a self-contained FC in STL and just call that function whenever you need it in SCL.

Even if there's only one question, there's are usually 20 different replies!!

Regards

Ken
 
Ken. You are so right.

The x:= true and y:=false are similar to S x and R y in STL, and (S) and (R) in LAD.
However, we all know that a latch function can be achieved without S and R. Only there has to be parallel keep contact.
In LAD we would program a latching output like this (with stop precedence):
 
Start Stop output
--| |--------|/|-------( )
|
output |
--| |-----|



In SCL that would be:
output := (output OR start) AND NOT stop
So, in SCL it actually becomes more compact and elegant in this way.
 
@ Ken M: I like your solution. It is, to quote Jesper, much more compact and elegant. I should use the logical expressions more often when programmingin SCL.
 
Hi

This toggle i not bad... I mean, Toggle in STL and LAD needs a bit work to understand, in scl I understood this toggle in the first cycle o_O

I know, don't write process logic in SCL, but for calculations, and this toggle, scl is not bad I think now

JesperMP said:
If (input) And Not (Mem) Then 
If Output Then Output := False ;
Else Output := True ;
End_if ;
End_if ;

Mem := Input ;


edit: Forgot an endif :oops:
 

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
82
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
559
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
317
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
653
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
512
Back
Top Bottom