Part 1
Matteo Cacciari
em@il: matteo.cacciari@unibo.it
DEIS CASY
19-04-2011
1
Outline
Introduction
CoDeSys
Installation info
Software development and correctness check
IEC 61131-3 compliant
First Steps
Project organization
Project simulation
The SFC Editor
Function blocks
Visualization
Example
Introduction
Hierarchical and modular organization of a complex control system:
AUTOMATIC
CONTROL
AUTOMATION PYRAMID
Introduction
Goal: implement a sequential logic control.
Usually implemented on Real-Time digital controllers
called PLC
CoDeSys
CoDeSys (Controlled Development System) is a complete development environment for
programming PLC.
Developed by 3S software (www.3s-software.com).
Complies with the international IEC 61131-3 standard
CoDeSys is a part of the Codesys Automation Suite:
Development layer
Communication layer
Device layer
CoDeSys
After the installation we find different programs in the Start menu:
Communication: for configuring the OPC and DDE servers used
for the communication and remote applications.
ENI interface: for connecting external database to the CoDeSys
environment with the purpose of sharing data between users,
programs and projects.
CoDeSys SP RTE: turns any type of industrial PC into a powerful
PLC scalable via the PCs performance (not usable in the demo
version).
runtime HMI system: for watching and operating the data of a
controller which has been programmed with CoDeSys (not usable
in the demo version).
Software development
Ideal control program development :
Work station
Ethernet
communication
PLC
RT
communication
Real system
to reduce costs
to reduce time
CoDeSys environment integrates a functioning mode called Simulation mode to simulate the
code without neither a real-time environment, nor a PLC (this is our case for the final project)
In simulation mode we can run the control program and manually modify the value of the
variables.
Manually change the variables value is not always possible:
the system could be too complex
some behaviors could be too difficult to simulate
8
Plant
Simulator
Actuators
Signals
We can interact with the system during simulation building a graphic interface:
passively, showing only what is happening;
actively, manually changing the state of the
system or the state of the controller (e.g. filling
a warehouse, changing the functioning modes
of the controller if we want to work only some
pieces instead of all, ).
9
Programming languages:
FBD
IL
ST
13
SFC
First Steps
1. Run CoDeSys v.2.3
14
WORK SPACE
MESSAGE WINDOW
OBJECT ORGANIZER
Work Space: place where the editor of all objects are opened (SFC editor, FBD editor,).
Message window: contains all messages from the previous compilations, checks or
comparisons.
15
Object Organizer
It has four register cards on the bottom:
POUs: contains the POUs defined as programs, functions and function blocks.
Data Types: lists the data types defined by the user.
Visualization: contains the graphic panel for HMI and for displaying the variables.
Resources: contains the elements for configuring and organizing the project (e.g. Global
Variables definition, Task configuration, Library Manager, PLC configuration, )
How to ?
Add a POU: right click on POUs in POUs card and Add Object.
Export a POU: right click on POUs and Export object.
Import a POU: click on Project in the Menu bar and Import.
Add a Library: Resource card Library Manager in the
work space window right click Additional Library
Append a new task: Resource Task Manager in the work
space window right click on Task configuration Append Task
Assign a program to a task: right click on the new task
created Append program call.
Important Note: to use the standard languages it is necessary to load the libraries named
Iecsfc.lib and Standard.lib.
16
The two programs interact with each other using global variables.
Note: the control program can only use the measurements coming from the virtual sensors.
Other simulation variable cannot be used!
17
19
The most important commands are found in the Tool bar (see figure below).
INSERT STEP
INSERT
INSERT
TRANSITIONS
ALTERNATIVE
PARALLELL
BRANCH
BRANCH
INSERT JUMP
20
IEC STEP
EXIT ACTION
There are implicitly declared variables in the SFC which can be used
<StepName>.x (for IEC steps) or <StepName> (for simplified step) are boolean variables
that are TRUE if the step is active and FALSE otherwise.
<StepName>.t (for IEC steps) represent the time the step is active (useful for timers)
Flags are automatically generated variables that can be used to control the execution of SFC
POUs . Can be used to implement a pseudo-parent/child management (we need to put them
in VAR_INPUT list).
SFCInit: if TRUE the SFC is reset to the initial step and remain there until it become FALSE.
SFCPause: if TRUE the execution of the SFC diagram is stopped until it become FALSE.
SFCTrans: takes on the value TRUE when a transition is actuated.
22
SFCCurrentStep: is of the type STRING and it stores the name of the active step.
Parent/Child Management
Parent/child Management:
SFCs called child depend on another SFC called parent.
Parent SFC can force the start and the stop of the children.
The children execute in parallel with the parent SFC if activated.
If we put the flag variable as VAR_INPUT in a program all the programs in the project can
modify this variables. We can obtain a pseudo-parent/child management.
With SFCInit we can activate or deactivate a SFC.
With SFCPause we can freeze a SFC
Why pseudo?
all the programs can modify the flag variable not only the parent (we have several parent);
when the child is stopped it does not disappear but it remains frozen in the init state.
23
Function Blocks
The Function Block (FB) is a POU similar to a function. Unlike functions a FB:
can have several outputs;
has an internal state.
The consequences of having a state are:
the same inputs can give different outputs;
the FB data structure must be stored until the end of the program.
Note: Clearly reusing a FB means have different copy of the same data structure!
FBs can be seen as a class in the object-oriented programming, everywhere I need to use the
FB I have to build an instance of it (each IEC language can instance a FB).
Each instance has:
an identifier (the instance name);
a structure with internal, input and output variables.
We can refer to input and output variables of an instance with the following syntax:
< instance name> . < variable name>.
24
Function Blocks
To use a FB we have to:
Declare the FB type:
VARIABLES
DECLARATION
ALGORITHM
DECLARATION
Declare an instance:
Call the FB instance:
in a ST program:
in a LD program:
in a FBD program:
25
Visualization
A visualization is a graphical representation of the project variables which allows also the
interaction with the PLC program during the simulation via mouse and keypad.
A graphic editor allows to connect visualization elements with project variables through
configuration windows.
A visualization created in CoDeSys can be used for testing and interacting with the control
software in simulation mode, but also:
for operating the visualization in full screen mode on a PLC computer with CoDeSys HMI (a
runtime system not available in the demo version).
for interacting with the controller via internet with a Web-Visualization (useful for remote
maintenance purposes)
for visualizations which can be started directly on the PLC as a Target-Visualization.
26
27
Example
TANK
LEVEL
SENSOR
START/STOP
SOLENOID
VALVES
RESISTOR
CONVEYER
MOTOR
POSITION
SENSOR
BOTTLE LEVEL
SENSOR
TEMPERATURE
28
SENSOR
Example
Actuators
Description
Motor
Conveyor motor on/off signal
Hot
Resistor on/off signal
EV1
EV2
Solenoid valves on/off signals
EV3
Sensors
Start
Pres_bottle
Temp_val
Tank_lev
Bot_lev
Description
1=process starts; 0=otherwise
1=bottle in position; 0=otherwise
Temperature value
Fluid level in the tank
Fluid level in the bottle
29
References
User Manual for PLC Programming with CoDeSys 2.3, 3S - Smart Software Solutions GmbH
3S web page, http://www.3s-software.com/index.shtml?homepage
M. Sartini, Manuale di utilizzo del software CoDeSys (Italian)
The example is on http://www-lar.deis.unibo.it/people/msartini/
30