Professional Documents
Culture Documents
INSTITUTE
Logic
OF
Controller)
AUTOMATION SYSTEMS
Prof. Dr.-Ing. Wolfgang Meyer
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]
Programcycle
InputMemory
Read
Inputs
Flag
Memory
Execute
Program :
1. Instruction
2. Instruction
:
:
n. Instruction
OutputMemory
Write
Outputs
Inputs
Sensors
Outputs
Actuators
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.
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.
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
Visualisation
Select
the
tab
Visualizations and add
a new object by clicking
the right mouse button
on Visualizations
Add Object
4.
2.
3.
1.
10
11
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
13
14
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
Timer Declaration
When an undeclared variable is
used the first time, then a dialog
box
arises
for
variable
declaration.
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
Red
LD
RedPhase
ST
TimerRed.IN
LD
T#3s
ST
TimerRed.PT
CAL
TimerRed
LD
TimerRed.Q
RedYellowPhase
RedPhase
17