Members Only | Ezine | Links | Address | Contact us | Copyright

New!

PLCopen 15 years anniversary brochure!

Introduction into IEC 61131-3 Programming Languages

(from the final draft international standard)

Scope

This Part specifies syntax and semantics of programming languages for programmable controllers as defined in Part 1 of this Standard.
The functions of program entry, testing, monitoring, operating system, etc., are specified in Part 1 of this Standard.

Overview and general requirements

This part of IEC 61131 specifies the syntax and semantics of a unified suite of programming languages for programmable controllers (PCs). These consist of two textual languages, IL (Instruction List) and ST (Structured Text), and two graphical languages, LD (Ladder Diagram) and FBD (Function Block Diagram). Sequential Function Chart (SFC) elements are defined for structuring the internal organization of programmable controller programs and function blocks. Also, configuration elements are defined which support the installation of programmable controller programs into programmable controller systems. In addition, features are defined which facilitate communication among programmable controllers and other components of automated systems. The programming language elements defined in this part may be used in an interactive programming environment. The specification of such environments is beyond the scope of this part; however, such an environment shall be capable of producing textual or graphic program documentation in the formats specified in this part. The material in this part is arranged in "bottom-up" fashion, that is, simpler language elements are presented first, in order to minimize forward references in the text. The remainder of this subclause provides an overview of the material presented in this part and incorporates some general requirements.


Figure 3 - Combination of programmable controller language elements LD - Ladder Diagram (4.2) FBD - Function Block Diagram (4.3) IL - Instruction List (3.2) ST - Structured Text (3.3) OTHERS - Other programming languages (1.4.3)

Table of Content

From the FDIS, incl. page numbers.

