You are on page 1of 9

Industrial Process Automation, Exercise3: PLC (Programmable

INSTITUTE
Logic
OF
Controller)

AUTOMATION SYSTEMS
Prof. Dr.-Ing. Wolfgang Meyer

Industrial Process Automation (Exercise)


PLC (Programmable Logic Controller)

PLC design
Introduction to the PLC environment CoDeSys
Implementation of the traffic light state graph as
Sequential Function Chart (SFC)
Instruction List (IL)

Literature:
[Lewis, 95]

R. W. Lewis; Programming industrial control systems using


IEC 1131-3; Inst. of Electrical Engineers; London; 1995
1

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

Revision: Functionality of a PLC


(Permanent) cyclic run:
Most PLCs execute a cyclic scan continuously. The cycle starts with the hardware I/O
system gathering the latest values of all input signals and storing their values in fixed
regions in memory. Then the PLC program is executed. New values for physical
outputs as determined by the PLC program are written to an output memory region.
Finally, when the program execution is completed the output values held in the
memory are written to the physical outputs in one operation. Afterwards the cycle
starts again.
PLC
Environment
Memory

Programcycle

InputMemory

Read
Inputs

Flag
Memory

Execute
Program :
1. Instruction
2. Instruction
:
:
n. Instruction

OutputMemory

Write
Outputs

Inputs

Sensors

Outputs

Actuators

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

CoDeSys a PLC environment


A wide spread PLC tool which supports the IEC 1131-3 standard is
CoDeSys (www.3s-software.com). It runs on many different hardware PLCs
and of course as a Soft PLC.
After starting CoDeSys, the following window appears:

If a project is already opened, close the project with File Close .


3

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

New Project
To create a new project, select New
from the File Menu. Then the
Target
Settings
appears
for
configuration of the target system.
Select 3S CoDeSys
SP PLCWinNT V2.4
from the combo box.
Accept the default
settings with OK.

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

Program Organisation Unit (POU)


The first POU is created automatically. Its name is PLC_PRG and it is the
main POU. That means, this POU is called by the PLC by default. All other
POUs have to be called by this POU or a POU that is called by PLC_PRG.
The PLC languages are displayed at the right side. Additionally, CFC
(Continuous Function Chart) is listed. It is not part of the IEC1131-3 yet,
therefore it is not used in the exercises. Use Structured Text for
PLC_PRG, because the calling of other POUs is very easy in this language.

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

Simulation Mode
CoDeSys expects that the workstation is connected
to PLC hardware. As it is not the case, enable the
Simulation Mode in the Online menu.
To run the program, select Login and then
Run
from the Online menu. Select Logout
to edit the program again.

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

To add a new POU, click


Project Object Add

The POU PLC_PRG is called


automatically. The call of added POUs
must be done by the user (see below).

Select a language and name the POU.

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

Define Variables
Variables must be defined in the
declaration part (upper text
area) of a POU. One option is to
write the declaration manually
between VAR and END_VAR.
A second possibility is to use
undeclared variables in the
program
part.
When
an
undeclared
variable
is
recognized by the tool, then a
window arises with some default
values. For example, type
Red:=Switch;
and
press
<RETURN> in a ST-POU. Then
the Declare Variable windows
appears as depicted.
8

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

Visualisation
Select
the
tab
Visualizations and add
a new object by clicking
the right mouse button
on Visualizations
Add Object

4.
2.
3.

Name the Object (e. g.


Traffic_Light).
A window appears on
the right side with a grid.
With
the
drawing
buttons,
graphical
elements can be added.
The
drawings
are
configured by double
clicking.

1.

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

Configure graphical elements


Variables (application: lights)
In the category Variables, the link
between a graphical element and a
Boolean variable in the PLC
program is defined. The semantic is:
<POU>.<Boolean variable>

Colours (application: lights)


Color is the colour which is shown
when the associated Boolean
variable is FALSE, otherwise Alarm
color is shown.

10

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

Change values of variables


(application: switch)
For the switch it is required that the
user changes the variable by the
visualisation object. In the Input
category of the switch shape, a toggle
variable can be defined. The value of
the Boolean variable changes with
every click on the shape.

11

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

Exercise 3.2-3.3
The result of exercise 3.1 is shown below. Implement the automata graph as
SFC and IL.

Init-Phase
Switch=1 / Red=1
Red=1
Green=0
Yellow=0

Red=0
Green=0
Yellow=1

Red=1
RedYellow-Phase Green=0
Yellow=1
TimmerYellow=1s
TimerRedYellow=1s /
Yellow=0, Red=1
Red=Yellow=0, Green=1
Red=0
TimerGreen=3s /
Yellow-Phase
Green-Phase Green=1
Green=0, Yellow=1
Yellow=0
Red-Phase

TimerRed=3s /
Yellow=1

12

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

Exercise 3.2: SFC


First of all, the IEC-Steps
must
be
enabled
(ExtrasUse IEC-Steps)

Select a Step or Jump and


add a new Step and
Transition by a right-click
Step-Transition
(before)

If additional actions are required, select


Extras Associate Action

13

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

Exercise 3.2: SFC


The first steps of the
solution are shown.
Complete the program.
Do not forget to adapt
the variables of the
Visualisation.

14

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

Exercise 3.3: IL
The Instruction List is not similar to automata. But the idea of states and
state changes can be implemented in IL, too.
The required operators are listed below:
LD variable
load operand into result register
ST variable
store result into operand
AND variable
link actual result and variable by logical AND
OR variable
link actual result and variable by logical OR
S variable
set variable TRUE if actual result is TRUE
R variable
set variable FALSE if actual result is TRUE
CAL functionblock
call functionblock
Set (S) and Reset (R) only works with Boolean values. The ST operator is
not restricted to a data type.
15

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

Timer Declaration
When an undeclared variable is
used the first time, then a dialog
box
arises
for
variable
declaration.

If the variable is a timer, then


the type can be selected in the
Help Manager.

After applying, the type is taken


over and can be accepted.
16

Industrial Process Automation, Exercise3: PLC (Programmable Logic Controller)

Exercise 3.3: IL
The usage of IL-statements and the timer-function-block is explained in the
following RedPhase. Complete the program. Remember that the InitPhase
must be executed exactly one time.
(*RedPhase*)

Comment

LD

RedPhase

Load content of RedPhase into result register

Red

If result register is TRUE set Red to TRUE

LD

RedPhase

ST

TimerRed.IN

Store actual result in INput of TimerRed

LD

T#3s

Load constant T#3s into result register

ST

TimerRed.PT

CAL

TimerRed

LD

TimerRed.Q

RedYellowPhase

RedPhase

Call functionblock TimerRed

If actual result is TRUE set RedPhase to FALSE

17

You might also like