LAD vs FBD vs STL

So you want to start writing your PLC program and you can’t decide which language to use. Maybe you’ve written a few programs now and you think you’re pretty good so you’ll give another language a try. Which one to use: Ladder (LAD), function block diagram (FBD) or statement list (STL)? (I’ll leave SCL and GRAPH for another day).

Well, good news, whichever choice you make you can reverse. Didn’t like FBD? Just change it to LAD. LAD taking up too much screen space? Why not try STL? However, sometimes swapping and changing doesn’t work quite right and so I’ve put together some things to consider when picking a language.

Pros and Cons

So what is the difference between these languages? Surely they must all have their pros and cons.

LAD

Ladder logic is a visual programming language based on the concept of representing each individual network as it would be shown in a circuit diagram for relay logic. This language is best for people who come from an electrical (as opposed to electronic or computer science) background. Diagnostics are made easy as the individual contacts are highlighted to show the RLO (result of the logic operation) so you can quite quickly find out what is preventing your coil from turning on. Disadvantages are that once your networks get more complex it becomes impossible to see the whole thing on the screen at a time. NOTE: converting your existing hardware relay logic to LAD directly may look correct but will most likely not work as expected – PLCs are sequential, relays are not.

FBD

Function Block Diagram is better for people coming from an electronic or computer science background as it is a visual representation based on logic gates. Diagnostics are a little less clear than LAD as it is harder to see the individual inputs to a gate but the gate as a whole is highlighted based on the RLO. Depending on your network, FBD representation may take up more or less screen space than LAD.

STL

Statement List is often the quickest way to write your PLC. Copy and paste is quicker, making small modifications is quicker. Performing more complex operations like loops and jumps and indirect addressing becomes easier in STL. You can also bypass the type checking that occurs LAD and STL, want to load a byte into an int? No problem. HOWEVER, it is just about impossible to debug, particularly if you are using it for all the complex operations mentioned above. Also, just because you can load a real number into a double word doesn’t mean that the result will make any sense to anyone. STL is powerful, but you have to know what you’re doing. NOTE: it is entirely possible to write STL code which Step7 will not be able to convert back to LAD or FBD leaving you stuck trying to debug in STL.

Recommendation

Basically, it depends on who is going to have to maintain the software and what you are trying to do with it. Most of the places I go to electricians will be performing maintenance tasks and debugging problems on the PLCs I write. In these cases I use LAD wherever possible. Picking FBD is still valid and comes down to personal preference as the maintenance personnel can freely swap between these two languages.

STL, I’ll admit, I use more than I should. It allows me to rapidly write code and to do things in one network that would take me 100 networks in LAD or FBD. However, I avoid using it whenever dealing with hardware inputs or outputs as these are the things which are most often the subject of maintenance debugging. I also keep it to simple networks (yes, I still write loops and jumps) so that it is easier to detect bugs later on.

Leave a Reply

Your email address will not be published. Required fields are marked *