1. General 9
1.1 Scope 9
1.2 Normative references 9
1.3 Definitions 9
1.4 Overview and general requirements 14
1.4.1 Software model 14
1.4.2 Communication model 16
1.4.3 Programming model 18
1.5 Compliance 21
1.5.1 System compliance 21
1.5.2 Program compliance 23
2. Common elements 24
2.1 Use of printed characters 24
2.1.1 Character set 24
2.1.2 Identifiers 24
2.1.3 Keywords 25
2.1.4
Use of white space 25
2.1.5 Comments 25
2.1.6 Pragmas 26
2.2 External representation of data 26
2.2.1 Numeric literals 26
2.2.2 Character string literals 27
2.2.3 Time literals 29
2.2.3.1 Duration 30
2.2.3.2 Time of day and date 30
2.3 Data types 31
2.3.1 Elementary data types 31
2.3.2 Generic data types 33
2.3.3 Derived data types 34
2.3.3.1 Declaration 34
2.3.3.2 Initialization 35
2.3.3.3
Usage 37
2.4 Variables 38
2.4.1 Representation 38
2.4.1.1 Single-element variables 38
2.4.1.2 Multi-element variables 40
2.4.2 Initialization 41
2.4.3 Declaration 41
2.4.3.1 Type assignment 43
2.4.3.2 Initial value assignment 45
2.5 Program organization units 47
2.5.1 Functions 48
2.5.1.1 Representation 49
2.5.1.2 Execution control 53
2.5.1.3 Declaration 54
2.5.1.4 Typing, overloading, and type conversion 57
2.5.1.5 Standard functions 59
2.5.1.5.1 Type conversion functions 60
2.5.1.5.2 Numerical functions 61
2.5.1.5.3 Bit string functions 64
2.5.1.5.4 Selection and comparison functions 64
2.5.1.5.5 Character string functions 67
2.5.1.5.6 Functions of time data types 69
2.5.1.5.7 Functions of enumerated data types 71
2.5.2 Function blocks 72
2.5.2.1 Representation 72
2.5.2.1a Use of EN and ENO in function blocks 74
2.5.2.2 Declaration 75
2.5.2.3 Standard function blocks 82
2.5.2.3.1 Bistable elements 82
2.5.2.3.2 Edge detection 83
2.5.2.3.3 Counters 84
2.5.2.3.4 Timers 87
2.5.2.3.5 Communication function blocks 88
2.5.3 Programs 89
2.6 Sequential Function Chart (SFC) elements 90
2.6.1 General 90
2.6.2 Steps 90
2.6.3 Transitions 93
2.6.4 Actions 96
2.6.4.1 Declaration 96
2.6.4.2 Association with steps 98
2.6.4.3 Action blocks 99
2.6.4.4 Action qualifiers 100
2.6.4.5 Action control 101
2.6.5 Rules of evolution 106
2.6.6 Compatibility of SFC elements 117
2.6.7 SFC Compliance requirements 118
2.7 Configuration elements 118
2.7.1 Configurations, resources, and access paths 120
2.7.2 Tasks 124
3. Textual languages 134
3.1 Common elements 134
3.2 Instruction list (IL) 134
3.2.1 Instructions 134
3.2.2 Operators, modifiers and operands 135
3.2.3 Functions and Function Blocks 137
3.3 Structured Text (ST) 141
3.3.1 Expressions 141
3.3.2 Statements 143
3.3.2.1 Assignment statements 144
3.3.2.2 Function and function block control statements 144
3.3.2.3 Selection statements 145
3.3.2.4 Iteration statements 145
4. Graphic languages 147
4.1 Common elements 147
4.1.1
Representation of lines and blocks 147
4.1.2 Direction of flow in networks 147
4.1.3 Evaluation of networks 149
4.1.4 Execution control elements 150
4.2 Ladder Diagram (LD) 152
4.2.1 Power rails 152
4.2.2 Link elements and states 152
4.2.3 Contacts 153
4.2.4 Coils 153
4.2.5 Functions and function blocks 153
4.2.6 Order of network evaluation 154
4.3 Function Block Diagram (FBD) 156
4.3.1 General 156
4.3.2 Combination of elements 156
4.3.3 Order of network evaluation 156
ANNEX A
Specification method for textual languages (normative) 157
A.1 Syntax 157
A.1.1 Terminal symbols 157
A.1.2 Non-terminal symbols 157
A.1.3 Production rules 158
A.2 Semantics 158
ANNEX B
Formal specifications of language elements (normative) 159
B.0 Programming model 159
B.1 Common elements 159
B.1.1
Letters, digits and identifiers 159
B.1.2 Constants 160
B.1.2.1 Numeric literals 160
B.1.2.2 Character strings 160
B.1.2.3
Time literals 161
B.1.2.3.1 Duration 161
B.1.2.3.2 Time of day and date 161
B.1.3 Data types 162
B.1.3.1 Elementary data types 162
B.1.3.2 Generic data types 162
B.1.3.3 Derived data types 163
B.1.4 Variables 164
B.1.4.1 Directly represented variables 164
B.1.4.2 Multi-element variables 165
B.1.4.3 Declaration and initialization 165
B.1.5 Program organization units 167
B.1.5.1 Functions 167
B.1.5.2 Function blocks 168
B.1.5.3 Programs 169
B.1.6 Sequential function chart elements 169
B.1.7 Configuration elements 170
B.2 Language IL (Instruction List) 172
B.2.1 Instructions and operands 172
B.2.2 Operators 173
B.3 Language ST (Structured Text) 173
B.3.1 Expressions 173
B.3.2 Statements 174
B.3.2.1 Assignment statements 174
B.3.2.2 Subprogram control statements 174
B.3.2.3 Selection statements 174
B.3.2.4 Iteration statements 175
ANNEX C
Delimiters and Keywords (normative) 176
ANNEX D
Implementation-dependent parameters (normative) 180
ANNEX E
Error Conditions (normative) 182
ANNEX F - Examples (informative) 184
F.1 Function WEIGH 184
F.2 Function block CMD_MONITOR 185
F.3 Function block FWD_REV_MON 188
F.4 Function block STACK_INT 194
F.5 Function block MIX_2_BRIX 199
F.6 Analog signal processing 203
F.6.1 Function block LAG1 204
F.6.2 Function block DELAY 205
F.6.3 Function block AVERAGE 206
F.6.4 Function block INTEGRAL 207
F.6.5 Function block DERIVATIVE 208
F.6.6 Function block HYSTERESIS 208
F.6.7 Function block LIMITS_ALARM 209
F.6.8 Structure ANALOG_LIMITS 209
F.6.9 Function block ANALOG_MONITOR 210
F.6.10
Function block PID 211
F.6.11
Function block DIFFEQ 212
F.6.12 Function block RAMP 213
F.6.13 Function block TRANSFER 214
F.7 Program GRAVEL 214
F.8 Program AGV 223
F.9 Use of enumerated data types 227
F.10 Function block RTC (Real Time Clock) 227
F.11 Function block ALRM_INT 228
ANNEX G
Index (informative) 229
ANNEX H
Reference character set (informative) 240

LIST OF TABLES

