codesys v3.5 - part a (english) v1.3.pdf
TRANSCRIPT
-
Textbook
CoDeSys version 3
A hardware
independent
introduction to
CoDeSys
pbF V3.5
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-2
This book is developed for the Codesys course for Industry. In this course you will
learn how to program hardware useing the Codesys V3.5 pbF software. The name is
Codesys provided by Festo.
This Software is free, and is loaded onto the memory stick wich is handed out in this
course. During the course we will use a Festo controller as the controlunit to control
MPS station distribution or MecLab Pick and Place station. All Festo Didactic
modules can be controlled with this controller.
Order Number: xxx DE
Description: Codesys for Industy V3.5
Type: Codesys V3.5 pbF
Version: V1.3
Auther: Rinus Simonis
Edition: April 2013
2012 by Festo Didactic GmbH& Co. KG
Rechbergerstrae 3, D-73770 Denkendorf
All right resereved. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any
form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior written
permission of the publisher
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-3
CONTENTS CHAPTER 1 : Introduction ...................................................................................... 10
1.1 Codesys ............................................................................................................ 11
1.2 Details of Festo ................................................................................................. 11
1.3 PC administrator Rights ................................................................................ 11
1.4 Installing Codesys V3 provided by Festo. ........................................................ 11
CHAPTER 2 : Methode to solve control problems .................................................. 12
3.1 From a problem to a Solution ........................................................................... 13
CHAPTER 4 : Quick Start Codesys ......................................................................... 16
4.1 Activating Codesys .......................................................................................... 17
4.2 Creating a New Project..................................................................................... 17
4.3 Device............................................................................................................... 18
4.4 Add POU(PRG) ................................................................................................ 20
4.5 Task Configuration ........................................................................................... 27
4.6 Testing the application ..................................................................................... 29
4.7 Communication parameters .............................................................................. 29
4.8 Online testing ................................................................................................... 32
4.9 Basic visualisation ............................................................................................ 34
CHAPTER 5 : Project STRUCTURE ....................................................................... 42
5.1 Project Structure ............................................................................................... 43
5.1.1 PLC............................................................................................................ 44
5.1.2 Application ................................................................................................ 44
5.1.3 Libraries .................................................................................................... 44
5.1.4 Task configurator ...................................................................................... 45
5.1.5 Visualisation manager ............................................................................... 45
5.1.6 Visualisation screens ................................................................................. 45
5.2 Internal processing ........................................................................................... 45
5.3 Task Configuration ........................................................................................... 46
CHAPTER 6 : Hardware connection and testing ...................................................... 48
6.1 Controller connection ....................................................................................... 49
6.2 Testing .............................................................................................................. 52
CHAPTER 7 : Motionstep diagram .......................................................................... 54
7.1 The Motion step Diagram................................................................................. 55
7.2 The Grid ........................................................................................................... 55
7.3 The rest position of an actuator ........................................................................ 56
7.4 The Memories .................................................................................................. 56
7.5 The Signals (Sensors) ....................................................................................... 57
7.6 The Actions ...................................................................................................... 57
7.7 Example without using a memory .................................................................... 57
7.8 Example using a memory ................................................................................. 59
7.9 Example using a timer and a memory .............................................................. 60
7.10 Example of a counter for the entire cycle ....................................................... 61
7.11 Example using a counter in the cycle ............................................................. 62
CHAPTER 8 : Sequential function chart .................................................................. 64
8.1 Sequential function chart .................................................................................. 65
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-4
8.2 The basic symbols............................................................................................ 65
8.3 Unconditional Jump ......................................................................................... 66
8.4 Conditional Jump ............................................................................................. 67
8.5 Parallel Branches ............................................................................................. 68
8.6 Step Memories ................................................................................................. 69
8.7 Actions ............................................................................................................. 70
CHAPTER 9 : recommendations for naming identifiers ......................................... 72
9.1 Identifiers for variables (variable names) ........................................................ 73
9.2 Identifiers for user-defined data types (DUT) ................................................. 74
9.3 Identifiers for functions, function blocks, programs (POU) ............................ 76
CHAPTER 10 : The 5 Programming laguages ........................................................ 78
10.1 Languages ...................................................................................................... 79
10.2 Combined program editor FBD / LD / IL ...................................................... 79
10.2.1 Programming IL...................................................................................... 79
10.2.2 Changing the view .................................................................................. 82
10.3 Instruction List (IL) ....................................................................................... 84
10.3.1 Labels ...................................................................................................... 86
10.3.2 Modifiers ................................................................................................ 86
10.3.3 The IL Operators and Modifiers ............................................................. 87
10.3.4 Load (LD) instruction ............................................................................. 88
10.3.5 Store (ST) instruction ............................................................................. 88
10.3.6 Set (S) instruction ................................................................................... 89
10.3.7 Reset (R) instruction ............................................................................... 89
10.3.8 AND instruction...................................................................................... 89
10.3.9 OR instruction ......................................................................................... 89
10.3.10 XOR instruction .................................................................................... 90
10.3.11 ADD ...................................................................................................... 90
10.3.12 Subtract, SUB ....................................................................................... 90
10.3.13 Multiply, MUL ..................................................................................... 90
10.3.14 Divide, DIV .......................................................................................... 91
10.3.15 Greater Than, GT .................................................................................. 91
10.3.16 Greater than or equal, GE, .................................................................... 91
10.3.17 Equal, EQ, ............................................................................................. 92
10.3.18 Not Equal, NE, ...................................................................................... 92
10.3.19 Less than or equal, LE, ......................................................................... 92
10.3.20 Less than, LT, ....................................................................................... 93
10.3.21 JuMP, JMP, ........................................................................................... 93
10.3.22 CAL instruction .................................................................................... 94
10.3.23 RET instruction ..................................................................................... 96
10.3.24 Working with ( ) ................................................................................ 97
10.4 Function block diagram (FBD) ...................................................................... 98
10.4.1 Working FBD/LD/IL editor .................................................................... 99
10.4.2 AND function ....................................................................................... 101
10.4.3 OR function .......................................................................................... 101
10.4.4 EXOR function ..................................................................................... 102
10.4.5 Inversion / negation .............................................................................. 102
10.4.6 RS function block (Reset dominant) ..................................................... 103
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-5
10.4.7 SR function block (Set dominant) ......................................................... 103
10.4.8 CTD function block (decrement, CounT Down) ................................... 103
10.4.9 CTU function block (increment, CounT Up) ........................................ 104
10.4.10 CTUD function block .......................................................................... 104
10.4.11 RTC function block (Runtime Clock) ................................................. 105
10.4.12 TOF function block (delayed turn-off) ................................................ 106
10.4.13 TON function block (timed turn-on) ................................................... 107
10.4.14 TP function block (pulse timer) ........................................................... 108
10.4.15 F_trig function block (falling edge trigger) ......................................... 108
10.4.16 R_trig function block (rising edge trigger) .......................................... 109
10.5 Ladder diagram (LD).................................................................................... 110
10.5.1 Normally open contact .......................................................................... 112
10.5.2 Normally closed contact ........................................................................ 112
10.5.3 Coil ........................................................................................................ 112
10.5.4 Negated coil ........................................................................................... 112
10.5.5 Set Coil .................................................................................................. 113
10.5.6 Reset Coil .............................................................................................. 113
10.5.7 Rising edge ............................................................................................ 113
10.5.8 Falling edge ........................................................................................... 113
10.5.9 Timer function ....................................................................................... 113
10.5.10 Box with AND function ...................................................................... 114
10.5.11 Inserting a function block or module call ............................................ 114
10.6 Structured Text (ST) ..................................................................................... 115
10.6.1 assignment, :=........................................................................................ 118
10.6.2 Using subprograms ................................................................................ 118
10.6.3 Using function blocks ............................................................................ 119
10.6.4 RETURN instruction ............................................................................. 120
10.6.5 IF THEN ELSIF THEN ELSE END_IF instruction .... 120
10.6.6 CASE or ELSE END_CASE instruction ............................... 121
10.6.7 FOR TO BY DO END_FOR instruction ........................... 121
10.6.8 WHILE DO END_WHILE instruction ....................................... 122
10.6.9 REPEAT UNTIL END_REPEAT instruction ............................ 122
10.6.10 EXIT instruction .................................................................................. 123
10.6.11 ADD, + ................................................................................................ 123
10.6.12 Subtract , SUB ................................................................................... 124
10.6.13 Multiply *, MUL ................................................................................. 124
10.6.14 Divide /, DIV ....................................................................................... 124
10.6.15 Exponent **, EXPT ............................................................................. 125
10.6.16 Modulo MOD ...................................................................................... 125
10.6.17 Less than , GT .............................................................................. 126
10.6.19 Less than or equal =, GE .............................................................. 126
10.6.21 Equal =, EQ ......................................................................................... 127
10.6.22 Not equal , NE ................................................................................ 127
10.6.23 AND, & instruction ............................................................................. 127
10.6.24 XOR instruction .................................................................................. 128
10.6.25 OR instruction ..................................................................................... 128
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-6
10.6.26 LEN .................................................................................................... 129
10.6.27 LEFT ................................................................................................... 129
10.6.28 RIGHT ................................................................................................ 129
10.6.29 MID .................................................................................................... 129
10.6.30 CONCAT ............................................................................................ 130
10.6.31 INSERT .............................................................................................. 130
10.6.32 DELETE ............................................................................................. 130
10.6.33 REPLACE........................................................................................... 130
10.6.34 FIND ................................................................................................... 131
10.7 Sequential Function Chart (SFC) ................................................................. 132
10.7.1 Step ....................................................................................................... 133
10.7.2 Entry and exit actions ........................................................................... 134
10.7.3 Transition or condition ......................................................................... 135
10.7.4 Active step ............................................................................................ 135
10.7.5 Step with Action ................................................................................... 135
10.7.6 Qualifiers .............................................................................................. 136
10.7.7 Implicit variables in SFC ...................................................................... 136
10.7.8 SFC flags .............................................................................................. 137
10.7.9 Branches ............................................................................................... 138
10.7.10 Jumps .................................................................................................. 141
10.8 Continues Function Chart (CFC) ................................................................. 142
10.8.1 Editor functions .................................................................................... 144
10.8.2 Pointer ................................................................................................... 144
10.8.3 Insert Input ............................................................................................ 144
10.8.4 Insert Output ......................................................................................... 144
10.8.5 Insert Box ............................................................................................. 145
10.8.6 Insert Jump............................................................................................ 145
10.8.7 Insert Label ........................................................................................... 145
10.8.8 Insert Return ......................................................................................... 145
10.8.9 Insert Composer .................................................................................... 145
10.8.10 Insert Selector ..................................................................................... 145
10.8.11 Insert Comment .................................................................................. 145
10.8.12 Insert Connection mark source ........................................................... 146
10.8.13 Insert Connection mark Sink .............................................................. 146
10.8.14 Insert Input of box .............................................................................. 146
10.8.15 Insert output of box ............................................................................. 146
10.8.16 Extras Negate ...................................................................................... 147
10.8.17 Extras Set/Reset .................................................................................. 147
10.8.18 Extras EN/ENO .................................................................................. 147
10.8.19 Reset Pins............................................................................................ 147
10.8.20 Remove unused pins ........................................................................... 147
CHAPTER 11 : Quick start Visualization.............................................................. 148
11.1 Visualization in your project ....................................................................... 149
11.1.1 The screen ............................................................................................. 152
11.1.2 Configuration of visualisation object .................................................... 154
11.1.3 Stop button ............................................................................................ 156
11.1.4 Relay ..................................................................................................... 156
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-7
11.1.5 Lamp...................................................................................................... 156
11.1.6 Activation of the complete application ................................................. 156
CHAPTER 12 : Visualisation ................................................................................. 158
13.1 Editor functions ............................................................................................ 159
13.1.1 Static and dynamic text in a component ................................................ 159
13.2 Variables displayed in the Text box ......................................................... 159
CHAPTER 14 : ENI ............................................................................................... 164
14.1 ENI ............................................................................................................... 165
14.1.1 General .................................................................................................. 165
14.1.2 ENI (Engineering Interface) .................................................................. 165
14.1.3 Preconditions: ........................................................................................ 166
14.1.4 Handling Codesys project objects under source control: ...................... 166
14.1.5 Installation, usage of ENI Server .......................................................... 167
CHAPTER 15 : user interface ................................................................................ 168
15.1 The main window ......................................................................................... 169
15.2 Pull down menus ......................................................................................... 169
15.2.1 File ......................................................................................................... 169
15.2.2 Edit ........................................................................................................ 170
15.2.3 View ...................................................................................................... 170
15.2.4 Project.................................................................................................... 171
15.2.5 Build ...................................................................................................... 171
15.2.6 Online .................................................................................................... 172
15.2.7 Debug .................................................................................................... 172
15.2.8 Tools ...................................................................................................... 173
15.2.9 Windows ................................................................................................ 173
15.2.10 Help ..................................................................................................... 173
15.3 Device/POU ................................................................................................. 174
15.3.1 POU ....................................................................................................... 174
15.3.2 Device, Device tree ............................................................................... 174
15.3.3 Generals ................................................................................................. 175
15.3.4 Boot project ........................................................................................... 175
15.3.5 Password................................................................................................ 177
CHAPTER 16 : Library manager ........................................................................... 182
16.1 Libraries ....................................................................................................... 183
16.2 Installation and including in project ............................................................. 183
16.3 Codesys V2.3 libraries ................................................................................. 183
CHAPTER 17 : Trace ............................................................................................. 186
17.1 Trace configuration ...................................................................................... 187
CHAPTER 18 : Installing ADDITIONAL CONTROLLERS ................................ 190
18.1 Installing an additional controller ................................................................. 191
CHAPTER 19 : Documentation ............................................................................. 194
19.1 Documenting a project ................................................................................. 195
19.2 Project info ................................................................................................... 195
19.3 Project statistics ............................................................................................ 196
19.4 Printer setup .................................................................................................. 196
19.5 Printing ......................................................................................................... 196
19.6 Additional project documentation ................................................................ 196
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-8
CHAPTER 20 : glossary ........................................................................................ 198
CHAPTER 21 : Shortcuts ...................................................................................... 204
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-9
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-10
CHAPTER 1 : INTRODUCTION
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-11
1.1 Codesys
Codesys: The programing standard for PLCs according to the IEC 61131-3
Codesys (Controller Development System) is a software tool used to do industrial
automization. Its has two main parts:
The programming envirolment of Codesys,
The run time system for the selected tragets.
Each IEC 61131-3 run time system controller can be programmed with Codesys.
Intergraded compilers ensure that the program code is processed at optimum speed.
More than 200 innovative manufacturers from various industry sectors, program
there automated systems with Codesys. The result is that thousands of end users and
machine developers over the world use Codesys on a daily basis for automation of
processes.
At the moment Codesys is the most used IEC 61131-3 development tool in Europe.
Codesys can be downloaded from the Festo website once you register on the site.
1.2 Details of Festo
Codesys pbF is supplied and used by Festo.
Festo Didactic GmbH& Co. KG
Rechbergerstrae 3, D-73770 Denkendorf
Internet; www.festo-didactic.com
e-mail: [email protected]
1.3 PC administrator Rights
To install the Codesys software the PC user must have local administrator rights!
1.4 Installing Codesys V3 provided by Festo.
Put the CD in the CD-ROM player or put the pen drive in the USB port of your
computer.
Select the file name Setup_CodesysV3_pbf_Full (..)
The installation will be executed.
In this book we assume you make no changes during the installation of the software.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-12
CHAPTER 2 : METHODE TO SOLVE CONTROL PROBLEMS
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-13
3.1 From a problem to a Solution
The development from a control task to an actual working system can be a difficult
task, if the correct methods and tools are not used. There are two possible methods
that can be used. The first method is by making use of a motion step diagram, and the
second method makes use of a sequential function chart.
Sequential function chart is a step orientated structure. This method is useful if the
same programming language (SFC) is used.
In this course we will make use of the motion step diagram to solve the problems.
The calculated solutions can be used in all programming languages.
Here are the basic principles of the motion step diagram:
Figure 1
On the left of figure 1 the position of Actuator A. When the actuator is in the rest
position, sensor a0 is activated. If the actuator moves to the activated position,
sensor a1 is activated.
On the right of figure 1 the position of Actuator B. When the actuator is in the rest
position, sensor b0 is activated. If the actuator moves to the activated position,
sensor b1 is activated.
Note in figure 1 that actuator A piston is at rest in the retracted position. Actuator B
piston is at rest in the extended position.
In the motion diagram we only indicate when the actuator moves from the rest
position to the activated position. (The actual direction of the actuator piston is not
shown)
The movement of the actuator is used as the starting point of the diagram.
A
a0 a1
A
a0 a1
Inactive
Active
B
b1 b0
B
b1 b0
Inactive
Active
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-14
In figure 2 the movement of one actuator is illustrated.
The bottom line indicates that the actuator is in the
rest position. The top line indicates that the actuator
is in the actuated position.
The vertical lines are called step lines.
The first (1) and the last step (3) is always the same.
The next step is to indicate the state of the sensors
a0 en a1 on the diagram.
Figure 2
In figure 3, below the movement of the actuator we
will first insert the status of the Start button, and
then follow with the status of the sensors a0 en a1.
The bottom line indicates that the sensor has a signal
state 0 (off), and the top line indicates that the
sensor has a signal state 1 (on).
The next step is to determine at which moment a
signal must be given, for the actuator to move in a
direction.
Figure 3
In figure 4 we indicate at witch step an action must be
taken. On step 1, A+, and on step 2 A-.
The next step is to determine which signal(s) or
combinations thereof is needed to perform the action
to be taken.
Figure 4
A
1 2 3/11
A
1 2 3/1
1
Start a0 a1
A+ A-
A
1 2 3/1
1
Start a0 a1
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-15
In figure 5 it is indicated that if
the Start is pushed and a0
has a signal state of 1, A+
will be activated. If
a1changes to a signal state
1, A- will be activated.
The length of the signals is
indicated by the horizontal
lines from where the action
should be performed.
Figure 5
The next step is to convert the Boolean formulas into a program.
A+ = Start a0 A- = a1
A
1 2 3/1
1
Start a0 a1
A+ A-
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-16
CHAPTER 4 : QUICK START CODESYS
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-17
4.1 Activating Codesys
If Codesys in installed in the standard way, it can be opened in the following method:
Go to Start; Programs; Festo Software; Codesys V3; and select
Codesys V3.5 pbF.
After a while Codesys opening screen will be displayed.
In figure 6 the opening screen is shown.
Figure 6
4.2 Creating a New Project
There are several ways to create a new project. In this book we will use the menu bar
for all the actions.
Select File, and in the drop down screen select New Project see figure 7
Figure 7
In Window Categories general should be chosen.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-18
After name the name of the project should be written.
Choose Empty project.
Make sure the proper location is chosen to save your projects.
When everything is OK click on OK
Figure 8
Your first project is created.
Make sure you safe your project. Only after saving your project, the automatic save
function in Codesys will save your work regularly.
Good practice is to create a separate folder for each project you create. In this way
you have a proper overview of your work. Otherwise Codesys is placing all your
work in one folder.
The next step is to add a device.
4.3 Device
Switch over to the tab Device in the left bottom of the main screen.
Figure 9
Click on MyFirst and click with the right mouse button
The following window will appear:
Click on Add Device
Figure 10
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-19
Figure 11
Choose Codesys Control Win V3 and click on Add Device.
After a moment you see the device window changing into figure 12
Figure 12
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-20
4.4 Add POU(PRG)
Click on Application in the device window.
Click with the right your mouse button, choose Add Object and choose POU
Figure 13
Figure 14
Now you have to choose the appropriate language. In figure 14 Instruction list is
chosen. When you click on Open the appropriate language editor will open.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-21
Figure 15
The upper part is to declare the local variables. The lower part is the language editor
in which you can write your application.
We are going to convert the following Boolean formulas into an application.
A += Start a0
A- = a1
Figure 16
Place the cursor as shown in figure 16
Type the following instructions: LD Start
Press Enter
Typing the LD command
the window will be shown.
You can choose a
command from this
window or just type the
next text.
Figure 17
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-22
Typing Start will also open a window. Just push the Enter button.
Figure 18
After pushing the Enter button the next screen will open.
This is the Auto Declare screen in which you declare the variables you use in your
applica
tion.
Figure 19
The Variable Start is of the type Bool. Just Click on OK to create this variable.
Figure 20
Place the cursor as shown in figure 20. The information about this variable will be
shown. Click with the right mouse button.
The window shown in figure 21 is shown.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-23
Figure 21
Choose insert IL line below now you can enter the AND function
Figure 22
Press Enter, the Auto Declare screen is opened again.
Figure 23
Variable a0 is of the type BOOL. Press OK
Your editor screen should look like figure 24.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-24
Figure 24
Place the cursor next to a0 and insert an IL line below (figure 21)
In figure 25 is shown how you application should look after entering the instructions
ST A
Figure 25
The 3 lines you see in the editor window belong to the first Network of your
application.
Now we are going to add a new Network for the next action
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-25
Place the cursor below the first network and right click on your mouse.
Figure 26
Now we can enter the information for the second network.
Figure 27
Your application should look like figure 27.
Pushing Function button F11 which is a Build of your project should give no error
messages.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-26
Figure 28
Our basic application is finished.
The next step is to add a Task configuration
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-27
4.5 Task Configuration
Figure 29
To add a Task configuration, choose Application, right click on your mouse,
Choose Add Object, Choose Task Configuration
Leave the name as is. Press Open.
Figure 30
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-28
Click on Add POU, the input assistant will open.
Choose POU and click on OK.
The next step is to test your application using the Soft PLC in your PC.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-29
4.6 Testing the application
Activating Codesys V3 in your system tray the Gateway and the Soft PLC should
be activated.
Look in your system tray if the Gateway and the
Soft PLC are available and running.
After starting the Soft PLC it will run for 1 hour after
that you have to activate the PLC again!
Figure 31
4.7 Communication parameters
Setting the communication parameters to activate your application.
Double click on Codesys_Control_Win_V3
Figure 32
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-30
The next window will open in the main window.
Figure 33
Choose Gatway-1 by clicking on it.
Figure 34
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-31
Figure 35
1. Select the PLC
2. Device info appears
3. Set active path
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-32
4.8 Online testing
Switch over to POU in the main screen.
Choose Online and choose login
Figure 36
On the bottom of your screen you can see that your application is in STOP mode.
You can activate it with F5.
When the RED Stop is turned into the GREEN RUN your application is running.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-33
Place the cursor after Start in the Colum Prepared value and click once.
The word TRUE will appear. Repeat this in the box after a0.
Figure 37
The prepared value is now TRUE. This value has to be transferred to the soft PLC.
This can be done with Ctrl + F7 write values in the Debug menu.
You will see that variable A is switched on.
Dont forget to make Start and a0 false again. Write values with Ctrl + F7
Make a1 true and write the values with Ctrl + F7
Figure 38
Repeat this a few times to get acquainted with these functions
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-34
4.9 Basic visualisation
Logout to stop the application. Only then you can add visualisation.
Figure 39
To add visualisation Choose application right click on your mouse choose Add
Object and choose Visualisation
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-35
Figure 40
Choose a proper name for the visualisation. Screen_1 and click on Open.
After a while the device window is looking like figure 41.
Figure 41
On the right hand side the visualisation screen_1 is open and ready to edit.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-36
Figure 42
To create a button in the visualisation screen click on a symbol on the right side of
the screen in the Toolbox window and draw it in the visualisation screen.
The following things have to be done:
We want to change the colour of the start button when it is pressed.
We want to change the status of the variable start from FALSE into TRUE.
We want to change the colour of the variable a0 when it is activated.
We want to change the status of the variable a0 when it is activated.
We want to change the colour of the Actuator A when it is activated.
We want to change the colour of the variable a1 when it is activated.
We want to change the status of the variable a1 when it is activated.
To realise that we need some functions from the properties window
Figure 43
In our case we need these three topics.
First we open the Colours
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-37
Figure 44
By clicking on the + sign in front of the colours it opens the colours window.
Choose the colour for the normal state by double clicking on the right hand side of
the Fill colour symbol and choose the appropriate colour.
Repeat this for the Alarm state.
In the visualisation screen the colour of the start button is changed into the normal
state colour.
Figure 45
Open the Colour variable window and double click on the right hand side of the
Toggle colour. Then click on the dotted line.
The input assistant window will open.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-38
Figure 46
After you have chosen the Start variable click on OK.
In this state the colour of the start button will change when the status of the Start
button is changed.
Now we have to open the input configuration window
Figure 47
Under normal conditions the Start button is a Push button and will tap the variable
from FALSE to TRUE when the Start button is pushed. When the Start button is
released the variable is taped back from TRUE to FALSE. In our example we have to
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-39
activate the Start button and the variable a0. Because we want to make it as easy as
possible we are now using the Toggle function for the Start button.
Place the cursor on the right hand side of the variable under the Word Toggle and
double click.
Figure 48
Click on the dotted line and the input assistant will open.
Choose Start again
This is how the configuration should look. See figure 49
Figure 49
Repeat these actions for a0 and a1.
For the Actuator A you only need the colour change,
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-40
Figure 50
Your Visualisation screen could look like this figure 50.
When you are ready, perform a login, and activate the application with F5
Push the start button.
Activate a0 and after a while activate a1
The colour of the actuator should change.
Congratulations, you have just created your first working project in Codesys V3.5.
All this information is explained extensively in other Chapters.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-41
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-42
CHAPTER 5 : PROJECT STRUCTURE
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-43
5.1 Project Structure
POUs
Global
variables
Libraries
Local variables
Language Code
Project
PLC (Soft PLC)
PLC logic (handling I/O)
Application
Task configuration
Task (POUs)
Visualistion Task
Visualisation manager
Target visualisation
Web Visualistion
Visualisation screens
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-44
5.1.1 PLC
PLC is the type of (soft) PLC which is used.
PLC logic is how the PLC is handling the logic part (I/O).
5.1.2 Application
An application consists always a Library manager
When applicable Global variables
POUs (Program Organisation Unit) (Program, Function, Function Block)
5.1.3 Libraries
Libraries can be a collection of functions for certain hardware.
5.1.3.1 Global variables
Global variables can be reached from all other POUs in the application.
They are created in the Global variable editor.
Local variables with the same name as a global variable have a higher priority in the
processing of a POU.
5.1.3.2 Program
Every program consists of a declaration section and a body. In the declaration section
the local variables are declared. The body is written in one of the IEC programming
languages: IL, ST, SFC, FBD and LD; or CFC.
POUs may call other POUs; however recursive calling (calling itself) is prohibited.
5.1.3.3 Function
We are all familiar with such functions as, add, square root, sin, cos, equal, etc.
Within IEC, an enormous number of these standard functions are defined. You can
even define your own functions, such as in the following example, defining the
function simple of type REAL:
FUNCTION simple: REAL
VAR_INPUT
A, B: REAL;
C: REAL := 1.0;
END_VAR
simple := A*B/C;
END_FUNCTION
Once defined, this function can be used endlessly in the same program, in other
programs and even in other projects.
5.1.3.4 Function block
The same applies to function blocks as for functions; we can defines these ourselves,
and use them as often as we wish.
Function block instances (copies) are allowed. Each Instance has a unique identifier,
and can be declared locally or globally.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-45
5.1.4 Task configurator
5.1.4.1 Task
In the task the POU can be given a priority. Based on this priority he will be
processed.
5.1.4.2 Visualization Task
In the visualisation task the different HMI screens are processed. A visualisation task
will never interrupt a POU task.
5.1.5 Visualisation manager
5.1.5.1 Target visualisation
This will process the visualisation for this target.
5.1.5.2 WEB visualisation
When supported will process the visualisation for the WEB
5.1.6 Visualisation screens
The actual visualisation screens for this application
5.2 Internal processing
The flowchart shows how the processor works when POUs are used.
Figure 51
poll inputs
evaluate logic
communication
post outputs
I/O scan
program scan
outputs
in
logic
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-46
5.3 Task Configuration
With the Task Configurator we can create tasks to be carried out in a specific order
and at specific times.
In the Task Configurator each task is given a priority number. The task with the
highest priority (priority number 1) will be performed first.
Tasks can be performed in the following way:
Cyclic, the task is performed cyclically according to the time specified in the
interval field.
Freewheeling, the task will be processed as soon as the program is started
and at the end of one run will be automatically restarted in a continuous
loop. There is no cycle time defined.
Event, (Boolean event, the task will be started as soon as the variable
defined in the Event field gets a rising edge.)
Status, (Boolean event, the task will be started if the variable defined in the
Event field is true.)
Triggered by external event, depending on the target, the task is performed
if a system event occurs, which is defined in the event field. The system
event is not the confused with the Codesys system events.
Watchdog
If the target system configuration supports a watchdog, a high and low limit can be
set for each task.
Active watchdog
With an active watchdog, if the task exceeds the watchdog time, the task will be stop
with an error signal.
Time: (Example t#200ms), if this time is exceeded the task will be stop. Depending
on the target settings, the time has to be entered as a percentage value of the cycle
time. The time block is gray, and there will be a % sign.
Sensitivity: here an integer number is entered that will be displayed as an error when
the watchdog time is exceeded. NOTE! If a 0 is entered the watchdog is switched off.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-47
Each task can call an unlimited amount of POUs.
For each task a priority number, between 0 and 31should be given.
A watchdog can be defined for each task.
With a large project with several hundred I/Os, between 3 to 5 tasks should be
defined.
Switching from one task to the next takes approximately 10s.
Codesys processes all POUs and any configured tasks independent of the underlying
operating system.
If the underlying operating system is capable of multitasking, then it can carry out
other tasks parallel to Codesys. Such a parallel task could for example be used to
interrupt a running Codesys task that has got stuck in an endless loop. If the
underlying operating system is non-multitasking, then the entire controller will have
to be reset to factory settings.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-48
CHAPTER 6 : HARDWARE CONNECTION AND TESTING
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-49
6.1 Controller connection
In this course we use a CECC, with 14 digital inputs and 8 digital outputs. It also has
USB, Ethernet and CANopen interface on-board.
Figure 52
At the back is a 230V AC socket. Place the cord with the plug in the socket and turn
the power on.
Device supply voltage X1
Pin Signal Comment
X1.1 24V U+ (electronic)
X1.2 0V U- (GND)
X1.3 GND Functional earth
X1.4 n.c. Not connected
I/O interface X2, X3 and X4
Pin Comment
X2.0 ..X2.1 Fast digital inputs (200kHz)
X2.2 x2.7 Digital Inputs (1 kHz)
X3.0 X3.5 Digital Inputs (1 kHz)
X4.0 X4.7 Digital outputs (500mA)
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-50
Supply voltage I/O X5
Pin Signal Comment
X5.1 24V U+ (I/O supply)
X5.2 0V U- (GND)
CAN open interface X6
Pin Signal Comment
1 n.c. Not connected
2 CAN_L1) CAN Low
3 CAN_GND CAN ground
4 n.c. Not connected
5 CAN_SHLD Connection to functional earth
6 CAN_GND CAN ground (optional)
7 CAN_H1) CAN high
8 n.c. Not connected
9 n.c. Not connected
1) If the CECC is located at the end of the cable, connect pin 2 and pin 7
with the help of a termination resistor (120 ohms/0,25W)
Ethernet interface X8
Pin Signal Comment
1 TD+ Transmitted Data +
2 TD- Transmitted Data -
3 RD+ Received Data +
4 n.c. Not connected
5 n.c. Not connected
6 RD- Received Data -
7 n.c. Not connected
8 n.c. Not connected
Body Screen
Load voltage supply IO-Link X11 (CECC-LK)
Pin Signal Comment
X11.1
24V
Connection for load voltage supply via IO-link
master ports: UA+ X11.2
X11.3
0V
Connection for load voltage supply via IO-link
master ports: UA- (GND) X11.4
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-51
Communication interface IO-Link master (CECC-LK)
X12, X13, X14 and X15
Pin Signal Comment
X12.1,
X13.1,
X14.1, X15.1
L+ 24V
X12.2,
X13.2,
X14.2, X15.2
C/Q Communication signal IO-Link
X12.3,
X13.3,
X14.3, X15.3
L- 0V
X12.4,
X13.4,
X14.4, X15.4
24V UA+
X12.5,
X13.5,
X14.5, X15.5
0V UA-
IO-Link device X16
Pin Signal Comment
X16.1 L+ 24V
X16.2 C/Q Communication signal IO-Link
X16.3 L- 0V
Status LEDs
Pin Comment
Run Status of the application
Net Device detected
Error Error
Mod Reserved
Connecting CECC-LK to your PC
Plug the RJ45 crossover Ethernet cable into the Ethernet socket and the other end of
the cable into the PC.
If you use a Hub, Switch or Router between the PC en de CECC-LK a 1:1 Ethernet
cable can be used.
Use a screened LAN/Ethernet cable (shielded twisted pair, STP) from Cat 5/5e/6/7
for this.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-52
6.2 Testing
Create a standard CECC project, use the CECC template I_O_Test The (POU) program should be of the type Structured Text (ST) write only a
semicolon ; in it.
Open the input window and switch on Always update variables.
Open the output window and switch on Always update variables.
Download this project to the controller.
Activate the program.
Now you can see in the input window dynamically the actual status of the inputs.
When you switch to the output window, you can change the status of each output by
placing the new value behind the output and use Ctrl + F7 to send this value to the
controller.
This project can be used when you want to test only the I/O of the system.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-53
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-54
CHAPTER 7 : MOTIONSTEP DIAGRAM
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-55
7.1 The Motion step Diagram
To create a universal working solution, regardless of which programming language
will be used, we make use of a motion step diagram.
In the following sections the various parts of the motion diagram is explained. First
we make a basic representation of the actuator movement from the rest position to
the activated position, and vice versa. Then we will discuss the steps to get from a
problem to a solution.
7.2 The Grid
The vertical lines in the diagram are called step. This is numbered from 1 to xx; the
last step is equal to the step 1.
At the top of the diagram between two horizontal lines the action of the actuators is
indicated. The bottom line indicates that the actuator is at rest, and the top line
indicates the actuator is in the activated position.
Figure 53
The active position of the top cylinder marked with the letter A, has a digital value 1.
The active position of the second cylinder marked with the letter b, has a digital
value 2.
The active position of the third cylinder marked with the letter c, has a digital value
4.
On each step the corresponding value should be recorded, and eventually added up,
from top to bottom.
A
B
C
1 2 3 4 5 6 7 8 9 (1)
Step line
active position
rest position
Step lines
20= 1
21= 2
22= 4
Value A active
Value B active
Value C active +
Total Digital value
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-56
Each step will have a unique number. As soon as two steps have the same value, then
a memory has to be used to differentiate between the two steps. This memory is
called a make uneven memory.
There is one exception to the rule. If two consecutive steps have the same value, then
a timer is used, and then a memory is not needed.
7.3 The rest position of an actuator
In the rest position the xx0 sensor is always activated. (See Figure 45).
Figure 54
The actuators are labels in capital letters and the sensors in small letters.
The memories that will be used are drawn under the actuators (cylinders).
7.4 The Memories
Figure 55
The memory cannot be activated or deactivated on the step where the numbers are
the same.
The set and reset (of the bi-stable memory must be changed to a mono-stable
memory) resetGsetG When two consecutive steps have the same number, timers is used to activate and
deactivate the actuator. A memory is not needed
G1
G2
G1s =
G1r = G2s =
G2r =
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-57
7.5 The Signals (Sensors)
The signals are placed under the memories.
Figure 56
Above the line the signal is 1, and below the line the signal is 0.
The red squares indicate when a signal changes from a 0 to a 1.
The signals do not switch on the steps lines. Switch on happens just before the step
line, and switch off happens just after the step line.
At the Start the red square is just before step 1, because that is the point when it is
activated. The stipple line indicates that the Start signal can be on for a longer period.
7.6 The Actions
Figure 57
The red dot indicates where the action should start.
The horizontal line indicates for how long the action in active.
To perform an action, look above for a rising signal (signal that goes from a 0 to a 1).
Because this is the first step we also look for the last signal that was activated.
The formula for A+ should then be:
0aStartA
The formula for A- should then be:
1aA
When sensors are used twice then a relay which has multiple contacts has to be used.
7.7 Example without using a memory
Here is a solution using a motion step diagram using two cylinders and no memory.
Start
a0
a1
A
+1 A-
A+ =
A- =
Start
A
B
G
20=1
21=2
1 2 3 4 5 (1)
0 1 3 2 0 No Memory
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-58
Figure 58
Step 1: Draw the motion of the actuators
Step 2: Check for the digital values that appear more than once
Step 3: Draw the signals (sensors)
Step 4: Draw the actions to take place
Step 5: Note the Boolean formulas
Step 6: Determine the length that actions are activated
Step 7: Check for overlapping actions (shorten if necessary)
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-59
7.8 Example using a memory
Here is a solution using a motion step diagram for two cylinders using a memory.
Figure 59
Step 1: Draw the motion of the actuators
Step 2: Check for the digital values that appear more than once
Step 3: draw the memories
Step 4: draw the signals (sensors)
Step 5: Note the memory formulas
Step 6: Draw the actions
Step 7: Note the Boolean formulas
Step 8: Determine the length the action is activated
Step 9: Check for overlapping actions (shorten if necessary)
Here we see to activate the memory, the primary signal combination Start AND a0
is used. If we look at the signal needed for A+ then we can use the same signals.
But because Start AND a0 is used to activate the memory, we use G1for A+.
Here we see how primary and secondary signals are used in the formulas.
Start
a0
a1
A
B
G
20=1
21=2
1 2 3 4 5 (1)
0 1 3 1 0 One Memory
b0
b1
A+
A-
B+
B-
A+ = G1
A- = b0 G1
B+ = a1 G1
B- = b1
G
1
G1s = Start a0
G1r = b1
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-60
7.9 Example using a timer and a memory
Here is a solution using a motion step diagram for two cylinders using a timer and a
memory.
Figure 60
Step 3 and 4 has the same value 3. This will only happen when a timer is used. The
timer has two parts, the timer T and the contact t. As soon as the start condition
for the timer is true 1, the timer starts timing. When the preset time has elapsed the
timer contact t switches.
Step 1: Draw the motion of the actuators
Step 2: Check for the digital values that appear more than once
Step 3: Draw the memories
Step 4: Draw the timer (T en t)
Step 5: Draw the signals (Sensors)
Step 6: Note memory formulas
Step 7: Note formula for Timer T
Step 8: Draw actions
Step 9: Note Boolean formulas
Step 10: Determine the length the action is activated
3
Start
a0
a1
A
B
G
20=1
21=2
1 2 4 5 6 (1)
0 1 3 1 0 One Memory
b0
b1
A
+ A-
B
+ B-
A+ = G1
A- = b0 G1
B+ = a1 G1
B- = t
G
1
G1s = Start
a0 G1r = b1
3
T
t
T = b1
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-61
Step 11: Check for overlapping actions (shorten if necessary)
7.10 Example of a counter for the entire cycle
The whole sequence is repeated 5 times.
Figure 61
Between step 4 and 5 it is indicated that the sequence should be repeated a number of
times. Extra steps should be taken to prevent the machine to start automatically when
the supply is switched on. Using an extra memory will prevent this from happening.
Start must be replaced with G2. The set command is Start en the reset command is C.
Start
a0
a1
A
B
G
20=1
21=2
1 2 3 4 5 (1)
0 1 3 1 0 One memory
b0
b1
A+
A-
B+
B-
A+ = G1 C
A- = b0 G1
B+ = a1 G1
B- = b1
G
1
G1s = Start a0
G1r = b1
cycles 5x
C
Cpuls
Creset
Cpuls = b1
Creset = G1 b0 C
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-62
7.11 Example using a counter in the cycle
In this example cylinder B must move 5 times, then cylinder A is retracted in rest
position. Cycle is finished.
F
Figure 62
Between step 3 and 4 it is indicated that cylinder B should repeat a number of cycles.
Extra steps should be taken to prevent the machine to start automatically when the
supply is switched on. Using an extra memory will prevent this from happening.
Start must be replaced with G2. The set command is Start en the reset command is C.
Start
a0
a1
A
B
G
20=1
21=2
1 2 3 4 5 (1)
0 1 3 1 0 One memory
b0
b1
A+
A-
B+
B-
A+ = a0 C
A- = C b0 G1
B+ = a1 G1
B- = b1
G
1
G1s = a0 + b0 G1 C
G1r = b1
Cylinder B 5 x
C
Cpuls
Creset
Cpuls = b1
Creset = Start a0 b0 C
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-63
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-64
CHAPTER 8 : SEQUENTIAL FUNCTION CHART
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-65
8.1 Sequential function chart
This solution is most suitable for sequential controllers. The BS EN IEC 60848:2002
is the standard in French and English. The BS 5848:1993 is the standard in Dutch
and English. Both standards give the description of the symbols, and use a graphic
representation of the control problem.
In the following sections we will discuss the symbols, the functions, and operations
used in the diagrams.
8.2 The basic symbols
The function diagram is designed using the following symbols.
Figure 63
Each function diagram starts with an initiating step. Below the step is a horizontal
line. This is where a condition is entered. This condition has to be met before going
to the next step
Between the steps is the condition that has to be met
before going to the next step. Once the condition is
met, the previous step becomes inactive and the
next step becomes active.
Once in the step the actions will be carried out.
In the ini step no actions is entered, except for
loading timers and counters. If the PLC is in run
mode this step becomes active immediately.
Figure 64
Ini
Initiating step Step
Ini
Condition
Condition
Action
Action
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-66
More than 1 action can be connected to an action.
An action is represented in a square
Figure 65
In this way action is linked to one step.
To ensure proper functioning of the SFC it is important to have a condition that has
to be met between the steps.
8.3 Unconditional Jump
In SFC it can happen that a jump function has to be performed between steps. Thus
we get the conditional jump and the unconditional jump.
After step 3 a jump function will be
performed, and jump back to the "ini
step. Step 4 will never be performed.
Figure 66
Action 1
Action 1 Action 2 Action 3
Action 1 Action 2 Action 3
1
Ini
2
3
4
The unconditional jump
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-67
8.4 Conditional Jump
A condition jump can also be called a destination jump.
Depending on the condition that is true, the corresponding branch will be executed.
Here a destination is made between the left
and the right branch in SFC, depending on
the condition.
Only one of the branches will be
performed. This is referred to as an OR
function.
Figure 67
1
Ini
2
3
4
5
6
The conditional Jump
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-68
8.5 Parallel Branches
In some cases it is necessary that several branches of the SFC must run simultaneous.
It will look as follows:
Figure 68
Both branches are processed at the same time. This is referred to as an AND
function.
1
Ini
2
3
4
5
6
Start of
simultaneous
operation
End of
simultaneous
operation
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-69
8.6 Step Memories
A sequential function chart is a simplified version of a motion step diagram.
Before each step we need to make use of a memory.
Figure 69
For the program we use the following memories:
G0 before step ini, G1 before step 1, G2 before step 2, G3 before step 3, G4 before
step 4.
1
Ini
2
3
4
Start
a1
b1
a0
b0
A+
B+
A-
B-
Initialisation step
Condition
Condition
Condition
Condition
Condition
step 1
step 2
step 3
step 4
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-70
First we need to create the steps
G0set = G4 b0 + ini
G0reset = G1
G1set = G0 Start
G1reset = G2
G2set = G1 a1
G2reset = G3
G3set = G2 b1
G3reset = G4
G4set = G3 a0
G4reset = G0
Two memories will always be active.
8.7 Actions
Actions with the use of bi-stabile valves, uses the following formula:
A+ = G1
A- = G3
B+ = G2
B- = G4
If A used a mono-stabile valve, then the following formula is used:
A+ = G1 + G2
(A- = G3 is not used in this application)
B+ = G2
B- = G4
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-71
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-72
CHAPTER 9 : RECOMMENDATIONS FOR NAMING IDENTIFIERS
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-73
Naming of identifiers
Identifiers are defined at the declaration of variables (Variable names), user-defined
data types and at the creation of POUs (functions, function blocks, programs) and
visualizations. You might follow the following recommendations concerning the
naming of identifiers in order to make it as unique as possible.
9.1 Identifiers for variables (variable names)
The naming of variables in applications and libraries as far as possible should follow
the Hungarian notation:
For each variable a meaningful, short description should be found, the base name.
The first letter of each word of a base name should be a capital letter, the others
should be small ones (Example: FileSize). If needed additionally a translation file for
other languages can be created. Before the base name, corresponding to the data type
of the variable, prefix(is) is added in small letters.
* Pointedly for BOOLean variables x is chosen as prefix, in order to differentiate
from BYTE and also in order to accommodate the perception of an IEC-programmer
(see addressing %IX0.0).
Data type lower limit upper limit Information
content Prefix Comment
BOOL FALSE TRUE 1 Bit x*
b reserved
BYTE 8 Bit by Bit string, not for
arithm. operations
WORD 16 Bit w Bit string, not for
arithm. operations
DWORD 32 Bit dw Bit string, not for
arithm. operations
LWORD 64 Bit lw not for arithm.
operations
SINT -128 127 8 Bit si
USINT 0 255 8 Bit usi
INT -32.768 32.767 16 Bit i
UINT 0 65.535 16 Bit ui
DINT -2.147.483.648 2.147.483.647 32 Bit di
UDINT 0 4.294.967.295 32 Bit udi
LINT -263
263
- 1 64 Bit li
ULINT 0 264
- 1 64 Bit uli
REAL 32 Bit r
LREAL 64 Bit lr
STRING s
TIME tim
TIME_OF_DAY tod
DATETIME dt
DATE date
ENUM 16 Bit e
POINTER p
ARRAY a
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-74
Examples:
bySubIndex: BYTE;
sFileName: STRING;
udiCounter: UDINT;
In nested declarations the prefixes are attached to each other in the order of the
declarations:
Example:
pabyTelegramData: POINTER TO ARRAY [0..7] OF BYTE;
Function block instances and variables of user-defined data types as a prefix get a
shortcut for the
FB- resp. data type name (Example: sdo).
Example:
cansdoReceivedTelegram: CAN_SDOTelegram;
TYPE CAN_SDOTelegram : (* prefix: sdo *)
STRUCT
wIndex:WORD;
bySubIndex:BYTE;
byLen:BYTE;
aby: ARRAY [0..3] OF BYTE;
END_STRUCT
END_TYPE
Local constants (c) start with prefix c and an attached underscore, followed by the
type prefix and
the variable name.
Example:
VAR CONSTANT
c_uiSyncID: UINT := 16#80;
END_VAR
For Global Variables (g) and Global Constants (gc) an additional prefix + underscore
is attached to the
library prefix:
Examples:
VAR_GLOBAL
CAN_g_iTest: INT;
END_VAR
VAR_GLOBAL CONSTANT
CAN_gc_dwExample: DWORD;
END_VAR
Appendix J: - Recommendations on the naming of identifiers
Codesys V2.3 10-105
9.2 Identifiers for user-defined data types (DUT)
The name of each structure data type consists of a library prefix (Example: CAN), an
underscore and a preferably short expressive description (Example: SDOTelegram)
of the structure. The associated prefix for used variables of this structure should
follow directly after the colon.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-75
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-76
Example:
TYPE CAN_SDOTelegram : (* prefix: sdo *)
STRUCT
wIndex:WORD;
bySubIndex:BYTE;
byLen:BYTE;
abyData: ARRAY [0..3] OF BYTE;
END_STRUCT
END_TYPE
Enumerations start with the library prefix (Example: CAL), followed by an
underscore and the identifier in capital letters.
Regard that in previous versions of Codesys ENUM values > 16#7FFF have caused
errors, because they did not get converted automatically to INT values. For this
reason ENUMs always should be defined with correct INT values.
Example:
TYPE CAL_Day :(
CAL_MONDAY,
CAL_TUESDAY,
CAL_WEDNESDAY,
CAL_THIRSDAY,
CAL_FRIDAY,
CAL_SATURDAY,
CAL_SUNDAY);
Declaration:
eToday: CAL_Day;
9.3 Identifiers for functions, function blocks, programs (POU)
The names of functions, function blocks and programs consist of the library prefix
(Example: CAN), an underscore and an expressive short name of the POU (Example:
SendTelegram). Like with variables always the first letter of a word of the POU
name should be a capital letter, the others should be small letters. It is recommended
to compose the name of the POU of a verb and a substantive.
Example:
FUNCTION_BLOCK CAN_SendTelegram (* prefix: canst *)
In the declaration part a short description of the POU should be provided as a
comment. Further on all inputs and outputs should be provided with comments. In
case of function blocks the associated prefix for set-up instances should follow
directly after the name.
Actions get no prefix; just actions which should be called only internally, i.e. by the
POU itself, start with prv_. Each function - for the reason of compatibility with previous Codesys versions -
must have at least one parameter. External functions must not use structures as
return values. Appendix J: - Recommendations on the naming of identifiers
10-106 Codesys V2.3
Identifiers for Visualizations
Note: Currently you must avoid that visualization has the same name like another
POU in the project. This would lead to problems in case of changes between
visualizations.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-77
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-78
CHAPTER 10 : THE 5 PROGRAMMING LAGUAGES
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-79
10.1 Languages
Codesys V3.5 supports all the languages described in the IEC 61131-3.
Text based languages:
Instruction List (IL)
Structured Text (ST)
Graphical Languages:
Sequential Function Chart (SFC)
Function Block Diagram (FBD)
Ladder Diagram (LD)
An extra programming language Continuous Function Chart (CFC), which is based
on Function Block Diagram, is also available under the graphical language.
10.2 Combined program editor FBD / LD / IL
10.2.1 Programming IL
In version 3.5 of Codesys the following
languages are combined into one editor
FBD/LD/IL
Creating a new POU.
You give the POU a name (1), which
type of POU do you want to create (2),
choose the language you want to use
(3). In the FBD/LD/IL editor you can
change the view from one language to
another.
F
igure 70
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-80
Changing to another view means, the system assumes that the syntax in your file is
correct. In other case you can lose information.
The shortcuts you can use are:
Ctrl + 1 for FBD view
Ctrl + 2 for the LD view
Ctrl + 3 for the IL view
When the POU is created you see a double window.
Figure 71
In the upper part of the window you declare the local variables. The application
program is entered in the lower part of the screen.
Entering Variables:
Place the cursor in the Variable window (upper part) and press Shift + F2. The auto
declare window will open.
Figure 72
Name of the variable, xA (1), Type of the variable, BOOL (2).
The other possibilities of this screen will be explained in another section.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-81
Create xA as BOOL, xB as BOOL, xQ as BOOL.
We are going to create the following IL program:
LD xA
AND xB
ST xQ
The combined FBD/LD/IL editor is a network oriented editor.
For IL this means that the combination of a condition and an action is one network.
To write the commands in one network you have to add some lines in that network.
Place the cursor in the first line of the program window, the lower part.
Figure 73
Write the instruction LD xA push Enter.
Entering the commands will show you an overview of possible instructions.
Figure 74
Place the curses in the column next to xA and click with the right mouse button.
A menu will open. Choose Insert IL line below.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-82
Now you can enter the next IL line in the network.
The whole IL program should look like this:
Figure 75
10.2.2 Changing the view
Figure 76
Choose FBD/LD/IL from the menu.
Choose View
Choose the view you want to see.
Ctrl + 1 for Function block diagram
Ctrl + 2 for Ladder logic
Ctrl + 3 for instruction list
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-83
Ctrl + 1
Ctrl + 2
Ctrl + 3
The screen is divided into 5 columns. Each with its own content.
Column Contains... Description
1 Operator This field contains the IL operator (LD, ST, CAL, AND, OR etc.)
or a function name.
In case of a function block call here also the respective parameters
are specified, in this case in the prefix field := or => must be
entered.
2 Operand This field contains exactly one operand or a jump label. If more
than one operand is needed (multiple/extensible operators AND A,
B, C or function calls with several parameters), those must be
written into the following lines where the operator field is to be
left empty. In this case add a parameter-separating comma.
In case of a function block, program or action call the appropriate
opening and/or closing brackets must be added.
3 Address This field contains the address of the operand as defined in the
declaration part. The field cannot be edited and can be switched on
or off via Tools, options
4 Symbol
comment
This field contains the comment as defined for the operand in the
declaration part. The field cannot be edited and can be switched on
or off via Tools, options
5 Operand
comment
This field contains the comment for the current line. It is editable
and can be switched on or off via Tools, options
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-84
Changing the columns shown, choose Tools and Options
Figure 77
10.3 Instruction List (IL)
In version 3.5 FBD/LD/ IL are combined in one editor.
This means a common set of commands and elements is used and an automatic
internal conversion between the three languages is done. In offline mode the
programmer always can switch to one of the other editor views.
Notice anyway, that there are some special elements, which cannot get converted and
thus will only be displayed in the appropriate language. Also there are some
constructs which cannot get converted unambiguously between IL and FBD and
therefore will be "normalized" at a conversion back to FBD. These concerns:
Negation of expressions and explicit/implicit output assignments.
This language supports programming based on an accumulator. All IEC 61131-3
operators are supported as well as multiple inputs / multiple outputs, negations,
comments, set / reset of outputs and unconditional / conditional jumps.
Each instruction is primarily based on the loading of values into the accumulator by
using the LD operator. After that the operation is executed with the first parameter
taken out of the accumulator. The result of the operation again is available in the
accumulator, from where the user should store it with the ST instruction.
In order to program conditional executions or loops IL supports both comparing
operators like EQ, GT, LT, GE, LE, NE and jumps. The latter can be unconditional
(JMP) or conditional (JMPC / JMPCN). For conditional jumps the accumulator's
value is checked on TRUE or FALSE.
Syntax:
An instruction list (IL) consists of a series of instructions.
Each instruction begins in a new line and contains an operator and, depending on the
type of operation, one or more operands separated by commas.
The operator might be extended by a modifier.
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-85
In a line before an instruction there can be an identification mark (label) followed by
a colon (:), for example "ml:" in the example shown below. A label can be the target
of a jump instruction, for example "JMPC next" in the example shown below.
A comment must be placed as last element of a line.
Empty lines can be inserted between instructions.
An Instruction List program comprises a series of instructions.
Each instruction begins on a new line.
Each instruction contains an Operator, if necessary a Modifier, and one or more
Operands separated by commas.
The Operator can be preceded by a Label. This Label consists of a word ending with
a colon (Label:).
A comment may also be present on a line as the last element, enclosed entirely
between brackets and asterisks (* like this *).
Empty lines between instructions are permitted.
NOTE!
IL is compiled line by line, and does not comply with the Boolean order of
operations BNAO (Brackets, Not, And, Or).
Example:
Label
Start:
Operator Operand Comment
LD %IX1 (* Push-button *)
ANDN %MX5 (* Not busy *)
ST %QX2 (* Fan on *)
JMPC Next
Label
Next:
-
Codesys for Industry V3.5 [version 1.3] Festo Didactic
A-86
10.3.1 Labels
An instruction may be preceded by a label terminated with a colon (:). With the JMP
instruction we can jump to a label.
A label may be no longer than 16 characters.
The first character must be a letter.
All other characters may be numerals, letters or the underline _ symbol.
A label may occur only once in an IL program. However, a label may have the same
name as a variable. The difference is that the label terminates with a colon.
Example:
Begin:
LD Start (*Start button*)
AND Stop (*Stop button*)
JMP Program (*Label Program*)
Program:
LD %IX5 (*Clamp in*)