Anda di halaman 1dari 30

CoDeSys Presentation

Part 1

Matteo Cacciari
em@il: matteo.cacciari@unibo.it
DEIS CASY
19-04-2011
1

Outline
Introduction

time-driven vs. sequential logic control

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

We distinguish two types of control:


time-variant control: represented by time-variant models (differential or difference
equations).
sequential logic control: coordinates the functioning phases of the system, usually by using
discrete events (2nd-3rd layer).
3

Introduction
Goal: implement a sequential logic control.
Usually implemented on Real-Time digital controllers
called PLC

The ideal programming language is the SFC defined


in the IEC 61131-3 standard.

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

We will stop at this level

Download the software Codesys:


you need to register
Download v.2.3 (not v.3!)
no temporal limitations
no SFC or ST variables number limitation
library limitation (not necessary for projects)

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

The control is developed on a PC with CoDeSys installed.


The code is transferred to the PLC through a common network.
The PLC reads the inputs coming from the real system sensors through a Real-Time
communication network, it runs the control tasks and give as outputs the signals that govern
the actuators.
Note: If the PLC is not programmable directly with CoDeSys we need to compile the code
7
before porting it on the PLC.

How to check the control program


Before exporting the control program to the PLC we need to check the correctness of the
code.
Why?
to avoid undesired behaviours;
to avoid hardware failures
to avoid risks to human

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

How to check the control program


Usually a second program is built to simulate the real plant. We need to realize:
the virtual sensors (e.g. a position sensor, a level sensor,)
the effect of the actuator (e.g. the increasing of the water if the valve is opened)
Sensors
measurements
Control
Program

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

IEC 61131-3 compliant


The IEC 61131-3 standard can be seen as split in two parts:
Common Elements:
Data Typing: definition of the data types (e.g.
Integer, Real, Byte, Date, String, ). It is also
possible to define own personal data types derived
from the previous
Variables: depending on the visibility, 5 classes
are defined (local, global, input, output, inputoutput). They are declared between the keyword
VAR and END_VAR. The default value is 0 or FALSE.
Software Model: defines the structure of a control system basing on a maximum powerful
PLC (Multi-processor, multi-tasking, unlimited I/O, communication with other PLC and PCs).
Configuration: represents the whole programmable controller (usually a PLC with
several CPUs connected). In a control system we can have more than one
configuration communicating with each other. It contains one or several resources.
Resource: provides support functions for the execution of IEC programs and an
interface between a program, the I/O ports of the PLC and the user (like a CPU). 10

IEC 61131-3 compliant


Task: controls the execution of a set of programs and/or function blocks. Programs/function
blocks must be associated to a task in order to be executed and can be executed periodically
or can be event-driven. A task declaration consists of the task name, its priority, and a
condition on which the task is to be executed (cyclic, time-controlled, event-controlled).
POUs: (Program Organization Units) represent small independent software units containing
the program code. There exists three types of POUs: programs, functions and function blocks.
The POUs enable a modular software structure with the possibility of software reuse.
Similarly to the object oriented approach a POU must be declared and then instantiated one
or several times. A POU is programmed with a language defined in the standard and can be
used by any other POUs (the recursive use is forbidden).
Programs: represents a set of software elements. The
instances of a program can be assigned to several tasks.
Functions: are pre-programmed calculations that accept
numerous inputs, but return only one output (INsOUT).
It is always referred to its created name.
Function blocks: are pre-programmed calculations that accept numerous inputs, and
can return several outputs. Differently from functions, a FB has an internal state so an
11
instance of that block must be defined each time it is used in a POU (INs+STATEOUTs).

IEC 61131-3 compliant


Communication Model: describes the data exchange of configuration elements:
Acces Paths: enables the communication between configurations (VAR_ACCESS).
Local/Global Variables: symbolic names that have a mean for the user. Local variables
are variables usable only inside the POUs where are declared. Global variables are
usable from each element inside the configuration.
Directly represented variables: refer to real addresses in the PLC memory.

Note: Usually a conventional


PLC contains one resource,
running one task, controlling
one program, running in a
closed loop.
12

