and Controls Hydraulics Assembly Technologies Pneumatics Service
profile Drive & Control
Understanding the IEC61131-3
Programming Languages It was about 120 years ago when Mark Twain used the phrase “more than one way to skin a cat.” In Choosing Your Language the world of PLC programming, The International Electrotechnical that cliché is still applicable today. Commission (IEC) identifies five Thanks to the International standard programming languages Electrotechnical Commission as the most common for both (IEC), five standard programming process and discrete programmable languages have emerged as the most controllers: Ladder Diagram (LD), common, used for both process and Function Block Diagram (FBD), discrete programmable controllers. Sequential Function Chart (SFC), The IEC is an organization Instruction List (IL), and Structured that prepares and publishes Text (ST) international standards for all electrical, electronic and related With the different programming technologies, including controllers. languages available, it’s important to With its IEC61131-3 publication, consider a few factors before deciding The complexity of the application, the which to use for your application: the organization identifies these capabilities of the PLC/PAC and the ability five programming languages and to transfer the program code are among • Ease of maintenance by the final their common abbreviations as: the key factors to consider with selecting user: SFC controller programming language. • Universal language acceptance: LD Ladder Diagram (LD), Instruction List (IL), Function Block Diagram • Acceptance in Europe: IL or ST (FBD), Structured Text (ST) and applications, and the multiplying • PLC speed of execution: IL or ST Sequential Function Chart (SFC). methods for implementing control • Applications mainly using digital functions. But many controls I/O and basic processing: LD Long dismissed as just being engineers may be wondering or FBD a European phenomenon, the about the characteristics of each • Ease of changing code: LD IEC’s programmable controller programming language. When • Ease of use by newer engineers: ST languages are gaining traction should one be used over another? • Ease of implementing complex in the United States. The IEC What are the benefits and mathematical operations: ST developed these programming disadvantages of each? This article • Applications with repeating standards in response to the will provide a brief overview and processes or processes requiring interlocks and concurrent growing number of automation comparison of each of the five operations: SFC vendors, the growing complexity of main PLC programming languages. Ladder Diagram (LD) This programming language, invented in the U.S. decades ago, is probably the most widely used. Invented to replace hardwired relay control systems, Ladder Diagram programming is a mainstay in the U.S. today, used in probably 95 percent of all applications. Visually, this language resembles a series of control circuits, with a series of inputs needing to be “made” or “true” in order to activate one or more outputs.
Ladder Diagram language has
experienced such widespread This language resembles a series of control circuits, with a series of inputs needing to be adoption that almost every “made” or “true” in order to activate one or more outputs. programmer in any country or industry can read and write this language. Because it resembles the fires an actuator to push the box be daunting — picture a ladder familiar electric circuit format, to another conveyor. Digital inputs rung with an output used in several even a non-programmer with an are checking for various conditions, phases of a process with many input electrical background can follow and a basic program is analyzing conditions attempting to control the program for purposes of the inputs and firing digital outputs exactly when that output needs to troubleshooting a problem. It’s also in response. There may be timers turn on. easy to start writing a program in the program, or some basic in Ladder Diagram. With just a comparisons or math, but there are Function Block Diagram basic outline of input and output no complex functions involved. Although Ladder Diagramming signals, one can sit down are start may be the most widespread churning out code. Most of the As the complexity of PLC language, a survey conducted by other IEC languages require more functionality has grown, however, Control Engineering magazine preparation, such as flowcharting Ladder Diagram language has several months ago highlighted all the potential process flows. been challenged to meet these growth in the use of programming Finally, most implementations advances and still maintain the languages other than ladder. of Ladder Diagram allow a paradigm of easy visualization and Function Block Diagram program to be organized into understanding. Functions such programming is an example. folders or subprograms that as PID, trigonometry and data Even though the adoption rate for are downloaded to the PLC, analysis are commonly required this language has recently slowed allowing for easy segmentation. in many control applications, but relative to other languages such as difficult to implement. Another Structured Text, Function Block Ladder Diagram programming is challenge is that as program size Programming is probably the ideal for a simple material handling grows, the ladder can become very second most widely used language. application, for example, where difficult to read and interpret, a sensor detects the presence of unless it’s extensively documented. In many ways, this graphical a box, other sensors check for Finally, implementing full language resembles a wiring obstructions, and then an output processes in Ladder Diagram can diagram even more so than Ladder code. With Function Block Diagram, the blocks are “wired” together into a sequence that’s easy to follow. It uses the same instructions as Ladder, but visually is more understandable to a viewer who is not versed in relay logic. The major advantage is that programs written in Function Block tend to be easy to follow — just follow the path! This language is ideal for simpler programs consisting of digital inputs, such as photoelectric sensors, and outputs such as valve manifolds, and could be appropriate in any application where Ladder is ideal. With Function Block Diagram, the blocks are “wired” together into a sequence that’s easy to follow. It uses the same instructions as Ladder, but is visually more understandable to a viewer who is not versed in relay logic. However, this language is not ideal for large programs using special I/O and functions. The large amount of turned off, and the next one in the necessary conditions are met to screen space required by this style sequence is active. The transition allow the program to advance to of programming can quickly make step also has code to check that the the next step. a program unwieldy if it reaches any substantial size. Also, writing a program in Function Block requires more preparation upfront to understand the program and how it will flow before any code is written, since it can be more difficult to make corrections later.
Sequential Function Chart
Sequential Function Chart (SFC) programming resembles the computer flowcharts that many will remember drawing up in their college days. An initial step “action box” (the starting point of a flowchart) is followed by a series of transitions and additional action steps. The concept of SFC is simple: an action box, with code inside written in any language of the programmer’s choice, is active In this example, SFC programming includes a flowchart on one side and two small programs to the right. In an SFC program, the flowchart boxes (called actions) and the until the transition step below it little horizontal lines with names (called transitions) actually have small programs running activates. The current action box is inside them. For appropriate applications which have a repeatable multi-step process or series of repeatable processes, this form of programming is the easiest to implement. An example would be a pick and place application, where product is constantly picked up from one area, moved through a specific path, and placed in another area. While exceptions exist, since there is typically only one active piece of code and one transition to be concerned with, condition checking and the control of the process should be achievable without large rungs. The language is also very friendly to maintenance engineers because the visual nature of the program plus code segmentation makes it easy to troubleshoot. For example, if the mechanism in a pick-and- place application has moved to Instruction List consists of many lines of code, with each line representing exactly one operation. the product but not picked it, the troubleshooter could bring up the program and look at the transition List, Function Block and Ladder programming will see similarities condition between the “move programs can easily be converted with Instruction List programming. to product” box and the “pick into each other, allowing a piece This language consists of many lines product” box to see what is holding of code to be displayed in the of code, with each line representing up the process. way most comfortable to the exactly one operation. Thus, it is user. Structured Text can also be very step-by-step in layout and On the downside, this style of converted into any of these three format, which makes the entry of programming is not suitable for languages, but SFC stands alone. a series of simple mathematical every application, as the structure It cannot be converted. Therefore, functions easy. In addition, if the that is forced on a program could you may want to consider this programmer uses only the IEC- add unneeded complexity. A large language only for end users who defined instructions, a program amount of time must be spent up are comfortable with the language written in this language can be front preparing and planning before and are unlikely to display it in a moved easily between hardware any programming is attempted different format, or for applications platforms. These advantages make or else the functions charts could where the hardware has the speed this language very popular in become unwieldy and difficult and memory necessary to store and Europe, a fact that is surprising to follow. The overhead required execute an SFC program. to many U. S. programmers who for this type of program causes it prefer the ease of maintenance to execute slower than the other Instruction List in the graphical languages, and languages. A final consideration Anyone who has experience place a lower premium in the is the inability to convert to programming microprocessors or transferability of programs. other languages. Instruction experience with Assembler language involved in plastics or chemical manufacturing. Trigonometry, calculus, and data analysis can be implemented far easier in this language than in Ladder or Instruction List. Decision loops and pointers (variables used to do indirect addressing) allow for a more compact program implementation than can be achieved in Ladder. The flexible Structured Text editor that is common in most programming Structured Text language has seen the greatest increase in adoption and closely resembles a high-level computer programming language such as PASCAL or C. packages makes it easy to insert comments throughout a program, and to use indents Instruction List language is a low- PID in Instruction List. This also and line spacing to emphasize level language and as such, will applies to complex mathematical related sections of code. This execute much faster in the PLC computations. Instruction List does makes the task of structuring than a graphical language, like not lend itself well to any form of a complex program easier. The Ladder. This language is also much structured programming, such as text-based, non-graphical nature more compact and will consume state programming or step ladder, of Structured Text, similar to less space in PLC memory. The further limiting its usefulness for Instruction List, also runs much simple one line text entry method implementing large programs. It is faster than Ladder. An additional supported by this language also also arguable that the advantages benefit of Structured Text is that allows for very fast program of speed and compactness are it comes closer than most of the entry — no mouse required, no less relevant, given the processing other languages in achieving the tab to click! In legacy systems, speeds of modern PLCs and the transferability promise of the programs written in this language large amounts of memory available. IEC61131 standard. Copying and are easier to display and edit on a pasting Structured Text from the handheld programming unit, with Structured Text editor of one programming package no software or laptop required. With its IF…THEN loops, CASE to another can often be done with selectors, and lines ending in just a few changes, emancipating Despite the advantages this semicolons, Structured Text a programmer from the hardware language provides to a programmer, language closely resembles a high- platform. A final benefit is that it seems that maintenance and level computer programming many students currently graduating service engineers do not prefer language such as PASCAL or C. The from engineering studies have a Instruction List. Perhaps because aforementioned Control Engineering better background in computer it is less visual than Ladder, and survey indicated that of all the languages than in the basics of therefore more difficult to get IEC61131-defined programming electrical wiring, and therefore can a sense of what the program languages, Structured Text has seen be more proficient in Structured is doing and what errors it is the greatest increase in adoption. Text than Ladder programming. experiencing. Similar to the issues with Ladder Diagram This language perhaps best A disadvantage is that for and increasing PLC program embraces the growing complexity many previously experienced complexity, it can be a struggle to of PLC programming, such as programmers or maintenance and enter complex functions such as the process control functions service personnel, the Structured Text environment is somewhat Finally, your PLC or PAC platform unfamiliar and unsuitable for may also affect the choice of troubleshooting. In many ways, programming languages. Not the code and structure necessary all automation vendors have to make this code maintenance programming software that is fully friendly can reduce some of IEC61131-3 compatible. In fact, the advantages gained from its most of the non-European vendors compactness. As a result, the main do not offer this functionality, or Not all PLCs are capable of running tendency is to use Structured Text only have a very limited spectrum the various IEC languages due to lack “behind the scenes.” For example, of memory or processor speed. However, of options, say Ladder and SFC, but IEC 61131 allows a programmer some companies like Bosch Rexroth make none of the other languages or tag- robust PLCs that can run all of to build his or her own functions the languages. based addressing, etc. in one language, which can then be used in another language. Thus Another consideration is that not the programmer is most likely • Ease of maintenance by the final all PLCs are capable of running to encapsulate a Structured Text user: SFC the various IEC languages due program inside an instruction • Universal acceptance of to lack of memory or processor called on in Ladder. While this may language: Ladder speed. This tends to be the case not necessarily be a disadvantage, • Acceptance in Europe: with many micro PLCs. However, the programmer will need to Instruction List or some companies like Bosch Rexroth thoroughly test any code that is Structured Text make robust PLCs that can run “hidden” and make sure it is bug- • Speed of execution by the PLC: all of the languages. While many free, since others will not have Instruction List or programmers are locked in to a access to it. Structured Text customer specification, if they • Applications mainly using digital have the freedom to choose a Choosing an I/O and basic processing: Ladder hardware platform, they should Appropriate Language or Function Block decide which language or languages With the different programming • Ease of changing code will work best for the application languages available, it’s important later: Ladder and then select the hardware to consider a few factors before • Ease of use by newer engineers: and software accordingly. deciding which to use for your Structured Text application. Of course, if you’re • Ease of implementing complex already familiar with a certain mathematical operations: language, then the tendency may Structured Text be to stick with what you know. • Applications with repeating However, look at some of these processes or processes requiring match-ups: interlocks and concurrent operations: SFC
Subject to change without notice. 5150 Prairie Stone Parkway, Printed in USA. Hoffman Estates, IL USA 60192-3707 ALL RIGHTS RESERVED Telephone (847) 645-3600 FORM ControlProgramming (0109) www.boschrexroth-us.com