Ladder vs STL

JOLTRON

Lifetime Supporting Member
Join Date
Aug 2006
Location
MI
Posts
692
Hello All,

I mainly program in Ladder logic. And my company has a few machines we got from our German counterpart, the programing styles between American and German thinking are very different. I was wondering if anyone could take this code and show me a similar way it could be done in Ladder to help me comprehend it, since It can't be done exact. Thanks, -Joel


L #SR
L 1
<>I
JC M003
A "EStop OK Bit"
AN #TS
A #TL // release chip step 1
AN #TKL
AN #TOR
R #S1Z
S #S1A
S #TKL
JC M004
JU M005

M004: L 0 // count => 0 after " RELEASE STEP 1"
T #SR
BEU

M005: A #S2Z // tension adjusters TO RESETS,
AN #SP2 // if no feedback
R #S2Z
A "EStop OK Bit" // introduction chip steps 2
A #TS
AN #TL
AN #TKS
AN #TOR
O #STAR
A #SP1
S #S2Z
R #S2A
A #S2Z
A #SP2
S #TKS
R #STAR
JC M006
BEU

M006: L 2
T #SR
BEU

M003: NOP 0
 
Last edited:
Here's my implementation. Take this source code and put it into a STL source and compile it. It will view in ladder. Note I have used temps for all the variables - you will have ins outs etc instead.

Code:
FUNCTION FC 10 : VOID
TITLE =
VERSION : 0.1
 
VAR_TEMP
SR : INT ; 
TS : BOOL ; 
TL : BOOL ; 
TKL : BOOL ; 
TOR : BOOL ; 
S1Z : BOOL ; 
S1A : BOOL ; 
S2Z : BOOL ; 
SP2 : BOOL ; 
TKs : BOOL ; 
STAR : BOOL ; 
SP1 : BOOL ; 
S2A : BOOL ; 
Estopok : BOOL ; 
NoMoreLogic : BOOL ; 
END_VAR
BEGIN
NETWORK
TITLE =
 
	 L	 #SR; 
	 L	 1; 
	 <>I ; 
	 =	 #NoMoreLogic; 
NETWORK
TITLE =
	 AN	#NoMoreLogic; 
	 A	 #Estopok; 
	 AN	#TS; 
	 A	 #TL; 
	 AN	#TKL; 
	 AN	#TOR; 
	 =	 L	 4.0; 
	 A	 L	 4.0; 
	 BLD 102; 
	 R	 #S1Z; 
	 A	 L	 4.0; 
	 BLD 102; 
	 S	 #S1A; 
	 A	 L	 4.0; 
	 BLD 102; 
	 S	 #TKL; 
	 A	 L	 4.0; 
	 JNB _001; 
	 L	 0; 
	 T	 #SR; 
_001: NOP 0; 
	 A	 L	 4.0; 
	 BLD 102; 
	 S	 #NoMoreLogic; 
NETWORK
TITLE =
	 AN	#NoMoreLogic; 
	 =	 L	 4.0; 
	 A	 L	 4.0; 
	 A	 #S2Z; 
	 AN	#SP2; 
	 R	 #S2Z; 
	 A	 L	 4.0; 
	 A(	; 
	 A	 #Estopok; 
	 A	 #TS; 
	 AN	#TL; 
	 AN	#TKs; 
	 AN	#TOR; 
	 O	 #STAR; 
	 )	 ; 
	 A	 #SP1; 
	 S	 #S2Z; 
	 R	 #S2A; 
	 A	 L	 4.0; 
	 A	 #S2Z; 
	 A	 #SP2; 
	 =	 L	 4.1; 
	 A	 L	 4.1; 
	 BLD 102; 
	 S	 #TKs; 
	 A	 L	 4.1; 
	 BLD 102; 
	 R	 #STAR; 
	 A	 L	 4.1; 
	 JNB _002; 
	 L	 2; 
	 T	 #SR; 
_002: NOP 0; 
	 A	 L	 4.1; 
	 BLD 102; 
	 S	 #NoMoreLogic; 
END_FUNCTION

Here's the ladder:
stllad001.JPG
 
Last edited:
L=LOAD
A=AND
AN=AND NOT
JC=JUMP CONDITIONAL
JU=JUMP
R=RESET
S=SET
T=TRANSFER
O=OR
NOP=NO OPERATION
BEU=I THINK THIS MEANS BLOCK END.. NOT TOTALLY SURE..

So first your program compares SR with 1 and if its not equal it jumps to label m003 else it continue to
A "EStop OK Bit"
AN #TS
A #TL // release chip step 1
AN #TKL
AN #TOR
this is like a ladder rung:
--I I--I/I--I I--I/I--I/I--



if thats true this happens:

R #S1Z
S #S1A
S #TKL
JC M004

else it jumps to M005

M004: L 0 // count => 0 after " RELEASE STEP 1"
T #SR
BEU
Here we load 0 and transfer it to SR and then end block

M005: A #S2Z // tension adjusters TO RESETS,
AN #SP2 // if no feedback
R #S2Z
S2Z ANDNOT SP2=RESET S2Z

A "EStop OK Bit" // introduction chip steps 2
A #TS
AN #TL
AN #TKS
AN #TOR
O #STAR
A #SP1
If this is true then do this:
S #S2Z
R #S2A
A #S2Z
A #SP2
S #TKS
R #STAR
JC M006
else
BEU (block end)

M006: L 2
T #SR
load 2 and transfer to sr
BEU (block end)

M003: NOP 0 (No operation) does nothing


Hopes this help..
 
Hello again. Now I have another question about STL.
I am confused with the "A(" nested and statements. Does this just carry the RLO to the end bracket ")" and carry on so nothing in the brackets matters?

