scl or other languages

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
Hi,

I was wondering, I mostly program in LAD, and STL. I know a little of Structure text programming. So in an other topic, they are telling me that it's comparable with SCL.

Is it interesting to learn SCL, or is it just something for C programmers that don't know anthing about LAD and STL ?
 
I mainly use Siemens PLC's and have recently used quite a bit of SCL. I have found several advantages. Ladder, graph and STL don't allow symbolic reference of array indexes so you can't increment an index to an array using a tag, you have to use an absolute value. In graph you can. SCL code also tends to be quite condensed when compared with ladder. Also there are some Class B conversion functions that I don't believe are available in ladder or graph. I am not sure about STL.
 
There is another issue about using SCL or LDA, the compiler compiles them back into STL which will lead to more commands per job. when you are Low in memory or speed, writing codes in STL might save you money. Otherwise and if it is possible to do, LDA will be best as the maintenance staff can easily deal with it...
 
Last edited:
Marek Tenerowicz said:
I mainly use Siemens PLC's and have recently used quite a bit of SCL. I have found several advantages. Ladder, graph and STL don't allow symbolic reference of array indexes so you can't increment an index to an array using a tag, you have to use an absolute value.
Yes
In graph you can.
I thought we were talking about SCL. What is graph?

SCL code also tends to be quite condensed when compared with ladder. Also there are some Class B conversion functions that I don't believe are available in ladder or graph. I am not sure about STL.
It isn't clear to me if you are saying SCL can do this:

A:=B[j]

or not. I would be interested in what the resulting STL code looks like.
 
Sorry Peter. In my comment "In Graph you can" I meant to say "In SCL you can". Yes I was saying A:=B[j] can be done in SCL, but since I don't write much STL I don't know what the code would look like. SCL just seems much more intuitive than STL.
 
Here's the STL for A:=B[j] where the arrays are declared as arrays of integers in the stat area of an FB:
Even if the arrays are accessed in a loop, the array element indirect address is calculated by multiplying the index by the size of the array element - if was doing this in STL, I would maintain the pointer as a double word and use addition to point to the next array element.