Table 1 - Character set features 24
Table 2 - Identifier features 25
Table 3 - Comment feature 26
Table 3a - Pragma feature 26
Table 4 - Numeric literals 27
Table 5 - Character string literal features 28
Table 6 - Two-character combinations in character strings 29
Table 7 - Duration literal features 30
Table 8 - Date and time of day literals 30
Table 9 - Examples of date and time of day literals 31
Table 10 - Elementary data types 32
Table 11 - Hierarchy of generic data types 34
Table 12 - Data type declaration features 35
Table 13 - Default initial values of elementary data types 36
Table 14 - Data type initial value declaration features 37
Table 15 - Location and size prefix features for directly represented variables 40
Table 16a - Variable declaration keywords 42
Table 16b - Usages of VAR_GLOBAL, VAR_EXTERNAL and CONSTANT declarations 43
Table 17 - Variable type assignment features 44
Table 18 - Variable initial value assignment features 46
Table 19 - Graphical negation of Boolean signals 51
Table 19a - Textual invocation of functions for formal and non-formal argument list 53
Table 20 - Use of EN input and ENO output 54
Table 20a - Function features 55
Table 21 - Typed and overloaded functions 57
Table 22 - Type conversion function features 60
Table 23 - Standard functions of one numeric variable 62
Table 24 - Standard arithmetic functions 63
Table 25 - Standard bit shift functions 64
Table 26 - Standard bitwise Boolean functions 65
Table 27 - Standard selection functionsd 66
Table 28 - Standard comparison functions 67
Table 29 - Standard character string functions 68
Table 30 - Functions of time data types 69
Table 31 - Functions of enumerated data types 71
Table 32 - Examples of function block I/O variable usage 74
Table 33 - Function block declaration and usage features 77
Table 34 - Standard bistable function blocks a 83
Table 35 - Standard edge detection function blocks 84
Table 36 - Standard counter function blocks 84
Table 37 - Standard timer function blocks 87
Table 38 - Standard timer function blocks - timing diagrams 87
Table 39 - Program declaration features 90
Table 40 - Step features 92
Table 41 - Transitions and transition conditions 94
Table 42 - Declaration of actions a,b 97
Table 43 - Step/action association 99
Table 44 - Action block features 100
Table 45 - Action qualifiers 101
Table 45a - Action control features 105
Table 46 - Sequence evolution 108
Table 47 - Compatible SFC features 118
Table 48 - SFC minimal compliance requirements 118
Table 49 - Configuration and resource declaration features 122
Table 50 - Task features 126
Table 51a - Examples of instruction fields 135
Table 51b - Parenthesized expression features for IL language 136
Table 52 - Instruction List operators 136
Table 53 - Function Block invocation and Function invocation features for IL language 138
Table 54 - Standard Function Block input operators for IL language 140
Table 55 - Operators of the ST language 142
Table 56 - ST language statements 143
Table 57 - Representation of lines and blocks 148
Table 58 - Graphic execution control elements 151
Table 59 - Power rails 152
Table 60 - Link elements 153
Table 61 - Contacts a 154
Table 62 - Coils 155
Table C.1 - Delimiters 176
Table C.2 - Keywords 177
Table D.1 - Implementation-dependent parameters 180
Table E.1 - Error conditions 182
Table H.1 - Character representations 240
Table H.2 - Character encodings 241

LIST OF FIGURES

Figure 1 - Software model 15
Figure 2a - Data flow connection within a program 16
Figure 2b - Communication via GLOBAL variables 17
Figure 2c - Communication function blocks 17
Figure 2d - Communication via access paths 18
Figure 3 - Combination of programmable controller language elements 20
Figure 4 - Examples of function usage 48
Figure 5 - Use of formal argument names 52
Figure 6 - Examples of function declarations and usage 56
Figure 7 - Examples of explicit type conversion with overloaded functions 58
Figure 8 - Examples of explicit type conversion with typed functions 59
Figure 9 - Function block instantiation examples 73
Figure 10 - Examples of function block declarations 77
Figure 11a - Graphical use of a function block name as an input variable 79
Figure 11b - Graphical use of a function block name as an in-out variable 80
Figure 11c - Graphical use of a function block name as an external variable 81
Figure 12 - Declaration and usage of in-out variables in function blocks 82
Figure 14 - ACTION_CONTROL function block - External interface(Not visible to the user) 102
Figure 15a - ACTION_CONTROL function block body with "final scan" logic 103
Figure 15b - ACTION_CONTROL function block body without "final scan" logic 104
Figure 16a - Action control example - SFC representation 105
Figure 16b - Action control example - functional equivalent 106
Figure 17 - Examples of SFC evolution rules 114
Figure 18a - Examples of SFC errors: an "unsafe" SFC 116
Figure 18b - Examples of SFC errors: an "unreachable" SFC 117
Figure 19a - Graphical example of a configuration 119
Figure 19b - Skeleton function block and program declarations for configuration example 120
Figure 20 - Examples of CONFIGURATION and RESOURCE declaration features 123
Figure 21a - Synchronization of function blocks with explicit task associations 131
Figure 21b - Synchronization of function blocks with implicit task associations 132
Figure 21c - Explicit task associations equivalent to figure 21b 133
Figure 22 - EXIT statement example 146
Figure 23 - Feedback path example 150
Figure 24 - Boolean OR Examples 156