You are on page 1of 17

Programming PLCs using Sequential Function Chart

Martin Bruggink
Department of Computing Science, University of Nijmegen
Toernooiveld 1, NL-6525 ED, Nijmegen, The Netherlands
martinb@sci.kun.nl

Nijmegen, January 1999


Key words: Programmable logic control, IEC 1131-3 standard,
sequential function chart, Petri net.
Abstract
In designing PLCs (Programmable Logic Controllers) many
companies have used a lot of different languages. In the desire to
improve the capability of these PLCs, these languages have
become more complex. This is in contradiction with one of the
main goals of PLCs, which is that PLC are relative simple systems
because it is very import that a PLC is reliable.
That is why a standard has been developed, called the IEC
1131-3 standard. This standard describes 5 languages for
programming PLCs. In this article I will study Sequential Function
Chart (SFC), which is one of the 5 languages of the standard. SFC
is mainly based on Petri net with a few adjustments in order to
make communication with the other languages possible. I will
make a comparison between Petri net and SFC and will look at
how a SFC diagram can be turned into a Petri net. By doing this
some things can be said about the reachable states of the system
being modelled.

1 Introduction to PLC
The programmable logic controllers (PLC) market is growing. PLCs are the backbone of most
automation projects of the process control and instrumentation sector. They are being used in many
places where some kind of control is needed to run a real-time system. For example, PLCs are being
used in complex petro-chemical plants, smelting furnaces, automobile production lines and so on.
Because PLCs are being used to control real-time systems they have to be reliable and robust. If a
system doesn't work properly, this could result in high financial losses. This is why the progress in the
development of PLCs is so low. It is a big risk to try to improve PLCs. When new PLCs are being
introduced, we want to be sure that the new controller is reliable and robust. Producers are confronted
with the question whether or not to install new PLCs. The old system is reliable, because it has been

working for some time. But the performance of that system wouldn't be as high as when new PLCs
were installed. On the other hand, can we rely on the new PLCs? Are they reliable and robust?
In the design of the first PLCs two characteristics were very important. First, a PLC has to be fast.
They are being used in real-time systems and the controller sometimes has to react within fractions of
a second. Secondly, a PLC shouldnt be to complicated. A simple PLC is easier to program and gives
more insights in its structure. So, a simple PLC is more reliable. Strangely enough, these
characteristics don't apply any more for the PLCs of today. Although they are still very fast, they have
become very complex. Multiprocessor PLCs have been introduced. PLCs can be used in distributed
networks. Some of the current PLCs look like small computers. This is all hardware design.
Of course, software is also needed. This brings us to the programming languages. Many
programming languages have been developed for programming PLCs. Each manufacturer has its own
language. These languages are sometime in contradiction with techniques developed in the computing
world. To improve the software used in PLCs, the International Electrotechnical Commission (IEC)
has tried to define a standard for programming languages which is called IEC 1131-3. The IEC 1131-3
standard tries to bring together the languages from the PLC world and the computing world.

1.1 The use of PLCs


PLCs are being used in real-time systems. A PLC controls these systems by using actors and sensors.
A sensor, for example, tells us whether or not a tank is full. If the tank is full, the sensor's signal is on,
otherwise off.
An actor, for example, is used for opening and closing a valve. When the valve is open, the tank
will be filled. The PLC controls the actor and receives input from the sensors. These signals don't
always have to be two-state signals. Some PLCs can handle other signals as well.
The advantage of the PLC is its flexibility, as programs can be modified relatively easily and
quickly. The disadvantage is that there is a certain delay between the changes of input and output
signals. When using hardwired logic such delays wouldn't occur.

2 The IEC 1131-3 standard