Code:
	 SET 
	 SAVE 
	 =	 L	 0.1
	 L	 #i
	 ITD 
	 L	 L#-1
	 +D	
	 L	 L#16
	 *D	
	 L	 #j
	 ITD 
	 TAK 
	 T	 LD	 2
	 TAK 
	 L	 L#-1
	 +D	
	 L	 L#16
	 *D	
	 L	 LD	 2
	 TAK 
	 T	 LD	 6
	 TAK 
	 TAR2 
	 +D	
	 L	 LD	 6
	 TAK 
	 T	 LD	 2
	 TAK 
	 TAR2 
	 +D	
	 LAR1 
	 L	 DIW [AR1,P#20.0]
	 LAR1 LD	 2
	 T	 DIW [AR1,P#0.0]
	 SAVE 
	 BE
Simon
 
That is good info Simon.

This code can be improved if the arrays are zero based. Simon's example must have used a 1 based array which requires subtracting 1 from the index before use. Also, array indexes should be DINTs. The INTs are promoted to DINTs before using as indexes. The code could be even more efficient if AR2 is used. There also seems to be a lot of juggling registers that accomplishes nothing and I don't think the user can do anything about these inefficiencies.

Simon, I think we all learned a lot from this, thanks. I do have a request. Could you do this?
temp=a
b[j]=temp
and declare the arrays to be 0 based 0..9 and use DINTs for i and j. I bet that the code will be much better.
 
Peter, array indexes cannot be assigned DINT types in SCL so that saving cannot be made. Declaring the arrays zero based does make the saving you predicted. (For reference, the debug info option is off, code optimisation is on, array index limit checking is off). For the case I originally posted, the arrays are in static data so the indirect addressing for the array access has to add on the current value of AR2 to make sure the code will work for multiple instance function blocks - this is the juggling of registers you are referring to.
Code:
FUNCTION_BLOCK FB3
VAR
	A: ARRAY[0..9] OF INT;
	B: ARRAY[0..9] OF INT;
	i,j,temp:INT;
	END_VAR
BEGIN
temp:=A[i];
B[j]:=temp;
END_FUNCTION_BLOCK 
	 SET 
	 SAVE 
	 =	 L	 0.1
	 L	 #i
	 ITD 
	 L	 L#16
	 *D	
	 TAR2 
	 +D	
	 LAR1 
	 L	 DIW [AR1,P#0.0]
	 T	 #temp
	 L	 #j
	 ITD 
	 L	 L#16
	 *D	
	 TAR2 
	 +D	
	 L	 #temp
	 TAK 
	 LAR1 
	 TAK 
	 T	 DIW [AR1,P#20.0]
	 SAVE 
	 BE

Just for comparison, here is the code with the arrays in temp data:

Code:
FUNCTION_BLOCK FB3
VAR_TEMP
	A: ARRAY[0..9] OF INT;
	B: ARRAY[0..9] OF INT;
	i,j,temp:INT;
	END_VAR
BEGIN
temp:=A[i];
B[j]:=temp;
END_FUNCTION_BLOCK 
 
	 SET 
	 SAVE 
	 =	 L	 46.1
	 L	 #i
	 ITD 
	 L	 L#16
	 *D	
	 LAR1 
	 L	 LW [AR1,P#0.0]
	 T	 #temp
	 L	 #j
	 ITD 
	 L	 L#16
	 *D	
	 L	 #temp
	 TAK 
	 LAR1 
	 TAK 
	 T	 LW [AR1,P#20.0]
	 SAVE 
	 BE
 
Last edited:
Thanks Simon.

That is educational.
The code isn't very efficient but it is limited by the design of the virtual machine. The design of the virtual machine makes a big difference in how efficient array handling can be.
I know that the TAR2 instruction loads the based address of the data block but that should only be necessary in multiple instance data blocks.
 
Y'all confuse me when you do this..

It is my understanding that IEC 1131-3 has 5 methods of programming:
  1. LD - Ladder
  2. IL - Instruction List
  3. ST - Structured Text
  4. FBD - Function Block Diagram
  5. SFC - Sequential Function Chart.
The problems is that not all companies use the same term(s) for what is equivalent. Siemens has STL (Statement List) which I believe is the same as Instruction List.

Why do they make this so hard? Looked up SCL, it is:
SCL (Structured Control Language) is a high-level textual programming language which is based on PASCAL. It is also based on a standard for PLCs (programmable logic controllers).
The standard​
DIN EN-61131-3 (IEC 1131-3) sets down standardized requirements for programming languages for programmable controllers. The basis for SCL is the section ”structured text”. For precise details of standards conformity, refer to the ”Compliance List” in the NORM.TBL file in STEP 7.

In addition to high-level language elements, SCL also includes language elements typical of PLCs such as inputs, outputs, timers, bit memory, block calls, etc. In other words, SCL complements and extends the STEP 7 programming software and its programming languages Ladder Logic and Statement List.​
The programming offered is beyond me at this time but there was a comment made that I did not understand.​
There is another issue about using SCL or LDA, the compiler compiles them back into STL which will lead to more commands per job. when you are Low in memory or speed, writing codes in STL might save you money. Otherwise and if it is possible to do, LDA will be best as the maintenance staff can easily deal with it...
It is my understanding the "code" that actually loads on the plc is machine language, regardless of what programming language you use.​
Does anyone know if any style of programming will actually decrease the use of memory used by the PLC? If so which version and why?​
I am not debating or asking which is better, people learn different ways and have a tendency to use what they are most familiar and/or comfortable with.​
I am looking for details that will explain which one(s) have features etc that may allow you to do more.​
 
Hey

First of all:

I AGREE WITH RSDORAN


Second: Can you explain this code a bit ? I write more and more in STL, but allways direct adressing and never used arrays or pointers... SO please explain detailed, I really want to understand your code !!!

FUNCTION_BLOCK FB3
VAR_TEMP
A: ARRAY[0..9] OF INT;
B: ARRAY[0..9] OF INT;
i,j,temp:INT;
END_VAR
BEGIN
temp:=A;
B[j]:=temp;
END_FUNCTION_BLOCK

SET
SAVE
= L 46.1
L #i
ITD
L L#16
*D
LAR1
L LW [AR1,P#0.0]
T #temp
L #j
ITD
L L#16
*D
L #temp
TAK
LAR1
TAK
T LW [AR1,P#20.0]
SAVE
BE
 
IF ya do not know the secret handshake do not hold your breath Combo, been here 4 years or more and have not learned that handshake.
 
Combo said:
... I really want to understand your code !!!

Please note that the STL posted has been produced by the SCL compiler. You can view STL produced by the compiler by firstly opening the block editor and then opening the block using file->open and selecting the relevant block. If you try to open the block by double clicking in the blocks folder, the SCL editor will start up (unless of course you delete the SCL source code !).

I would recommend Berger's book (search this site for the latest version) if you want to explore indirect addressing or search this site for indirect addressing examples.
 

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
79
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
652
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