is a Boolean function over the set of flip-flops
used for coding of states, such that it is true in
state s if and only if s
∈
τ
S
(t).
5. Defining function
next_state consistently with
function
δ
. This function defines the set and reset
signals of flip-flops, which have been used for
coding of states. The signal to set (reset) a flip-
flop is a Boolean function over the set of flip-
flops, input signals of PLC and output signal of
timer blocks, such that it is true if and only if this
flip-flop is set (reset) in the next state of FSTM.
6. Defining function
count_output consistently
with function
ω
. This function defines the values
of output signals of PLC. The value of an output
signal is a Boolean function over the set of flip-
flops, such that it is true if and only if this output
signal is set in the current state of FSTM.
Example. To capture four trains within the crossing,
we need four approach and four leave input signals
from trains, plus two up and down input signals from
the gate (Figure 5). There are four green signals
output to semaphores, two signals open and close to
the gate and a sound output signal. Any combination
of the input (output) signals corresponds to an input
(output) symbol. PLC controller stores the locations
as states of its internal flip-flops. At least three flip-
flops are needed. A selected coding for states and
output signals of the controller is shown in Table 1.
Table 1: The coding of states and output signals.
M1 M2 M3 a[i] State close open green(i) sound
0 0 0 0 Outside 0 0 0 0
0 1 0 a(i) Entering 1 0 0 0
1 1 0 a(i) Inside 0 0 a(i) 0
1 0 0 0 Leaving 0 1 0 0
0 1 1 a(i) Alarm 1 0 0 1
The program for PLC is a ladder diagram (IEC,
1993) consisting of a sequence of lines, each of
which describes a Boolean expression to set or reset
a flip-flop or an output signal, to activate a timer, or
to call a function block to operate a variable,
according to the values of input signals, states of
flip-flops, variables and timers. The expressions
reflect the coding of locations and implement the
functions
active_timers, next_state and
count_output described in Section 2. An example
is shown in Figure 6, which presents the transitions
from Entering to Alarm and from Entering to Inside
(Figure 5). M11 and M13 are auxiliary flip-flops,
which mirror the main flip-flops M1 and M3, in
order to assure atomicity of the transitions.
Figure 6: A fragment of the ladder diagram program for
the railroad crossing controller.
6 CONCLUSIONS
A method is described for the specification,
verification and automatic generation of code for
PLC controllers. The advantages of the method are
intuitive modeling by means of a widely accepted
UML state machine, and a potential for automatic
verification and implementation of the model.
A tool which implements the steps of the method
has been implemented and verified on small scale
examples. The verification included experiments in a
lab equipped with a few process models and a set of
S7 PLC controllers from Siemens.
REFERENCES
Alur R., Dill D., 1996. Automata-theoretic verification of
real-time systems. In Formal Methods for Real-Time
Computing, Trends in Software Series, John Wiley.
Behrmann G., David A., Larsen K.G, 2004. A Tutorial on
Uppaal, Aalborg University.
Dierks, H., 1997. PLC-Automata: A New Class of
Implementable Real-Time Automata. LNCS 1231.
Springer, Berlin.
IEC, 1993. Programmable controllers – part 3:
Programming languages.
Kaynar D.K., Lynch N.A., Segala R., Vaandrager F.W.,
2006. The Theory of Timed I/O Automata. Synthesis
Lecture on Computer Science, Morgan & Claypool.
Krcal P., Mokrushin L., Thiagarajan P.S., Wang Yi. 2004.
Timed vs. Time Triggered Automata. LNCS 3170,
Springer-Verlag, Heidelberg.
OMG, 2005. Unified Modelling Language: Superstructure,
version 2.0.
Sacha K., 2007. Translatable Finite State Time Machine.
LNCS 4745, Springer, Berlin.
Sacha K., 2008. Model-Based Implementation of Real-
Time Systems. LNCS 5219, Springer, Berlin.
M1 M2
S
11
M2
TON
IN
M1
M3
down
M1 M2
S
13
M3
T
MOV_B
EN
IN
a
green
MODEL-BASED DESIGN OF CODE FOR PLC CONTROLLERS
135