One of the goals of the IEC standardisation of programming PLCs is working towards an open system.
At IEC they say, the industrial instrumentation and control systems need an open systems approach to
build large systems using equipment from different manufacturers. In an open system manufacturers
can exchange software, by all using a standard language for programming PLCs [1].
Not everyone agrees with the idea of defining a standard for programming PLCs. In his article [6],
Kenneth C. Crater states that the entire concept of a standardized suite of languages, presumably to
become the accepted PLC programming languages, is flawed and works against the interest of the
user base. He also states that if such an idea were to have any validity, the IEC Standard is
retrogressive and specific to the point of mediocrity.
Before we begin to describe these languages (there are actually five languages described in the
standard), lets look how PLCs were programmed before.
Because PLCs have evolved from hardwired controls, ladder programming was a very popular way
for programming. Ladder programming is based on electrical wiring diagrams. In these diagrams one
can see how the electricity runs through the control scheme. An example of a ladder diagram is shown
in figure 1.
The basic programming skills needed to develop small applications using ladder programs can be
learnt relatively quickly and the graphical presentation can be understood almost intuitively. The
technique is particularly easy to understand by people who are familiar with simple electronic or
electrical circuits. Consequently, it is well accepted by electricians and plant technicians.

Figure 1 A ladder diagram


But, ladder programming also has a few disadvantages. First, it is difficult to form hierarchical
programs. There are generally very limited facilities for passing parameters between program blocks.
Secondly, it is not suitable for software re-use. When some kind of software is needed in several
places in the program, many of the same ladder diagrams will show up in a program, having only
minor modifications. One can reduce the size of a program by writing this code in some kind of
module and only call the module in the several places. Another shortcoming of ladder diagrams is that
it is not possible to use data structures. With many complex applications, there is usually a need to
group data together as a structure. With ladder diagrams such data is often spread out throughout the
PLC memory, making it very likely that a data violations occurs. These are only a few shortcomings
of using ladder diagrams.

2.1 Program languages in the IEC 1131-3 stan dard.


In the standard five different languages are defined. It is of course very doubtful whether or not this
qualifies as a standard. The five languages are a kind of average of all languages used in the PLC
industry. Each of these five languages can be used to describe parts of the program. They can all be
connected with each other.
The five languages are structured text, instruction list, ladder diagram, function block diagram and
sequential function charts. The first two are textual languages and the other three are graphical. We
will now shortly discuss these languages, except for ladder diagrams, which already has been
discussed in the previous chapter.

2.1.1 Structured text


Structured text (ST) looks a lot like Pascal. An example is shown in figure 2.
IF SPEED1>100.0 THEN
Flow_Rate := 50.0 + Offset_A1;
ELSE
Flow_Rate := 100.0; Steam := ON;
END_IF;
Figure 2 An example of structured text

2.1.2 Instruction list


Instruction list (IL) is a kind of assembler language. It is based on similar languages found in a wide
range of todays PLCs. An example is given in figure 3.

RESET:

LD
JMPC
LD
ST
LD
ST

R1
RESET
PRESS_1
MAX_PRESS
0
A_X43

Figure 3 An example of instruction list

2.1.3 Function block diagram


Function block diagram (FBD) is a graphical language. In function block diagrams function are
depicted as some kind of chip, with input ports and output ports. Ports from different function blocks
can be connected with each other or with variables. It is very useful for writing re-usable software.

2.1.4 Sequential function chart


Sequential function chart is a graphical language for depicting sequential behaviour of a control
system. It is used for defining control sequences that are time- and event-driven. This language will be
discussed more later on.

2.2 IEC 1131-3 concepts


The IEC standard [1] allows programs to be decomposed in small manageable parts. The IEC software
model is layered. Each layer hides many of the features of the layers beneath it. We will now look at
how these layers are used to build software.
At the highest level, the software for a particular control problem is contained in a configuration.
Existing at the outer layer of the entire PLC software model, a configuration is defined as a language
element that corresponds to the programmable controller system. A configuration is able to
communicate with other IEC configurations within different PLC systems via defined interfaces.
Within each configuration there are one or more resources. A resource provides support for all of
the features needed for the execution of programs. The main function of a resource is to provide a
support system to run programs. An IEC program cannot function unless it is loaded into a resource.
One of the main functions of a resource is to provide an interface between a program and the physical
I/O channels of the PLC.
A program can be built from a number of different software elements, each of which may be
written in any one of the different five languages. The execution of different parts of a program, for
example selected function blocks, may be controlled using tasks.
A task can be configured to control a set of programs and/or function blocks either to execute
periodically or upon the occurrence of a specified trigger.
The use of function blocks makes it possible to support hierarchical design. It is possible to create a
program from smaller more manageable blocks. Because a function block is able to store values, it has
a defined state. The standard also specifies the use of functions. Functions are a bit like function
blocks, except that they don't have an internal state and thus, they are deterministic.

