DN Staff

April 14, 2011

5 Min Read
IEC61131-3 as an Integration Tool

IEC61131-3 may sound like a complex specification, but inpractical use it comes down to just a few concepts that promote goodprogramming techniques and code reusability.

The most fundamental of IEC concepts is program executionbehavior. Each controller or PLC in an automation system is called a resource,and each resource executes one or more tasks. Multiple tasks may be updated atdifferent update rates. The IEC code in each task is further divided intoProgram Organization Units (POUs), which are executed within the task in theorder specified. The POU may exist as a program type and run in the associatedtask. Alternatively, it may be a mathematical function type POU or a FunctionBlock type of POU, both of which run when used within the program type of POU.

Much like the familiar programming subroutine, customizedfunctions and function blocks allow the programmer to wrap up a particularpiece of code for easy organization, for reuse, for protection of intellectualproperty, and/or for revision control.

IEC61131-3 as an  Integration Tool

IEC61131-3 as an Integration Tool_A


Click here for larger image.

Variables and Data Types
The terminology and mechanics of variables, data typesand literals is defined in IEC61131-3 - and these definitions must be followed.

The character set is limited to alphanumeric and the underscorewith no spaces or special characters allowed. Programmers must therefore getused to working with variables with names like "FeedSpeed" or "Feed_Speed."Capital letters are preserved for display purposes, but capitalizationdifferences are ignored in program execution.

Most programmers are likely to find a new set of standard termsto get used to in IEC61131-3. Besides the previously mentioned acronym POU, aconstant hard-coded value is called a literal. A variable with one bit ofinformation is called a BOOL. And when there's a decimal point, it's called aREAL or LREAL data type.

This data type terminologymanifests itself in both literals and variables. A literal, hard-coded value of"5" is expressed in the code with a data type prefix such as LREAL#5.0, INT#5,WORD#5, or TIME#5s.

This provides a visibledouble-check for the programmer to avoid unintentional mixing of data types.The same holds true with variables.

A variable is assigned a datatype, and the initial value associated with that variable must match the datatype. So if a variable is named "FeedSpeed" and is given the data type LREAL,then it can have an initial value of 5.0, but not 5 or 5s.

Often in programming, theoutput of one part of the code is in one data type, and it must be used inanother part of the code as another data type. For example, an input value maybe received from an HMI as a WORD#5, to be written to the variable "FeedSpeed,"with the LREAL data type. This requires a data conversion step.

IEC61131-3 good programmingpractice insists that any conversion step not be hidden from view, so theprogrammer must specifically define the conversion step. Fortunately, data typeconversion function blocks between any two combinations of the 20 standard datatypes are provided so that data type conversion can be tightlycontrolled.

Multiple Programming Languages
IEC uses and combines five of the most common programminglanguages: Ladder Diagram (LD), Structured Text (ST), Function Block Diagram(FBD), Instruction List (IL) and Sequential Function Chart (SFC).

The programmer decides the best language for a particular POUbased on personal preference and on the purpose of that particular POU. Afunction block POU written in one language can be used within another POU of adifferent language.

For example, a complexmathematical formula may be best programmed using the ST language. I/O logic isusually more easily programmed in LD, while FBD may be best for a motioncontrol sequence. SFC is effective to control the states of the machine. Underthe IEC61131-3 standard, the strengths of each language can be used simultaneously.

High-Level Programming
IEC61131-3 goes beyond fundamental programming techniques- defining several high-level programming concepts such as Enumerated Types,Arrays and Data Structures.

Enumerated Types give a name to a number so that when a numericalselection is required, the name can be used in its place. This makes the codemore intelligible and aids in troubleshooting.

For example, the PLCopen function block MC_MoveAbsolute includesa direction input so that rotary machines can locate the position in fourdifferent ways, including "shortest_way." Instead of assigning the directioninput to 0, 1, 2, or 3, the "shortest_way" text can be used.

Arrays are familiar to many programmers and allow a large amountof data to be accessed by indexing the address within the array. The datastructure is a critical programming tool for wrapping up an assembly ofdifferent types of data into one variable.

One example of the usefulnessof data structures can be found in Yaskawa's PLCopen Toolbox user library for theMP2000iec series controllers. Each axis in a system will typically have thesame data associated with it such as a jog speed, run speed, position,parameters, etc.

Traditionally, the programmer must create separate variables foreach of these axis-specific pieces of data, a tedious task. But withIEC61131-3, it's possible to define a data structure that contains all of theaxis-specific data once and for all, creating a type of template.

The programmer then creates a single variable (FeedAxis) for theaxis and chooses this new structure as the data type (Axis Struct). Thisprovides the equivalent result to having created tens or even hundreds ofvariables all at once.

The data can be accessed as if it were a variable using the dotnotation such as FeedAxis.JogSpeed or FeedAxis.Prm. Additional variables withthis same data structure can be defined for the other axes in the system,quickly creating an orderly and consistent definition of variables associatedwith each axis.

The IEC61131-3 standard provides a host of benefits toprogrammers of PLCs and controllers for integrating mechatronic applications.Although it takes some time up front to learn specific terminology andtechniques, overall efficiency is increased. The resulting programs can then beused and interpreted by others familiar with the standard, creating commonground for other programmers and for maintenance and operations personnel.

MattPelletier is senior product training engineer at Yaskawa America Inc.

Clickherefor more information.

Sign up for the Design News Daily newsletter.

You May Also Like