IEC 61131-3 compliant

Programming languages:

LD (Ladder Diagram): graphical language based on


Relays Ladder Logic.
LD

FBD (Function Block Diagram): graphical language


similar to an electronic circuit diagram. Each
function, function block and program can be seen as
a block connected by a network.

FBD

IL (Instruction List): textual language based on a


sequence of instructions similar to Assembler.
ST (Structure Text): textual language with high
level of abstraction, similar to Pascal/C. It allows the
implementation of complex constructs.
SFC (Sequential Function Chart): graphical
language with high expressiveness. The control is
organized as a state chart with steps representing the
current state of the system, where actions are
executed, and transitions containing the conditions
for realizing a change of state.

IL

ST

13

SFC

First Steps
1. Run CoDeSys v.2.3

2. Create a new project (File New or press

on the high left corner)

3. Select Target as None

4. Define the new POU


The default name is PLC_PRG.
It is automatically executed (the other
POUs must be explicitly called).

14

CoDeSys Main Window


MENU BAR
TOOL BAR

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

How to organize a project


Usually two programs are developed:
Control program: defines the sequential logic control of the system (what we want).
Simulation program: simulates the behaviour of the system (it does not really exist).

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

How to organize a project


Both the programs have to be executed. Since only PLC_PRG is executed by default, we have
to configure the system:

1. Append a new task (right click on Task configurationAppend Task);


2. Append two program calls for both the control and the simulation programs (right click
on New Task Append Program Call).
18

How to run a project


To simulate the project:
1) From the Menu bar: Project Clean all;
2) From the Menu bar: Project Rebuild all;
If there are no error in the message window it is possible to run the project in simulation
mode (if at the beginning we select as target None, the simulation mode is automatically
selected, otherwise you can select it in the Menu bar under Online)
3) From the Menu bar: Online Login;
4) From the Menu bar: Online Run;
Note 1: To debug the program can be useful to run the code in the step-by-step mode:
when the project is running press Ctrl+F5;
to execute the next time step Ctrl+F5 again;
to exit the single step mode press F5.
Note 2: during simulation it is always possible to see the
value of the variables, the current state of the system and
the progress of the code clicking on the POUs objects

19

The SFC Editor


The easy way to develop the control program is using the SFC language. The editor simplifies
the construction of the SFC.

Work space SFC Editor

The most important commands are found in the Tool bar (see figure below).
INSERT STEP

INSERT

INSERT

TRANSITIONS

ALTERNATIVE

PARALLELL

BRANCH

BRANCH

INSERT JUMP

IF SELECTED A IEC STEP IS USED


INSTEAD OF A SIMPLIFIED ONE

20

The SFC Editor


Differences between simplified step and IEC step
SIMPLIFIED STEP

Actions are inside the block and


directly connected with the step (action
is executed until the step is active);
The instructions of the action can be
written directly inside the block;
N (Non-stored): The action is active as long as the step
R (overriding Reset): The action is deactivated
S (Set / Stored): The action is activated and remains active until a Reset
L (time Limited): The action is activated for a certain time
D (time Delayed): The action becomes active after a certain time if the step is
still active and then it remains active as long as the step is active.
P (Pulse): The action is executed just one time if the step is active
SD (Stored and time Delayed): The action is activated after a certain time and
remains active until a Reset
DS (Delayed and Stored): The action is activated after a certain time as long
as the step is still active and remains active up to a Reset
SL (Stored and time Limited): The action is activated for a certain time

IEC STEP

Actions are outside the block with the


time qualifier;
In the action field we can put a boolean
variable or an action previously defined
and appended in the Object Organizer
under the program which uses it;

Right click on the desired program Add Action


21

The SFC Editor


The SFC editor defines other two actions:
entry actions, are actions executed only once, right after the step has become active.
exit actions, are actions executed only once before the step is deactivated.
ENTRY ACTION

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

How to create a visualization object


To create a visualization object:
click on the Visualization register in the Object Organizer.
right click on Visualizations folder Add Object
insert visualization elements using the Menu bar.

Double click on the element to open the configuration


window.

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

Anda mungkin juga menyukai