ControlLogix: Ladder vs. Structured Text

ST or Ladder?

We got a machine a while back that is mainly ST. I go to that area to help recover her when she breaks down. Maintenance over there hates ST and will probably string up the engineer if they ever find him! Actually just heard they are quoting having it rewritten.

And trust me, when they can not figure something out or open it and cant tell WTF they are looking at...Its the wingineer who is stupid not them! haha. :ROFLMAO:

Oh and in my opinion for next loops and program control have their place. Not in every stinkin program you write but they do have their place.
 
Last edited:
If I want to create a loop in ladder I will use a jmp/lbl. So, let me guess, looping is bad practice?

The argument will be made that using a jmp/lbl combo which results in jumping backwards in logic using isn't desirable. I know there have been discussions about that topic on the forum. I don't use jmp/lbl enough to make a good argument one way or another. Jumping to skip a bunch of logic that doesn't need to be processed is understandable. Personally if I'm doing any looping in ladder it's with a for loop instruction and a dedicated sub-routine simply for clarity.

It's not too often I use any loops in logic, especially with AOIs. If I do require a loop, then I am defaulting to ST code because I'm probably manipulating data rather than looping through "control" logic.

I do see loops used for device control which is a dated technique given the rise of AOIs.
 
So just for the fun of it, I re-wrote a couple of ladder programs here in "C" just to see what they'd look like, and it turned out to be a thousand IF statements with some embedded PIDs and Timers (an oddball-looking program, I'd say).
Boolean math doesn't require IF THEN ELSE

C:=A AND B;

IF THEN is only required if there is a need to do more than just change a coil.

The advantage of ladder is that you can see visually what is active and what isn't.
 
Not that you will care, but not much I agree with in your post. So using lbl/jmp is not good practice? That's ridiculous. Intentionally making a program complicated to prevent tinkering is even more stupid. You don't want tinkering, try a password.

Didn't say that lbl/jmp was bad practice, or to make a program more complicated. Strawman much?

Setup your arrays so that the last item is the newest. Then a single COP can shift the array. Elegant and efficient.

Use the best tool for the job. If you can make something cleaner in ST that others won't understand, too bad for them. I'm not going to write inefficient code for the sake of others. That's what comments are for, to explain how you did something. If someone can't understand, then they don't belong doing what they're doing.
 
Didn't say that lbl/jmp was bad practice, or to make a program more complicated. Strawman much?

Setup your arrays so that the last item is the newest. Then a single COP can shift the array. Elegant and efficient.

Use the best tool for the job. If you can make something cleaner in ST that others won't understand, too bad for them. I'm not going to write inefficient code for the sake of others. That's what comments are for, to explain how you did something. If someone can't understand, then they don't belong doing what they're doing.

Oh, so you didn't say, "You don't want to make it easy for people to tinker in your program in the first place." I guess that means different things.
 
The argument will be made that using a jmp/lbl combo which results in jumping backwards in logic using isn't desirable. I know there have been discussions about that topic on the forum. I don't use jmp/lbl enough to make a good argument one way or another. Jumping to skip a bunch of logic that doesn't need to be processed is understandable. Personally if I'm doing any looping in ladder it's with a for loop instruction and a dedicated sub-routine simply for clarity.

It's not too often I use any loops in logic, especially with AOIs. If I do require a loop, then I am defaulting to ST code because I'm probably manipulating data rather than looping through "control" logic.

I do see loops used for device control which is a dated technique given the rise of AOIs.

I guess I should have indicated that my question about loops was rhetorical. Asking about best practice in this forum and you will get 100 responses, all different... the majority of which are not correct, or realistic. Thanks for the response though.
 
With this upcoming project, since I am really a "C"/"C++" programmer and *not* a PLC/Ladder programmer, I would like to use Structured Text for my logic.

You have just made another big assumption, but unfortunately incorrect assumption. The format of the instructions, Ladder, structure text, function blocks, and etc, are not different languages, but are different ways of displaying the same logic. Some may have some instructions (like PIDE) that are not available the other formats, but this is not important for this discussion.

** Changing to a format that looks like "C" does not change the PLC into a "C" type operation. **

