1
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:
AUTOMATION SYSTEMS Prof. Dr.-Ing. Wolfgang Meyer
R. W. Lewis; Programming industrial control systems using
IEC 1131-3; Inst. of Electrical Engineers; London; 1995
[Lewis, 95]
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 Memory Program-cycle Input-Memory Read Inputs Execute Program : 1. Instruction Environment Sensors Inputs
3
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 .
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
5
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 Modein the Online menu.
To run the program, select Login and then
Run from the Online menu. Select Logout
7 To add a new POU, click
Project → Object → Add…
Select a language and name the POU.
The POU PLC_PRG is called
automatically. The call of added POUs must be done by the user (see below).
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
9
Visualisation
Select the tab
“Visualizations” and add a new object by clicking the right mouse button
on Visualizations
→ Add Object…
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. 2. 3. 4.
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
11
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.
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.
13
Exercise 3.2: SFC
First of all, the IEC-Steps
must be enabled
(Extras→Use 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
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.
15
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:
call functionblock CALfunctionblock
set variable FALSE if actual result is TRUE Rvariable
set variable TRUE if actual result is TRUE Svariable
link actual result and variable by logical OR ORvariable
link actual result and variable by logical AND ANDvariable
store result into operand STvariable
load operand into result register LDvariable
Set (S) and Reset (R) only works with Boolean values. The ST operator is not restricted to a data type.
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.
17
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.
If actual result is TRUE set RedPhase to FALSE RedPhase R RedYellowPhase S TimerRed.Q LD
Call functionblock TimerRed TimerRed
CAL
TimerRed.PT ST
Load constant T#3s into result register T#3s
LD
Store actual result in INput of TimerRed TimerRed.IN
ST
RedPhase LD
If result register is TRUE set Red to TRUE Red
S
Load content of RedPhase into result register RedPhase
LD
Comment (*RedPhase*)