2.2.1 Internal communication


Various mechanisms are provided to enable information to be exchanged between program
organisation units, i.e. between programs, function blocks and functions. One way is to connect
function block graphically and form a kind of network. Values of variables can be passed from
function block outputs to function block inputs. Functions can also be used to modify values or
produce derived values to be passed on to other functions or function blocks.
At the program level, program inputs can be used to pass data into internal functions and function
blocks from external variables. Generally program inputs will be connected to variables that are
associated with data coming from physical devices, such as PLC input sensors.

Global variables can also be used to exchange data between function blocks and other program
organisation units. Global variables can be defined at the configuration, resource or program level.
Global variables are accessible to all program organisation units contained within the parent entity in
which they are declared.
The standard also specifies ways for communication between configurations. We won't deal with
them here.

2.2.2 Common elements of the standard


The standard defines a large number of common features and elements that apply to all the
programming languages. The internal behaviour of program organisation units, i.e. program, function
blocks and functions, can be described using any one of the five different languages.
A diverse range of data types and functions suitable for developing most types of applications is
defined. These include types dealing with date and time, floating point representation, strings and of
course booleans and integers. It is also possible to form new datatypes.
The standard also defines a wide range of standard functions, for manipulating strings, bits, and all
of the other standard datatypes mentioned before. It also contains many numerical functions.

3 Sequential Function Chart


Sequential function chart (SFC) is a graphical language, which makes it possible to depict sequential
behaviour. It is very much based on Grafcet, a graphical language based on a French national standard.
Grafcet has evolved from Petri net as an industrial form of the methodology. We will look at the
comparisons between SFC and Petri net later.
One of the most important aspects of SFC is that it shows the main states of a system, all the
possible changes of state and the reasons why those changes would occur. It can be used at the top
level to show the main phases of a process, but it can also be used at any other lower level.
A SFC consists of the following elements.
A number of steps; these steps are being depicted by rectangular boxes. Each step represents a
particular state of the system being controlled. At least one of these steps is the initial step, which
is depicted by a rectangular box containing vertical bars. The initial step is the first step to be
activated whenever a SFC is started.
The steps are connected by transitions. A line between two steps depicts a transistion. Each
transition is associated with a condition. When a condition following an active step becomes true,
this results in the next step being activated and the active step becoming deactivated.
Each step is associated with some action, performed while the step is active. Actions can be
described by any of the five languages defined by the IEC 1131-3 standard.
Transitions can either be described directly on the sequential function chart using ST, FBD or LD
or can be described on an associated diagram using any of the languages ST, FBD, LD or IL, in which
case the definition is associated with the name of the transition.

Figure 4 A sequential function chart

3.1 Divergent and convergent sequences


Steps dont always become activated in the same sequence. It is possible to create divergent and
convergent paths. A divergent sequence is created by making two or more transition following one
step. When the step is active and a condition associated with one of the transitions becomes true, the
step will be deactivated and the step following the transition with the true condition becomes active.
Normally, transition conditions are tested from left to right. It is possible to define an order in
which the transitions are tested.
A divergent sequence can rejoin another sequence using a convergent path. Any number of
divergent and convergent paths can be used in a SFC.
Using this method for describing divergent and convergent sequences, it is not possible to define
simultaneous sequences. This is possible though using SFC. A simultaneous divergent sequence is
depicted by two horizontal lines.

Figure 5 Simultaneous sequences


One has to be very careful using divergent and convergent sequences though. It is possible that a
kind of deadlock occurs, when not all divergent sequences are being rejoined by convergent paths. We
will look at this later.

3.2 Actions
A we saw before, steps describe the state of the system being represented. In a real system, each step is
required to perform certain control actions that are applicable for that particular state.
In SFC methodology, every step can be associated with one or more actions. An action contains a
description of some behaviour that should occur as a result of the step being activated. The description
of an action can be given using any of the IEC languages.
Actions can be depicted in SFC language by an action box, which is connected with the particularly
step. An action box consists of three parts: the action qualifier, the action and the indicator variable,
which is optional.
The action contains a description of the actions being performed when the associated step is active.
This can be the name of some actions described some where else in the program, or it can be a
description of the action in one of the five languages. The qualifier determines when the action is
executed. For example, the action could be executed again and again, while the associated step is
active, or the action could only be executed when the step becomes deactivated. We will see later
which qualifiers are defined in the standard.
The indicator variable is optional. This is only used for annotation purposes. The indicator variable
names a key variable that is changed by the action and indicates that the action has completed its
execution.

