Top 5 PLC Programming Languages
In 1969, Programmable Logic Controllers (PLCs) were first introduced into manufacturing processes, and today, they are most widely used for automation and industrial process control. In an industrial setup, PLCs are used to control conveyor systems, to sequence automated devices such as robots, and to capture data and communicate information. Almost any machine function, process or production line is greatly enhanced whenever a PLC control system is used. A PLC system is modular, this allows you to mix and match different types of Output and Input devices to best suit your applications. Nevertheless, the greatest benefit of utilizing a PLC is its ability to replicate and change a given process or operation, while collecting and disseminating essential information.
Typically, any PLC has a Central Processing Unit, the CPU, which contains an internal program. The program tells the PLC how to perform various functions such as
- Execute user defined control instructions that are contained in User’s Programs stored in “non-volatile memory”
- Communicate with other devices like Input/Output devices, Networks, Programming Devices, and other PLCS
- Perform internal functions such as Internal Diagnostic and Communications.
Overall, the CPU-based program enables the PLC to monitor the state of input devices and make decisions to control the state of connected output devices, based upon a user-customized program. Hence, the quality of the PLC framework and architecture has a direct impact on its control performance and efficiency.
Historically, most machines and processes did not need advanced data interactions and computation within a PLC. But today’s Industrial Internet of Things (IIoT) megatrend demands more data from processes and systems which traditionally had not been connected to industrial systems. As industries make more use of the available data, advanced computation and analysis is becoming a real need for PLC programs. And as with various microprocessor-based technologies, PLCs have evolved from simple systems with limited memory space and capabilities to state-of -the-art controls which sometimes rival with distributed digital controls in both capability and flexibility.
Coupled with the emergence of a new wave of thought leaders and programmers in the industrial space, this progressive user base is now challenging traditional PLC programming tools. For instance, PLC programming in the industrial environment has historically been done through Ladder Logic, however, more domain-specific PLC programming languages are gaining popularity in the same industrial space. This article reviews the top five high-level IEC (International Electrotechnical Commission) 61131-3 standard PLC programming languages. They include:
1. Ladder Diagram (LD)
Commonly known as Ladder Logic, Ladder Diagram is the first IEC 61131-3 PLC programming language to be developed. It’s the most popular language, as before PLCs became popular relay-based system controls were the norm in manufacturing processes. The relay controls drove loads through simple logic circuits which were implemented through wiring to physical devices such as mechanical relays and switches. Electrical engineering drawings provided the blueprint for the hardwired relay controls, and the wiring layout resembled a ladder. With the introduction of basic PLCs, ladder logic was designed to mimic the relay-based circuits layout. In other words, Ladder Diagram was the first PLC programming language, designed to replace the physical wiring of relay control systems.
Ladder Diagrams utilize internal logic to replace all physical devices, except the ones which are actuated by an electrical signal. As the name suggests, ladder logic is built with two vertical rails among a series of horizontal rungs. The vertical rails show the electrical connection as represented on a relay-logic schematic. Thus, using a Ladder Diagram you can program all the necessary input conditions, whether physical or logical, to influence the output conditions.
Since Ladder Logic is based on relay logic, the most common code of instructions when programming a PLC are: Normally Open (NO) and Normally Closed (NC) and other simple lines of code. The Ladder Diagram is read from left-to-right and top to bottom. The left side represents inputs and they must be true so as to energize the outputs. You can actually visualize the process logically through the horizontal rungs and as data arrives from the inputs to the PLC components.
Advantages of Ladder Logic
- The horizontal rungs make it easy to learn, build, organize follow and interpret
- Easy to diagnose faults and correct issues especially when your system is online, by using online debugging tools
- More reliable compared to electronic circuit controllers
- It is an efficient way of representing discrete logic, as Ladder Diagrams are designed to mirror electrical circuits
- It allows you to document comments that are readily visible
The simplicity of Ladder Diagram makes it the most preferred and popular PLC programming language. It is also highly recommended for beginners, especially if you have a basic understanding of conditional statements and digital logic, it will be quite easy to pick up. However, like every other programming language, Ladder Logic has the following limitations:
Disadvantages of Ladder Logic
- Inability to encapsulate hierarchical data and logic code for reuse. For instance, if use a Ladder Diagram for complex systems, the programs would be unmanageably long, and is difficult to break the program into manageable parts.
- Limited execution control. The execution of ladder rungs in left-to-right and top-bottom approach, whose timing is defined by the speed at which the PLC can scan and execute; works only for applications that are primarily based on discrete logic. Also, this limited execution control of LD programs makes building multi-rate applications very difficult.
- Poor data structure. Generally, Ladder Diagrams address single memory bits, and they can read data and write to variables anywhere in the LD program. This makes it hard to protect and group the data as a structure. Because the low-level data addressing technique, may lead to accidental access of the wrong registers, thereby risking internal data.
- Arithmetic operations. Traditionally Ladder Logic could only deal with timers/counters and discrete values, but today’s Ladder Diagram packages are enhanced to support mathematical operations. However, this is only sufficient for simple arithmetic operations, but complex mathematical algorithms involving multiple variables and requiring intermediate results can be very difficult to program, debug, document and edit using Ladder Diagrams.
Also, applications of Ladder Diagram are limited due to the use of only the defined blocks and it is not great with motion control; but you can always get away with programming most of your PLC control systems using Ladder Logic alone.
2. Function Block Diagram
Function Block Diagram (FBD) is the second most popular PLC programming language. It is a graphical type language and it uses most of the Ladder Logic commands, but the FBD is usually easier to read, interpret and conceptualize compared to LD. A typical Function Block Diagram describes a function which connects together program blocks to build a PLC program. Connection lines are then used to connect the input and outputs blocks.
The use of blocks in FBD makes it possible to consolidate multiple code lines into a single block. Initially, Function Blocks were developed to build a control system which could only be used to set up a single repetitive task such as PID Loops, timers, counters…etc. In this case, the blocks could be programmed onto sheets, then the PLC could constantly scan the sheets depending on the programmed connection between the blocks or in numerical order.
But since programming languages keep advancing, today’s Function Block Diagrams are employed in multiple repetitive functions such as closed-loop control, starters, PID loops…etc. Whereby each new block of the FBD is connected to the output of the previous component. This allows data to flow in a nested manner from one program block to the next virtually. In this type of programming, the most important task is to take care of data types, identifiers, variables and key words for the program to run smoothly.
Advantages of Function Block Diagram
- Easy to Program: Since FBD is a graphical representation language, it is easier to use especially for system designers who do not have extensive skills in understanding and programming logic controls.
- Extensive Code Reuse: FBD provides extensive code reuse, as existing function blocks like filters or PIDs can be re-used. Also, system designers can encapsulate customized logic code and easily reuse in several other programs, without the risk of overwriting data accidentally. This is because whenever a function block is called within the program, a separate copy is created.
- Easy Debugging and Execution Traceability: The use of graphical data flow in FBD allows system designers to follow connections between function blocks and functions, this makes debugging very easy. Also, most of the program editors for FBD language like Siemens Step 7, provide animated data flows which make debugging much easier.
- Parallel execution: With the development of multiple-processor -based control systems, PLCs can now execute multiple functions simultaneously. And FBD being a graphical PLC programming language, it can represent parallel logic more efficiently. This is very helpful for applications that require advanced control, such as control of multiple PIDs connected in parallel.
Disadvantages of Function Block Diagram
- It is not suitable for algorithm development, as most mathematical algorithms and low-level functions have always been represented in text functions. Also, textual programming has been conventionally used to write function block algorithms, while FBD is a graphical language. Hence, the complexity of these algorithms, makes it difficult for one to understand the details of advanced signal processing and control techniques.
- The left to right execution strategy of an FBD network is best suited for continuous processes. But not ideal for solving sequencing control problems, because even though system designers can use data dependency of function blocks to solve such, this type of sequencing maybe cumbersome and time consuming.
- Modern industries are continuously seeking for ways to integrate IIoT to their systems through connectivity to databases and Web. However, FBD programs are not capable of integrating with IT systems, as they lack source control features and database logging capabilities unlike textual programs.
Thus, depending on your system needs FBD could or could not be the optimal choice. For a system requiring repetitive tasks and a lot of motion controls, Function Block Diagram is the straightforward option. However, if you need to create a lot of code or you need to solve multiple sequencing problems or integrate your PLCs to IT systems, then FBD may not be your best choice.
3. Sequential Function Chart (SFC)
The Sequential Function Chart is also a graphical PLC programming language and is similar to Ladder Diagram (LD) and Function Block Diagram (FBD). If you have ever used flowcharts then SFC should feel familiar, as it uses the same logic as a flow chart. This PLC programming language consists of a number of steps, transitions and actions.
The steps are represented by rectangular blocks and each step depicts a given state of the control system. Steps are the major functions in your SFC program, and the initial step is usually the first to be activated when the program is executed. Second, transitions are used to connect the steps and they are the instructions used to navigate from one step to another. The transitions are condition-based, such that when a condition for an active state becomes true, the next step gets active while the previously active step is deactivated.
The steps can either be inactive or active depending on the settings of the transitions, false or true respectively. This decision can be determined by the timing of a given phase of a process, or a certain physical state of a machine or equipment. Lastly, an action is always performed whenever a step is active. In simple terms, SFC language is used to write concurrent programs using steps and transitions to achieve the desired end result. Unlike conventional flowcharts, Sequential Flow Charts are capable of having multiple paths, and branches can be used to initiate multiple steps simultaneously.
Advantages of Sequential Function Charts
- Easy to use for large codes, as the huge processes can be divided into major steps which makes coding and debugging easier and faster.
- SFC allows real-time debugging, as you have direct access to the logic flow, hence, you can identify the exact fault location in your or equipment and fix it.
- Due to repeated execution of individual instructions, designing and modifying SFC logic is much faster.
Disadvantages of Sequential Function Charts
- SFC has a limited number of applications, as it can be challenging to apply an SFC program to a process that is not sequential.
- It is difficult to troubleshoot and implement Parallel Flows using Sequential Function Charts. Because even though it allows you to execute unlimited number of process flows; implementing separate flow paths for multiple flows could require a robust sequence.
4. Structured Text
Fourth on the list is Structured Text, commonly abbreviated as STX or ST. Structured Text closely resembles basic C programming and is a high-level PLC programming language. The user writes a line of codes which execute sequentially, perform Boolean checks, evaluate specific functions, and actuate appropriate PLC outputs. The ST code consists of statements which are separated by semicolons and it makes use of functions such as ‘WHILE’, ‘IF’, ‘FOR’, ‘ELSEIF’ and ‘ELSE’. Furthermore, an STX program can be manipulated easily in text processors, which make it possible to implement the program faster without requiring a hardware.
Structured Text is best suited for control systems that perform complex tasks or require mathematical algorithms. As it can implement data analysis, calculus and trigonometry more easily compared to the previously discussed graphical languages like Ladder Diagram, Function Block Diagram and Sequential Function Chart. If you have a background in conventional programming languages such as C, C++, Python or Java, then you can easily become proficient in Structured Text as it uses commands with similar structure. Also, Structured Text features the same programming paradigms, functions and structures as other textual based languages.
Advantages of Structured Text
- Structured Text is very good for implementing advanced functionality like mathematical logic and complex algorithms, due to its greater flexibility compared to other PLC programming languages.
- Since Structured Text is standardized among majority of PLC control systems, an STX program can be implemented and transferred easily between software and hardware platforms. Also, the standard coding format of ST programs makes their modification very easy.
Disadvantages of Structured Text
- Compared to graphical PLC programming languages, Structured Text syntax can be complex making its troubleshooting much more difficult. This can be explained by the fact that ST has fewer visual aids, no visual queues, and typically every single line contains more code
- Structured Text can be prone to errors. Because even though it provides the user with greater flexibility, this comes with a cost of standardization. Hence, the user is required to trap any potential software failure or create safe fallbacks using software engineering tools that maybe helpful.
Due to the shortcomings mentioned above, Structured Text is rarely used in production lines or in an industrial setup. Hence, we typically recommend it for those who have a background in other PLC programming languages like Ladder Logic. As it is an excellent way to implement ‘FOR’ loops and manipulate data using other structures which would require extra steps in Ladder Diagram (LD).
5. Instruction List
The final in the list is Instruction List (IL). Instruction List is more of an assembly language, and like Structured Text it is also textual based. It consists of a series of instructions and many lines of code, but each instruction is written on a new line with any needed comments annotated at the end of each line. An IL program is read from top-to-bottom and left-to-right. And in terms of IL program flow, each line specifies the conditions as well as the instructions and the execution outcomes.
Instruction List is very easy to read and conceptualize, since each line of code is executed sequentially. All you need to learn are the mnemonic codes such as Start=ST, Load =LD, OR, AND…etc. In many aspects, IL programs are similarly implemented like Ladder Logic; but they are often confused with Structured Text (ST) as their editors are the same. However, all three: Ladder Diagram, Structured Text and Instruction List are capable of creating a similar process flow.
Advantages of Instruction List
- It has a highly standardized structure, which requires the user to list every instruction, specify conditions and create explicit variables. This tight structure means implementation of the program has fewer variations, hence understanding the code is much easier.
- As the name suggests, Instruction List language places more emphasis on instructions than on data flow. This programming style brings with it high level of clarity especially on how data is processed within the program.
- It offers low memory consumption and high execution speed for programs compared to other PLC programming languages.
Disadvantages of Instruction List
- The main drawback with Instruction List is that it is not available in most PLC platforms, and is not popular a programming language mainly because it comes unnaturally to most system designers and PLC programmers. As mentioned above, in the market it is considered more of an assembly language than a PLC programming language.
- It is also limited in terms of code structuring, and it is more difficult to debug and fix errors in IL compared to other languages.
Conclusion
In conclusion, these five most popular language choices, open PLC programming in the industrial space to more possibilities beyond Ladder Logic. As there is certainly a place for each or a combination of any of the languages we have reviewed; as each one of them serves a unique purpose; be it Ladder Logic, Function Block Diagram, Sequential Function Chart, Structured Text or Instruction List.
With this kind of programming background, a PLC which can support multiple programming languages and efficiently interface with cloud technologies like IIoT, will open up many possibilities for industrial control systems which previously would not be possible. In summary, deciding which PLC language to use depends on your programming background, the complexity of the task at hand and the application of the system being controlled.
DO Supply Inc. makes no representations as to the completeness, validity, correctness, suitability, or accuracy of any information on this website and will not be liable for any delays, omissions, or errors in this information or any losses, injuries, or damages arising from its display or use. All the information on this website is provided on an "as-is" basis. It is the reader's responsibility to verify their own facts.