10 1 1 49 2016
10 1 1 49 2016
Nieke Roos
Department of Computing Science
University of Nijmegen
Toernooiveld 1, NL-6525 ED, Nijmegen, The Netherlands
nieker@sci.kun.nl
Keywords: Programmable Logic Controller, PLC, Structured Text, ST,
Pascal
Abstract
An ever increasing part of the industrial and safety-critical
processes is presently controlled by Programmable Logic
Controllers (PLCs). As its name already suggests, a PLC can be
and has to be programmed to perform its task. Since its birth, a
wide range of different PLCs has been put on the market that
makes use of an even wider range of programming languages.
Recently, the IEC 1131-3 standard has been published in an effort
to reduce chaos to order in the universe of PLC programming
languages.
This paper takes a closer look at one of the programming
languages defined by the IEC 1131-3 standard, namely the
Structured Text programming language. A comparison is made
between Structured Text and the language upon which it was
based, the Pascal programming language. The primary differences
that result from this comparison are then discussed and some
conclusions are drawn about the IEC 1131-3 standard.
1 The Programmable Logic Controller
1.1 Introduction
As the Industrial Revolution stormed the civilized world late last century man started to create
machines that could alleviate the hard labour some existing tasks brought with them. This very first
large-scale reflection of mans desire to be able to automate was the incentive to an evolutionary
developement of industrially employed equipment. The first machines ran on steam, later on gasoline
was used as primary source of energy and at present the majority of the devices in the industry is
powered by electricity. At the same time the dimensions of these devices decreased from steam
engines the size of an average suburban dwelling to electrical appliances not bigger than a lunchbox
containing even smaller circuits and wiring.
The invention of the computer and its massive application following the Digital Revolution taking
place in the 1960s, gave birth to a new phenomenon: the art of programming. This revolutionary
ability to control the behaviour of an apparatus by precisely conveying the actions it has to perform
exerted enormous influences not only on the computer science domain but on other domains as well.
An important and interesting example of the influence programmability has had on other domains is
the Programmable Logic Controller (PLC), resulting from the synthesis of the electrical world and the
universe of computer science in an effort to combine this programmability with electrical circuitry.
1.2 The architecture
The primary purpose of a PLC is to control a particular process or collection of processes in industrial
or other safety-critical applications. This system of processes has certain properties, which are to be
controlled by the PLC. These properties are communicated to the PLC through digitized analogue
signals directly or indirectly emanating from the system. In response to these inputs the PLC produces
electrical control signals that are fed back to the system. The main task of a PLC, therefore, is to
convert the inputs received to particular related outputs.
1.2.1 The hardware
In essence, the PLC is a miniaturized version of a general-purpose computer. Like its big brother, its
structure can be divided into a hardware-part and a software-part. As depicted in Figure 1, the PLCs
hardware is composed of:
an input interface,
an output interface,
a program memory,
a data memory, and
a processor.
PLC
Program
memory
Processor
Output
interface
Data
memory
Input
interface
Instruction
s
m
i
i
1
n
o
o
Function Block
Function
Function
Statements
Function Block
Function Block
Function
Function
Statements Statements
Function
Function
Function Block
Function Block
3.1 The language constructs
One of the problems concerning Structured Text within the framework of the IEC 1131-3 standard is
determining exactly what is part of the language and what is not. The standard defines Structured Text
to be just the statements that can be used to construct function and function block algorithms and
program bodies. However, within the standard, elements common to all five programming languages
defined in the standard, such as elements that identify, for instance, a configuration, a resource or a
program and the declaration of variables, are written using a syntax that also resembles the Pascal
syntax in such a way that many of the people that have applied the standard have unjustly regarded
these common elements as being part of the Structured Text programming language as well, in spite of
the standard. Clearly, the standard isnt as clear on this as one would like a standard to be.
A comprehensive context-free description of the syntax of the language constructs that, according
to the IEC 1131-3 standard, do belong to the Structured Text programming language is included in
appendix A.
3.2 Data types
Like almost every other programming language, the IEC 1131-3 standard also allows the use of a
variety of different types of data in Structured Text programs, both elementary and derived.
3.2.1 Elementary data types
The elementary data types provided by the standard are the following:
Integers
Floating point numbers
Data types that represent time
Strings
Bit strings
3.2.1.1 Integers
IEC Data type Description Range
SINT Short integer -128 +127
INT Integer -32768 +32767
DINT Double integer -2
31
+2
31
-1
LINT Long integer -2
63
+2
63
-1
USINT Unsigned short integer 0 +255
UINT Unsigned integer 0 +2
16
-1
UDINT Unsigned double integer 0 +2
32
-1
ULINT Unsigned long integer 0 +2
64
-1
Table 1: Integer data types
Examples: -18, 0, 1977 (decimal), 2#00010010 (binary), 8#22 (octal), 16#12 (hexadecimal)
3.2.1.2 Floating point numbers
IEC Data type Description Range
REAL Real numbers 10
38
LREAL Long real numbers 10
308
Table 2: Floating point data types
Examples: 18.7, 18.7E-77, 0,19e+77
3.2.1.3 Data types that represent time
IEC Data type Description Examples
TIME The duration of time
after an event
T#18d7h19m7s7ms
TIME#18h7s
DATE Calendar date D#1977-07-18
DATE#1977-07-18
TIME_OF_DAY Time of day TOD#18:07:19
TIME_OF_DAY#23:59:59.99
DATE_AND_TIME Date and time of day DT#1977-07-18-18:07:19.77
DATE_AND_TIME#1977-07-18-12:00:00
Table 3: Time data types
3.2.1.4 Strings
IEC Data type Description Examples
STRING Character strings Hello world