3.2.1 Action qualifiers


The standard defines a range of qualifiers which define precisely when a particular action executes in
relation to its associated step. There are about 10 action qualifiers.

Qualifier
None
R
S
L
D
P
SD

DS
SL

Description
Non-stored, default, same as N
Resets a stored action
Sets an action active, i.e. stored
Time limited action, terminates after a given period
Time delayed action, starts after a given period
A pulse action that only executes once when a step is activated,
and once when the step is deactivated
Stored and time delayed. The action is set active after a given
period, even if the associated step is deactivated before the
delay period
Action is time delayed and stored. If the associated step is
deactivated before the delay period, the action is not stored.
Stored and time limited. The action is started and executes for
a given period

Table 1 Action qualifiers


As an example we will look at the use of the N and DS qualifier. Figure 6 shows the use of the N
qualifier. StepA is associated with an action box. When StepA is active, Action1 will be executed
repeatedly, until StepA is deactivated. This happens when condition T1 becomes true. Then Action1
will be executed one more time.
The figure also shows a time diagram. This shows whether or not variables are true and whether or
not action is being executed or not. StepA.X is a variable, which is true only when StepA is activated. It
will be false when StepA is deactivated. As you can see, Action1 is executed while StepA.X is true.
When T1 becomes true, StepA becomes deactivated and StepA.X becomes false. Action1 will be
executed one more time.

Figure 6 The use of the N qualifier


Now, lets look at a more difficult example, the use of the DS qualifier. The DS qualifier is used in
the action box associated with Step1. A time indicator has to be given, which indicates what delay
time is used, in this case 4 seconds. Action1 is not directly executed when Step1 becomes activated.
This happens 4 seconds after Step1 has been activated. Then Action1 is stored and activated. This
means that it will be executing until it is reset.
When T1 becomes true and Step1 will be deactivated, Action1 will not be executed at all.

Figure 7 The use of the DS qualifier


One has to be very careful using the action qualifiers. It sometimes isn't clear how execution will be
performed using the more difficult action qualifiers like DS and SL. Also, all actions are executed one
more time after the associated step becomes deactivated. Sometimes an action isn't executed at all,
even when the associated step has been activated for some time. For example, consider the DS
qualifier is used with delayed time of 4 seconds. If the associated step is deactivated within 4 seconds,
the actions won't be executed at all.

4 Comparison with Petri net


As said, sequential function charts are very much based on Petri net [3]. Petri nets were developed by
Carl Adam Petri for describing the causal relationships between events. Petri nets are used for
modelling systems with interacting concurrent components.
We will now look at a definition of a Petri net which shows very much resemblance with SFC [2].
A Petri net consists of four parts: a set of places P, a set of transitions T, an input function I, and an
output function O. The input and output functions relate transitions and places. The input function I is
a mapping from a transition tj to a collection of places I(tj), known as the input places of the transition.
The output function O maps a transition tj to a collection of places O(tj) known as the output places of
the transition.
The structure of a Petri net is defined by its places, transitions, input function, and output function.
A Petri net structure, C, is a four-tuple, C=(P,T,I,O). P={p1,p2,....,pn} is a finite set of places, n >=
0. T = {t1,t2,...,tm} is a finite set of transitions, m >= 0. The set of places and the set of transitions are
disjoint, P U = .
I:T P is the input function, a mapping from transitions to a set of places. O:T P is the
output function, a mapping from transitions to a set of places.
An example is shown below.
C = (P,T,I,O)
P = {p1,p2,p3,p4,p5}
T = {t1,t2,t3,t4}
I(t1) = {p1}
I(t2) = {p2,p3,p5}
I(t3) = {p3}
I(t4) = {p4}

O(t1) = {p2,p3,p5}
O(t2) = {p5}
O(t3) = {p4}
O(t4) = {p2,p3}

4.1 Petri net graphs


