PLCs, PACs

Other PLC programming languages

Ladder logic is commonly used in the U.S. for programmable logic controllers (PLCs), but other languages are better suited for some programming applications. See sample PLC code in five languages.
By Frank Lamb July 8, 2019
Courtesy: Frank Lamb, Automation Primer

In the United States, most people involved with the programming and maintenance of programmable logic controllers (PLCs) tend to think ladder logic is the only PLC programming language. Much of this belief is due to the PLC’s history, and how the U.S. market has been dominated by brands that use ladder logic as their primary language.

In fact, before the widespread use of computers and laptops for programming PLCs, handheld programmers often were used to enter a program into the PLC. Drawing electrical diagrams for different instructions often preceded this. This was much like how the original relay logic used to be wired before the PLC came along. There were sometimes symbols on the handheld devices signifying the different instructions, but there was also a text-based language behind the graphical design.

In 1994, the International Electrotechnical Commission (IEC) produced a standard, IEC 61131-3, which defined what a PLC should be. Along with formalizing the definitions of instructions such as timers and counters, they also defined five programming languages.

Instruction list (IL) was the same text-based language ladder logic was often converted into. Some used it only as a stepping-stone to machine code, which ultimately was the language compiled in the processor. Other brands used instruction list as a primary language and added instructions that couldn’t be represented in ladder logic at all (such as statement list).

Ladder logic was defined further, along with subroutines and other aspects of PLCs. As mentioned previously, ladder evolved from circuit diagrams for relay logic, which was familiar to maintenance electricians.

Function block diagrams (FBD) was another graphical programming language used in some controllers, including distributed control system (DCS) controllers. It describes the function between input and output variables using different types of blocks, such as AND, OR, comparisons, math, timers and counters. Inputs are fed into a block from devices or other blocks’ outputs; outputs carry data to the next block or to a variable.

Structured text (ST) is a high-level language similar to computer languages such as Pascal. It uses iteration loops such as Do-While or For-Next, conditional statements such as If-Then-Else or Case, and other math functions such as Sqrt() or Sin().

The sequential function charts (SFC) language is based on an old logic language called Grafcet, which was based on binary Petri nets. It is a language of blocks called steps, and transitions with associated logic conditions. Steps within the language are active or inactive and logic can be run in parallel.

Several years ago, I thought it would be fun to write a short piece of code in all five languages to see how they would compare. The following logic establishes an auto and manual mode, then enables a “cycle” bit after 3 seconds. It is purposely generic, but is based on some of the different PLC platforms I use: (Figures 1 to 5)

 

 

Figure 1: Instruction list programming example; IL often is used for more complex mathematical tasks and searching. Courtesy: Frank Lamb, Automation Primer

Figure 1: Instruction list programming example; IL often is used for more complex mathematical tasks and searching. Courtesy: Frank Lamb, Automation Primer

 

Figure 2: Ladder logic programming example; LL is the most commonly used PLC programing, most closely resembling circuit diagrams used for relays. Courtesy: Frank Lamb, Automation Primer

Figure 2: Ladder logic programming example; LL is the most commonly used PLC programing, most closely resembling circuit diagrams used for relays. Courtesy: Frank Lamb, Automation Primer

 

Figure 3: Function block diagram programming example; FB diagrams lend themselves nicely to safety circuits/safety PLCs. Courtesy: Frank Lamb, Automation Primer

Figure 3: Function block diagram programming example; FB diagrams lend themselves nicely to safety circuits/safety PLCs. Courtesy: Frank Lamb, Automation Primer

 

Figure 4: Structured text programming example; ST can help with complex mathematical tasks and searching. Courtesy: Frank Lamb, Automation Primer

Figure 4: Structured text programming example; ST can help with complex mathematical tasks and searching. Courtesy: Frank Lamb, Automation Primer

 

Figure 5: Sequential function chart (SFC) programming example; SFC is useful for staged logic. Courtesy: Frank Lamb, Automation Primer

Figure 5: Sequential function chart (SFC) programming example; SFC is useful for staged logic. Courtesy: Frank Lamb, Automation Primer

 

As mentioned before, different brands and software packages handle these languages differently. The syntax and way the code is displayed will differ based on which platform is used.

Instructions and comments are often color-coded to make them easier to read. Generally, the language packages cost extra or are included in the “professional” versions of the programming software.

These languages are used for different purposes also. Ladder is still appropriate for straightforward “bit-banging” logic, while instruction list and structured text are often used for more complex mathematical tasks and searching. Function block diagrams lend themselves nicely to safety circuits/safety PLCs. and SFC is useful for staged logic.

Consider using some of the “other” PLC languages the next time there’s a complex program to write because it might make the job easier.

Frank Lamb is the founder of Automation Consulting LLC, the creator of Automation Primer, and is a member of the Control Engineering Editorial Advisory Board. Edited by Mark T. Hoske, content manager, Control EngineeringCFE Media, cvavra@cfemedia.com.

MORE ANSWERS

Keywords: Ladder logic, programming languages

Ladder logic is the most common programming language used for programmable logic controllers (PLCs) in the U.S.

Instruction list, function block diagram, structured text, and sequential function charts are all useful programming languages and may be more appropriate than ladder, depending on the application.

Consider this

What programming languages have you used other than ladder logic and why?


Frank Lamb
Author Bio: Frank Lamb is the founder of Automation Consulting LLC, the creator of Automation Primer, and is a member of the Control Engineering Editorial Advisory Board.