This is the code I'm dealing with. If anyone can give me an example of how it would look in ladder it would be greatly appreciated.

Thanks,
-Joel

A "Auto Mode"
A "Roll door closed"
A(
A "Start PB"
L S5T#6S
SE T 61
NOP 0
NOP 0
NOP 0
A T 61
)
AN "Indicate Empty start OP"
S "M Automatic-Clamp"
A(
ON "Auto Mode"
ON "Roll door closed"
O "Run with No Cans"
O "Mn Ext in Postion"
)
R "M Automatic-Clamp"
NOP 0
 
Put your cursor on the line with A( and press F1 - this will give you the Siemens help and will be a good starting point.
 
Read through that before posting. STL just doesn't make sense to me. I have a basic idea of how I think this should work but wanted to be sure before moving ahead in my project. Do you know of any place I can go to get examples and practice programs involving STL.
 
Try making this mod to your code and it should convert to ladder....

Code:
[/color]
[color=darkorange]A([/color]
A "Auto Mode"
A "Roll door closed"
A "Start PB"
L S5T#6S
SE T 61
NOP 0
NOP 0
NOP 0
A T 61
) 
AN "Indicate Empty start OP"
S "M Automatic-Clamp"
A( 
ON "Auto Mode"
ON "Roll door closed"
O "Run with No Cans"
O "Mn Ext in Postion"
) 
R "M Automatic-Clamp"
NOP 0
 
STL can be daunting when you first see it, but once it clicks in your mind you will love it.

Its a shame that unknowledgible endineers sometimes enforce rules where STL is not allowed at all, I can understand having the basic code in ladder but sub-routine functions are far better in STL.

Its like having a world boxing champion and tying one hand to a foot behind his back before a fight.

A good way to learn the basics is to write code in ladder, then switch it to STL and see what comes up.

There will be NOP's and BLD's that appear, which you don't need in STL but ladder representation requires them, you can see where these go, just remember that they can be removed for STL programming but once removed it will not reconvert to ladder. (unless you put them back of course)
 
Why is it so much better for sub-routines to be done in STL as supposed to ladder? Is it due to scan times? And is there a difference in the way FB's and FC's act??? Are the processed differently than each other?

Thanks,
-Joel
 
Here's my take on brackets (or nesting).

Opening a bracket saves the current state of the logic evaluation (the RLO) and starts a new and independant evaluation which is terminated by the close bracket. The saved RLO is now combined with RLO from the bracketed evaluation as per the opening bracket statement. It really is just like using brackets in algeabra.

Here's a screen shot of some ladder and the resultant STL that uses brackets. For the sake of clarity, I have manually indented the bracketed code.

Of course another option is to not use brackets at all and instead evaluate each term to a temporary variable and then combine the temporary variables using simple logic.
bracket001.JPG
 
JOLTRON said:
Why is it so much better for sub-routines to be done in STL as supposed to ladder? Is it due to scan times? And is there a difference in the way FB's and FC's act??? Are the processed differently than each other?

Thanks,
-Joel

Since sub-routines are usually called over and over, they often contain math functions, indirect addressing, and more complex algorithms.

In theses cases, STL will run much faster and it will be much quicker to develop. Plus, some of the instructions that are very useful in subroutines can't even be done in ladder. Once you learn STL, you'll see what I mean.

Just as an example, if I had an analog input and wanted to convert it to PPM, I could do this in STL:

L PIW760
ITD
DTR
L 4.56
*R
T #HMI_Display

Try the same thing in ladder. Not only will you need about ten times as many instructions, it will take longer, and it will be no easier to understand. Looking at the above code, anyone with a little practice can easily see that I take my analog input, convert it to a DINT, convert it to a REAL, scale it with 4.56, and output it to a variable for the HMI. It has six instructions and took 15 seconds to write. If you are doing a very large project, this adds up.
 
Ahh, it's only about four times as many then. But the point is that for math (and other non-bit functions) STL is more efficient and quicker to write.
 
For the example shown, the BR bit is always forced on so the blocks in the ladder will always execute. When performing other arithmetic, *D for example, the ladder version will generate code to check for overflow and if an overflow occurs, it will not execute blocks further along the same rung. If you perform the arithmetic using STL, it is up to you to decide what to do in the event of an overflow.
 
I guess the example above just shows the inefficiency of Siemens ladder implementation and not necessarily the advantage of STL.

This is how the compatible example would look in ladder code for Yaskawa MP PLC.

||- IW00004 * 4.56 ==> MF22000



Just one rung :) "Load as real", "multiply" and "store to". Well, I am a bit of joking here - the code would work all right, it is just not every PLC would allow you to do the data type conversions like that, in an implicit manner. Rather an exception.

Of course there are tons of examples where STL is much more effective than LD, no doubt.
 

Similar Topics

Hi, Anyone know why this network is not longer shown in LAD format but only in STL ? O "RB 20878".EinfV O "RB 20878".EinfR...
Replies
11
Views
2,498
Hi people, could any one tell me if i have converted this STL code correctly A M 30.7 O M 31.0 A M 105.7...
Replies
3
Views
1,446
Hi dear enthusiasts;), I am taking a PLC course where we use Festo PLC (FC660). I did some LDR programming before and not until recently I...
Replies
9
Views
6,699
Hey hi, I have written a logic in ladder in Siemens s7 300 plc and then converted it into STL . Now I m trying to convert it into ladder again...
Replies
1
Views
2,912
Hi, Is there a program that understands Sattcon 31 controller STL language and converts it to more understandable ladder diagram ? //
Replies
2
Views
2,198
Back
Top Bottom