A Petri net can be graphical represented. A graphical representation of a Petri net structure is much
more useful for illustrating the concepts of Petri net theory. A Petri net graph is a representation of a
Petri net structure as a bipartite directed graph.
In a Petri net graph a circle represents a place and a bar represents a transition. Directed arcs
connect the places and the transitions, with some arcs directed from the places to the transitions and
other arcs directed from transitions to places. An arc directed from a place to a transition defines the
place to be an input of the transition. An output place is indicated by an arc from the transition to the
place. Again, multiple outputs are represented by multiple arcs.

Figure 8 A Petri net graph


Now the resemblance between Petri net and SFC is quite simple. Let's look at the graph in figure 8.
The associated Petri graph is depicted in figure 9.
The Petri net graph is easily turned into a Petri net structure.
C = (P,T,I,O)
P = {p1,p2,p3,p4,p5,p6}
T = {t1,t2,t3,t4,t5,t6,t7}
I(t1) = {p1}
I(t2) = {p2}
I(t3) = {p2}
I(t4) = {p3}
I(t5) = {p4}
I(t6) = {p6}
I(t7) = {p6}

O(t1) = {p2}
O(t2) = {p3}
O(t3) = {p4}
O(t4) = {p5}
O(t5) = {p5}
O(t6) = {p6}
O(t7) = {p2}

The Petri net and the SFC are related to each other in the following way:
p1 = Start
p2 = Fill
p3 = Stir
p4 = Filter
p5 = Drain
p6 = Stop

t1 = StartSwitch = 1
t2 = Tran2
t3 = Tran3
t4 = Tran4
t5 = Tran5
t6 = StartSwitch = 0
t7 = StartSwitch = 1

Figure 9 The associated Petri graph of figure 4

4.2 Petri net markings


A marking u is an assignment of tokens to the places of a Petri net. Tokens are assigned to, and can be
thought to reside in, the places of a Petri net. The number and position of tokens may change during
the execution of a Petri net. The tokens are used to define the execution of a Petri net.
Definition: A marking u of a Petri net C=(P,T,I,O) is a function from the set of places P to the Boolean
set {0,1}: :PB
In a Petri net graph, tokens are represented by small dots in the circles which represent the places
of a Petri net.
The use of tokens is to define the places that are active. Places that contain a token can be
compared to a step that is active. When a SFC is first executed, the initial step becomes active. In other
words a token is being placed in the associated step.
Tokens can be propagated from one place to another during executing. We will now look at the
execution rules.

Figure 10 Petri graph with a marking in p2

4.3 Execution rules for Petri nets


A Petri net executes by firing transitions. A transition fires by removing tokens from its input places
and creating new tokens which are distributed to its output places.
A transition may fire if it is enabled. A transition is enabled if all input places of the particular
transition have a token.
A transition fires by removing all of its enabling tokens from its input places and then depositing a
token into each of its output places. Firing a transition will generally change the marking u of the Petri
net to a new marking u'.

4.4 Petri Net State Spaces


The state of a Petri net is defined by its marking. The firing of a transition represents a change in
the state of the Petri net by a change in the marking of the net. The state space of a Petri net with n
places is the set of all possible markings.
The change in state caused by firing a transition is defined by a change function called the nextstate function. When applied to a marking (state) and a transition tj this function yields the new
marking (state) which results from firing transition tj in marking . This function is only defined if tj is
enabled in marking .
A marking ' is immediately reachable from if there exists a transition tj T such that (,tj) = '.
We can extend this concept to define the set of reachable markings for a given marked Petri net. If
is
' immediately reachable from and " is immediately reachable from ', then " is reachable from
. We define the reachability set R(C,) of a Petri net C with marking u to be all markings which are
reachable from .
The reachability set thus defines all possible states the Petri net could reach.

Figure 11 The Petri net graph after firing transition t2


By translating a SFC into a Petri net, one can get a better idea of which state space can be reached
with a certain Petri net structure and it's initial marking function.
A Petri net composed from a SFC has the following properties [5]:
At no moment can an active step be such that one of its input transitions is firable, and one of
its output transistions is simultaneously firable (the SFC is not reactivable).
For any pair of transistions which are simultaneously firable, they have no input step in
common.
No step can have two simultaneously firable input transistions.
One has to be very careful not to define a SFC, which doesnt have these properties. We will now
look at an example of an unreachable SFC.

