Check out our new eBook:

PLC Programming with Studio 5000 Logix Designer

Level 1 – Beginners

Check out our new eBook:

Popular PLC Programming Languages

Popular PLC Programming Languages

Table of Contents

Introduction to PLC Programming Languages

Programmable Logic Controllers have evolved to meet the demands of today’s industrial automation. When they were first introduced, their function was to simply replace electrical relays, which were costly and difficult to maintain.

Fundamentally, PLC ladder logic looks just like an electrical diagram.

Electrical schematic

The first PLCs were limited in the amount of memory and functions. Therefore, the only language available was the ladder diagram.

This was the basis for engineers to write programs that matched the physical wiring of the before-mentioned electromechanical relays, pushbuttons, or timers. The same peripheral components for inputs and outputs are used and wired to the PLC.

With today’s increasing needs in process automation and machinery automation, the PLC has quickly evolved to meet the needs of all types of control systems.

As PLCs became more complex, they were quickly referred to as Process Automation Controllers (PAC), and the different programming languages began to be offered in the programming software.

EC 61131-3 - Programming Languages

EC 61131-3 is the third part (from a total of ten parts) of the open international standard IEC 61131 for programmable logic controllers. The IEC was first published in December 1993, and the current (third) edition was published in February 2013.

Part 3 of IEC 61131 deals with basic software architecture and programming languages of the control program within PLC. It defines three graphical and two textual programming language standards.

  • Ladder Diagram (LD), graphical
  • Function Block Diagram (FBD), graphical
  • Structured Text (ST), textual
  • Instruction List (IL), textual – deprecated in the 3rd edition of the standard and will not be learned in this book.
  • Sequential Function Chart (SFC) has elements to organize programs for sequential and parallel control processing, graphical.

PLC Programming Basics

Tags

It is essential to mention the fundamental or most important data types that support all PLC programming languages.

Below are a few of the most common you will encounter or use while programming. PLCs can store data of many types and ranges. Therefore, it is important to know them to avoid issues while compiling programs.

Data types in programming:

  • Boolean – One bit 0/1
  • Integers – Hold whole number values
  • Real or Floating Point – Decimal values
  • Strings – Alphanumeric characters

Program scan

No matter which programming languages you use, it’s crucial to understand how the PLC scan works.

The controller scan can be divided into four stages:

  1. Input reading – signals from the field arrive at the inputs modules, and the PLC takes a”picture” of the inputs and stores them in a dedicated memory.
  2. Program scan – The code runs one scan from the start to the end. In this stage, a dedicated memory served for outputs is updated according to the code.
  3. Output writing – The PLC writes the outputs memory to the outputs modules and then to the field to activate a motor or a valve.
  4. The last stage is saved for communication and internal diagnostic

This scan is repeatedly running forever or until be stopped manually. The scan stages are executed in a very short time, usually in milliseconds.

Ladder Diagram ,Ladder Logic - LD

The primary way of programming is known as ladder diagram or ladder Logic. The most common of all PLC programming languages and most widely used in programming.

As mentioned in the first section, LD uses the same symbols as an electrical diagram with more advanced functions available to the programmer.

The traditional electrical circuit is known as a “rung” and reads top to bottom and left to right. The ladder diagram uses the same fundamentals of logic gates (AND, OR, NOT).

Ladder Diagram - AND
AND Gate
Ladder Diagram - OR
Ladder Diagram - OR

Comments can be added to the rungs, making troubleshooting the code or documenting what the code is intended to do much simpler.

More advanced PACs offer functions such as relational, mathematical, and arithmetic. These can be added to a rung within the ladder diagram and used like in other program languages.

Structured Text - ST

Another popular PLC programming language is structured text. This language is text-based and relatively simple to read and write.

Structured Text is an excellent method for programs with repeatable code, for example if you have several motors or alarms to program. Below is an example.

Structured Text

In the example, there is an “IF” statement (semicolons are used to separate the statement or a line termination).

If the Machine_Start bool is not true or a 1, then we will set the Alarm_1 to true or a 1. If the first statement is not true, the Alarm_1 will be false or a 0.

This type of programming makes hundreds of alarms much easier to program, as iterating would only require changing a few characters in the tags.

Programming is also much easier as you can complete the code in just one line. The compiler does not care about spaces, and this is up to the programmer to decide to increase the readability of the code.

Comments can be added to the lines much like other programming languages. The syntax is as follows: /*This text is a comment*/ or (*This is also a comment*)

The structured text also makes comparing functions much easier, such as equal, less than, greater than. This can be done to check variables and add more functionality to the program.

The last advantage of structured text is the arithmetic operations that can be done in one line of code.

Sequential Function Chart - SFC

Sequential Function Chart or SFC is another popular way to program processes that must be executed in a sequence. The advantage of the Sequential Function Chart is the ability to break the program into steps or sequences, which are represented graphically.

An example, SFC can be used in a batch process in which a tank is cleaned and prepared to store food products to sterilize the vessel.

Sequential Function Chart

The first step is to start the process and wait for the conditions to get to the set-point (temperature, flow, or other process variables).

A transition step is then initiated to open a path to the tank from the chemical supply. Next, the tank is dosed with the chemical and kept at a temperature for sterilization.

Another transition step is used to close the valves from the supply, and finally, the process is stopped automatically.

The lines between the boxes add to the visual aspect much as a flow chart. This type of programming is excellent for processes where multiple PID (Proportional, Integral, Derivative) loops are used in a process.

It enhance the program organization and reduces the amount of coding required. However, programs can become hard to read in large processes when many actions are needed to accomplish the necessary steps.

Function Block Diagram - FB

The last popular programming language is the function block diagram. This type of programming provides a graphical programming method and allows the user to see the process.

Most commonly, FBD is used to program PID loops in process automation. This is because PID loops are easier to program this way as it helps to see all of the I/O associated with the PID.

Every block will have text near the top, as shown below; this text represents the function of the block.

The left side will represent the inputs, and the right will represent the outputs.

The block example shown is of a TON or Timer On-Delay.

TON FB
  • The “TimerEnable” pin or connection point represents the bit that will enable the timer.
  • The “PRE” or Preset Timer pin is the value assigned as the preset time.
  • The “ACC” pin represents the elapsed time.
  • Finally, the “DN” pin is the output that will be true when the timer has finished timing.

There are many more operations possible with Function Block Diagrams than timing functions. Many other functions, much like the other languages, include; conditional, logical, assignment operation, or counters.

Function Block Diagram

Conclusions

PLC Programming Languages have evolved to meet the demands of industrial automation’s discrete and analog devices and provide greater control of processes.

The different programming languages allow the programmer to choose between them to cater to their needs and programming functionality.

Languages such as Structured Text allow for greater program modularity; the ladder diagram is simple and easy to troubleshoot. FBD and SFC are alike in the graphical representation.

These languages all comply with IEC standards and are the most popular worldwide. 

Related Articles