The thought process for programming a PLC is more like writing code for AWK or sed than C. Broadly generalizing, In C programs the logic typically executes 'once through', with some sections repeating with loops. In PLC code ALL of the logic is re-run continuously. In C programs, the logic performs a calculation, and its function is done. The function may get repeated again, but the logic is "complete" when the subroutine returns. In PLCs, the function of the code continues through multiple executions of the same code. For instance, in even a simple function of starting a motor, one pass through the code uses a start input to latch logic to turn on an output and start a timer. Subsequent passes through the same code does a different function of checking to see of the motor shows faults, or checks to see if the motor should stop.

The different PLC formats make it easier to follow different types of code. Structured text is nice for displaying formulas. Function blocks are nice for showing relations within the logic. Ladder shows the logic most directly to how is executes, and many of us find it the easiest to follow and troubleshoot problems due to unusual input conditions.
 
The thought process for programming a PLC is more like writing code for AWK or sed than C. Broadly generalizing, In C programs the logic typically executes 'once through', with some sections repeating with loops. In PLC code ALL of the logic is re-run continuously. In C programs, the logic performs a calculation, and its function is done. The function may get repeated again, but the logic is "complete" when the subroutine returns. In PLCs, the function of the code continues through multiple executions of the same code. For instance, in even a simple function of starting a motor, one pass through the code uses a start input to latch logic to turn on an output and start a timer. Subsequent passes through the same code does a different function of checking to see of the motor shows faults, or checks to see if the motor should stop.

It's not really that different.

Each program/routine/AOI/FC/FB executes to completion, just like it would in the C world. The main difference is that the main task/OB starts over from the beginning once it is done, whereas the C programmer would have to manually do that if he wanted his program to run forever.
 
Boolean math doesn't require IF THEN ELSE

C:=A AND B;

IF THEN is only required if there is a need to do more than just change a coil.

The advantage of ladder is that you can see visually what is active and what isn't.

Peter, you are a shining light in the darkness. The rest of us are bickering about personal preferences, and you're trying to get us back on topic with solidly useful info.
 
YThe format of the instructions, Ladder, structure text, function blocks, and etc, are not different languages, but are different ways of displaying the same logic.

Actually, LAD, FBD, ST, STL etc. are different programming languages and, as any language (spoken or written) they are conveying information/commands from the user to the operating system of the automation controller.

There are rules, mnemonics and syntax that apply to each language and each operating system of any CPU controller require different logic commands in order to achieve the intended functionality.
 
Last edited:
If I want to create a loop in ladder I will use a jmp/lbl. So, let me guess, looping is bad practice?

Try FOR and BRK - it is more "structured" - your code that is executed repeatedly is containerised into its own subroutine file. The same can be said for code that you want JMP'd over (skipped), put it into a new subroutine and conditionally JSR it, it will have exactly the same effect.

One of the problems with JMPs and LBLs is that it imposes a restriction on placement of new code. To the unwary, adding a few rungs of code into the ladder could be sitting it in aplace that is skipped by a JMP/LBL, or executed many times in a "looping" JMP backwards
 
Oh, so you didn't say, "You don't want to make it easy for people to tinker in your program in the first place." I guess that means different things.

Yes, not making it easy to tinker /= intentionally making it difficult
 
the advantage of ladder is that you can see visually what is active and what isn't.

I am not sure about other PLC's but a i am using Beckhoff with TwinCat 3 and i can see active variables in ST. Same thing with with FBD. I can't see any advantages in Ladder. Of course this is just my opinion but i feel that Ladder is very unclear.
 
Last edited:
I am not sure about other PLC's but a i am using Beckhoff with TwinCat 3 and i can see active variables in ST. Same thing with with FBD. I can't see any advantages in Ladder. Of course this is just my opinion but i feel that Ladder is very unclear.

Really ? Is that why it has become one of the most popular, if not the most popular PLC language since the 1960's.

As a visual representation of the running program, it suits the widest audience, from seasoned programmers to low-skilled maintenance techs....
 

Similar Topics

Is it possible to export a routine programmed in structured text and import it into a ladder routine?
Replies
2
Views
2,879
I created a new program task under that I created 2 ladder files. My first ladder does not have the 1 flag in the ladder icon designating it is...
Replies
8
Views
4,210
Hi all, Is there a equivalent function block that do the same as MOV function in ladder? Thanks.
Replies
5
Views
2,326
I am making some changes in a control logix PLC program that an engineering programmed for my company. In the program they have used the same I/O...
Replies
15
Views
7,408
Hi everybody, Until now I worked only with ladder logic. Now I have a program with function blocks. It looks more complicate, e.g. you have to...
Replies
4
Views
3,055
Back
Top Bottom