5 Unreachable SFC
We will now look at an example of a SFC diagram, figure 12. In this SFC the Stop step will never be
activated. Because the diagram has a non-simultaneous divergence sequence, stepC and StepD will
never be activated at the same time. Because StepC and StepD are followed by a simultaneous
convergent sequence, the Stop step will never be reached.
Now lets convert the SFC diagram to a Petri net. This Petri net has the following structure.
C = (P,T,I,O)
P = {p1,p2,p3,p4,p5,p6,p7p8p9}
T = {t1,t2,t3,t4,t5,t6,t7}
I(t1) = {p1}
I(t2) = {p2}
I(t3) = {p3}
I(t4) = {p4}

O(t1) = {p2 ,p3}


O(t2) = {p4}
O(t3) = {p5}
O(t4) = {p6}

I(t5) = {p5}
I(t6) = {p5}
I(t7) = {p6,p7,p8}

O(t5) = {p7}
O(t6) = {p8}
O(t7) = {p9}

Figure 12 An unreachable SFC


The Petri net and the SFC are related to each other in the following way:
p1 = Start
p2 = Step1
p3 = StepA
p4 = Step2
p5 = StepB
p6 = Step3
p7 = StepC
p8 = StepD
p9 = Stop

t1 = StartSwitch = 1
t2 = Tran1
t3 = TranA
t4 = Tran2
t5 = TranB
t6 = TranC
t7 = TranD

When the SFC is executed, the Start step will be activated. So in the Petri net a marking is put in
p1. So the marking function of this Petri net is as follows.
= {(p1,1),(p2,0) ,(p3,0) ,(p4,0) ,(p5,0) ,(p6,0) ,(p7,0)}
Lets look what happens when t1 is fired. t1 is enabled because all of its input places have a
marking. The function gives us the next marking function when firing t1.
(,t1) =
= {(p1,0),(p2,1) ,(p3,1) ,(p4,0) ,(p5,0) ,(p6,0) ,(p7,0)}

Figure 13 The associated Petri graph of figure 12


The reachability set R of this Petri net and marking is the set of all markings that can be reached.
So at least is a element of R. We can compute R by releasing all reached markings and all enabled
transitions on the function. In , transition t2 and t3 are enabled. Now we can compose new
markings, which are elements of R.
(,t2) = {(p1,0),(p2,0) ,(p3,1) ,(p4,1) ,(p5,0) ,(p6,0) ,(p7,0)}
(,t3) = {(p1,0),(p2,1) ,(p3,0) ,(p4,0) ,(p5,1) ,(p6,0) ,(p7,0)}
The marking in which p9 has a marking is not an element of R:
= {(p1,0),(p2,1) ,(p3,1) ,(p4,0) ,(p5,0) ,(p6,0) ,(p7,0)} R
So is not reachable from . This means that, as we concluded before, the Stop step in the
associated SFC will never be activated. Because the set R can sometime be very large it is not always
possible to just write down all element of R. Using an occurrence net it is possible to see which
markings are elements of R. We will not deal with this here.
When programming in SFC one has to be very careful. It is very well possible that a SFC doesnt
perform the way as expected. By transferring a SFC into a Petri net it is possible to calculate the states
which can be reached in an SFC. This way it is much easier to predict the behavior of the system being
modeled by the SFC diagram.
Of course by computing the reachability set of a certain Petri net, one can still not be sure the
associated SFC will perform the way one would expect. For example, one also has to make sure that

an active step cannot have both a firable input transistion and a firable output transistion. How this can
be done is, will not be dealt with here.

References
[1] R.W. Lewis, Programming industrial control systems using IEC 1131-3, The Institution of
Electrical Engineers, London, 1995.
[2] Wolfgang A. Halang & Krzystof M. Sacha, Real Time Systems Implementation of Industrial
Computeriezed Process Automation, World Scientific.
[3] James L. Peterson, Petri net theory and the modeling of systems, Prentice-Hall Inc, Englewood
Cliffs, N.J. 07632, 1981.
[4] W.Reisig, Petrinetze Eine Einfrung, Springer-Verlag, Berlin Heidelberg New York, 1982.
[5] Ren David, IEEE Transistions on control systems technology, 3: 253- 268, september 1995.
[6] Kenneth C. Crater, President Control Technology Corporation Hopkinton, MA, When Technology
Standards Become Counterproductive.

You might also like