Ladder Logic vs. Other Programming Languages: A Comparison
In today’s article, we are going to talk about Ladder Logic, often referred to as the Ladder Diagram, and how it compares to other PLC programming languages.
As you may be aware, PLCs are special-purpose computers that are designed to monitor and control automated processes. PLCs are programmed using programming languages defined in the IEC 61131-3 standard.
This standard defines 5 programming languages called Ladder Diagram, Function Block Diagram, Structured Text, Sequential Function Chart, and Instruction List that are supported by almost all PLC manufacturers.
Now that we know what programming languages are available for PLCs, let’s start by talking about Ladder Diagram before seeing how it compares to other IEC 61131-3 programming languages.
Ladder Diagram is the most popular PLC programming language because it was the first one introduced.
When PLCs were first invented as a programmable alternative to hardwired relays in control panels, Ladder Diagram was the only programming language available.
Ladder Diagram was designed to be easy to understand for the electrical engineers that would be using it to program automation.
To make it easy to understand, Ladder Diagram is a high-level, graphical programming language that is designed to look like electrical schematics.
Because it is a visual language, it is very easy to understand and debug Ladder Diagram code. Ladder Diagram makes it easy to program and monitor complex Boolean logic which is exactly what it is designed for.
Here, you can see a snippet of Ladder Diagram that is used to control a motor. Can you see how easy it is to look at this snippet and determine what inputs are missing to make the motor run?
In our course CODESYS 1: Introduction to PLC Programming, we explain how to program PLCs using Ladder Diagram to control applications like this one.
If you’re interested in learning more about programming PLCs using Ladder Diagram, check it out at this link.
Now that we know what Ladder Diagram is, let’s see how it compares to the other IEC 61131-3 programming languages.
Ladder Diagram vs Structured Text
Structured Text, or ST, is a text-based PLC programming language.
It is generally preferred by people with traditional programming backgrounds because of its similarity to higher-level programming languages like Python.
Structured Text is much better than Ladder Diagram for specific tasks.
For computation, mathematical instructions can be chained together to do complex calculations on a single line. In Ladder Diagram, each step in the computation requires dedicated instructions which makes calculations bulky.
Structured Text is also better for looping over sections of logic since it has built-in instructions like FOR and WHILE which are designed for looping. In Ladder Diagram, you have to build loop constructs yourself.
Despite these advantages, I do not recommend using Structured Text as the primary programming language in a project.
The people who have to maintain and debug your code are usually not computer programmers and will not be comfortable with text-based programs.
For this reason, I recommend using Ladder Diagram as your main programming language and keeping the use of Structured Text limited to parts of the project that make sense like heavy data manipulation and computation.
Ladder Diagram vs Function Block Diagram
Function Block Diagram, or FBD, is another high-level graphical programming language.
FBD is commonly used in the process industry because its appearance is similar to P&IDs that define how process equipment is laid out.
In the example below, you can see the same logic to control a conveyor implemented in Function Block Diagram and Ladder Diagram.
Like Ladder Diagram, Function Block Diagram is a high-level graphical programming language that is easy to program, monitor, and troubleshoot.
Function Block Diagram can make implementing continuous process control using PID loops easier.
It is recommended to use Function Block Diagram instead of Ladder Diagram in process industries where continuous control is common.
Outside of the process industry, Function Block Diagram is very similar to Ladder Diagram and the choice to use one or the other will come down to personal, company, and industry preferences.
Ladder Diagram vs Sequential Function Chart
Sequential Function Chart, or SFC, is another high-level language that looks like a flow chart.
Because of its similarity to a flow chart, Sequential Function Chart is a great programming language for modeling sequential processes on a high level.
Because it is so high level, Sequential Function Chart should only be used to model processes, not to write control logic.
As you can see in the image below, the logic to control a simple conveyor takes up almost half a screen when implemented in SFC and only one rung in Ladder Diagram.
Since SFC is used for a different purpose, it shouldn’t be compared to Ladder Diagram.
Instead, you can think of it as a complementary programming language that you can use for sequential processes.
You can model the process in SFC, and then implement the control logic in Ladder Diagram.
Ladder Diagram vs Instruction List
Finally, Instruction List, or IL, is a text-based programming language similar to assembly languages.
Instruction List is harder to write and debug than Ladder Diagram, or any of the other IEC 61131-3 programming languages.
It is probably for that reason that the Instruction List programming language is now deprecated.
If you are working on new projects, you should not use the Instruction List programming language. I recommend using Ladder Diagram instead.
Now that we have compared all of the IEC 61131-3 programming languages to Ladder Diagram, I would like to make a few recommendations for which programming languages you use in your everyday work.
First, I recommend that every PLC programmer learns how to program with the Ladder Diagram programming language and uses it as their default programming language.
I make this recommendation because Ladder Diagram is the most widely used, understood, and accepted PLC programming language right now.
In these specific situations, I recommend that you use the other IEC 61131-3 programming languages:
– For continuous process control, consider using Function Block Diagram,
– For heavy computation, data processing, and looping, consider using Structured Text,
– For modeling sequential processes on a high-level and implementing sequencers, consider using SFC
In this article, I have introduced you to all of the IEC 61131-3 programming languages, explained their strengths and weaknesses in comparison to Ladder Diagram, and made recommendations about when you use each programming language.
Even though I recommend that you primarily use the Ladder Diagram programming language, I encourage you to learn all of the IEC 61131-3 programming languages.
A complete PLC programmer is comfortable with all programming languages and is able to choose the best language to accomplish a task.
If you only know one programming language then your options are limited – as the saying goes, if all you have is a hammer, then everything looks like a nail.
If you’re interested in learning how to program PLCs with the Ladder Diagram programming language, then I highly recommend that you enroll in our course CODESYS 1 – Introduction to PLC Programming. This course shows you how to write basic applications using the Ladder Diagram in CODESYS, a free, full-featured PLC IDE that includes a simulator for testing your applications.