Documente Academic
Documente Profesional
Documente Cultură
Glossary
K-Bus The K bus (also called internal data bus) is a data link within the
PLC. The task of the K bus is to link the CPU (bus coupler) with
the input and output components (nodes) of the PLC.
II
Table of contents
Table of contents
Glossary ............................................................................................................................ II
Table of contents .............................................................................................................. III
List of Figures ................................................................................................................... V
1 Introduction ................................................................................................................ 1
1.1 Goal ................................................................................................................... 1
1.2 Document Structure ........................................................................................... 1
2 The Theory ................................................................................................................ 2
2.1 Initial Commissioning of a WAGO Node ............................................................. 2
2.1.1 Creating a Project in WAGO-I/O-PRO(CoDeSys) ....................................... 2
2.1.2 Defining Communication Parameters ......................................................... 4
2.1.3 Creating the PLC Configuration .................................................................. 6
2.1.4 The First Program..................................................................................... 10
2.2 Writing/Forcing values ...................................................................................... 13
2.3 Variable Declaration ......................................................................................... 14
2.3.1 Variable Name/Designator ........................................................................ 15
2.3.2 Variable Classes....................................................................................... 16
2.3.3 Variable Type ........................................................................................... 17
2.3.4 Initial Value ............................................................................................... 18
2.3.5 Address .................................................................................................... 19
2.3.6 Comment .................................................................................................. 20
2.3.7 Constant, Retain and Persistent Variables................................................ 20
2.4 Relational Operators ........................................................................................ 22
2.5 Functions, Function Blocks and Programs........................................................ 24
2.6 Set/Reset Command ........................................................................................ 27
2.7 Timers in IEC 61131-3...................................................................................... 29
2.7.1 Timer Off-Delay TOF ................................................................................ 29
2.7.2 Timer On Delay TON ................................................................................ 29
2.7.3 Pulse Timer (TP) ...................................................................................... 30
2.7.4 Time Declaration ...................................................................................... 30
2.8 Computational Operators ................................................................................. 31
2.9 Counters in IEC 61131-3 .................................................................................. 32
2.9.1 CTU Counter ............................................................................................ 32
2.9.2 CTD Counter ............................................................................................ 32
2.9.3 CTUD Counter .......................................................................................... 33
III
Table of contents
IV
List of Figures
List of Figures
V
List of Figures
VI
Introduction
1 Introduction
This document is intended for all user who wish to acquire skills in programming
the 750 Series controller. The procedure for programming the controller using
WAGO-I/O-Pro CAA (CoDeSys) is explained step by step in the individual
sections.
1.1 Goal
The goal of this document is to help you take your first steps and gain confidence
in programming based on IEC 61131. The following pages contain a description of
how to develop a small program and load this to the control system.
The sections of this document are set up such that you can use it as a reference
"book" to look up special topics. This can help you refresh your memory long after
the seminar. This seminar is not, however, a substitute for the WAGO Seminar
404 "Basics of Programming IEC 61131-3 Using CoDeSys 2.3 CAA.". And in the
same sense, reading through this document does not qualify you to take part in
Seminar 404. This document is merely an additional, optional offer in addition to
the seminar to help reinforce the learning effect of the course.
We would be glad to hear any comments or suggestions for improvement that you
may have. Send these to training@wago.com.
1
Program Examples
2 The Theory
This section uses examples to describe the theoretical concepts required for
programming the WAGO controller.
After starting, you must first create a new project by clicking on the symbol
(or: File/New).
2
Program Examples
In this window you can select the module type and the programming language for
the main program. The language CFC (Continuous Function Chart) is used in this
course. The name of the main program must be PLC_PRG. PLC_PRG is the
designation for the starting module, from which you can then create other links.
The programming window is displayed when click on the OK button.
Inputs and outputs
Programming window
3
Program Examples
An option exists for testing a program without the hardware. You must activate the
Simulation mode for this via Online Simulation. You can change the value for
the variables in the program that is logged in by double-clicking on the value. The
new value is accepted after selecting Write online values.
To create a new communication channel click New. Here, you can select the
device drive and a name.
If you specify a serial link here (Serial RS232), you must set the correct COM port
in the next step. COM1 is normally set as the default. The WAGO USB
communication cable takes a virtual COM port. You can find the number used for
this link using the device manager.
4
Program Examples
If you want to set a different COM port, use the up and down arrows to move up
and down in the list.
The method for creating an Ethernet link is described in the manual. The Ethernet
link is also presented and explained in the course "Basics for Programming IEC
61131-3 using CoDeSys 2.3 CAA."
5
Program Examples
6
Program Examples
Here, click on Append subelement to open an input mask for selecting hardware.
Add
Situation 1, offline: Hardware is not yet available. In this case, the modules must
be configured individually. To do this, click on the plus symbol to add I/O system
components to the PLC configuration. These components are available in a folder,
sorted by their function. Once you have marked the required hardware you can
add it to the PLC configuration by clicking on the double right arrow (see Figure
2.11). Note here that the quantity and order of the components for the PLC
configuration must correspond to the actual setup.
7
Program Examples
Situation 2, online: The hardware is already available and ready for operation
(power supply applied). In this case, you can export the PLC configuration from
the node. The WAGO-I/O-CHECK software must be installed for this and the
communication parameters defined properly as described in Section 2.1.2. To
import the hardware open the Configuration tab and click on the magnifying glass
. This initiates export of the node in the background by WAGO-I/O-CHECK. This
does away with the need for manual configuration and, thus, rules out any
potential for errors. You can order WAGO-I/O-CHECK under item number 759-
302.
After you configure the hardware you must name the hardware inputs and outputs
to be used in the program. To do this, click on the tab Inputs/Outputs. The
following allocation is offered:
8
Program Examples
9
Program Examples
10
Program Examples
In this case, an OR operator is selected instead of the AND operator. The operator
must be connected to variables at the inputs and outputs. To do this, position the
inputs and outpus as required and link them to the operator. Use the mouse
pointer for this to "draw" a link to the input and output connection.
You must assign names to the inputs and outputs after you have connected them.
To do this, mark the three question marks indicated for the input/output and assign
a name by pressing F2 to obtain the Input Assistant. The following program is then
displayed:
11
Program Examples
The program is now complete and can be translated and then tested in the
simulation. You must activate the simulation mode for this via Online
Simulation. The program can be translated via Online login.
Login
Status
indication
You can now change the value for the variables in the program that is logged in by
double-clicking on the value. The new value will not be accepted, however, until
you click Write online values.
If the project is to be loaded to a controller, the simulation mode must be
deactivated (no check-mark next to Online Simulation). As in simulation, you
must now log in and start the program. If the program is in the controller and the
has been started, you can test the program by setting the input signals for the
node.
12
Program Examples
One or more variables are set one time to user-defined values using the command
Online/ Write values. This is done to change the values of variables.
Procedure:
Login and testing via
Online/ Login and
Online/ Start
13
Program Examples
Forced values are listed in a table. You can open this list using Online
Write/Force dialog. You can click on a forced value to cancel forcing and restore
the value to its original setting.
Using Declare Variable you can define (declare) the name, class, type, initial
value, address, retain and a comment. The information for class, name and type is
required. All other information is optional, or is yielded from project requirements.
As an alternative, you can call up the Input Assistant under Edit, or by pressing
Shift + F2.
14
Program Examples
Please note the following for the designator, i.e., the variable name:
• The variable name must begin with a letter (character). Digits can be
entered after this first letter.
• The variable name may not contain any spaces, German Umlauts (ä, ö, ü)
or special characters (ß, #, @, Ω, €, etc.).
• There may be no double declarations or identical key words. Key words are
all names and designations used by the programming system, such as
AND, OR, END_VAR. A complete list of these is given in CoDeSys Help
under "Key words".
• No distinction is made between upper and lower case spelling of variable
names, meaning that EIN1, Ein1 and ein1 are all the same variable.
• Underscores are taken as a valid character, for example "A_BCD" and
"AB_CD" are interpreted as different designators.
• Consecutive underscores are prohibited.
• There is no limit on the number of characters (length) in the variable name.
15
Program Examples
16
Program Examples
Resources
Resources tab
Call up selection
2
Mark and accept by
double-clicking
17
Program Examples
Different variable types are available, based on the application. The IEC 61131-3
standard contains elementary data types whose possible value range and number
of bits are described below:
This makes the EMERGENCY OFF button a break contact, for example. If the
break contact is assigned to a variable with an initial value of TRUE, the hardware
signal and variable value concur when the project is started.
18
Program Examples
2.3.5 Address
A variable can also be assigned to a hardware address. This creates a link
between the variable and an I/O point of the hardware, or to a memory location
(marker).
19
Program Examples
2.3.6 Comment
You can add a comment text to help describe or explain the variable in this bar.
Comments are very valuable for project documentation.
Retain variables keep their values after an abnormal termination as well as after
switching the control on or off regularly. Work is continued with the saved value
when the program is restarted. An example of an application for this is an item
counter in a production line, which continues counting where it left off after a
power failure. All other variables are re-initialized, either with their initialized
values, or with the standard initialization values. Retain variables are, however, re-
initialized for Reset Cold, Reset Original and, in contrast to persistent variables,
on a new program download.
Persistent variables keep their values only after a renewed download (Online
Load) but not, in contrast to retain variables, after Online Reset, as they are not
stored in the retain sector. If persistent variables should also keep their previous
value after a control system failure, they must also be declared as VAR RETAIN.
An application example of a persistent retain variable would be an operating hours
counter, which should resume counting after a power failure.
20
Program Examples
Constant variables are variables that cannot be changed in the ongoing program.
The number π, for example, could be declared as a constant to use it to perform
calculations in the program.
Variable declaration of the local variables is provided for in the declaration window
for each module.
Variable declaration
21
Program Examples
After marking,
press F2 for the
Input Assistant
Operands 2
GT (Greater Than)
Result1 = 1, when Operand1 > Operand2, otherwise 0
GE (Greater Equal)
Result2 = 1, when Operand1 >= Operand2, otherwise 0
EQ (Equal)
Result3 = 1, when Operand1 = Operand2, otherwise 0
LE (Lower Equal)
Result4 = 1, when Operand1 <= Operand2, otherwise 0
LT (Lower Than)
Result5 = 1, when Operand1 < Operand2, otherwise 0
NE (Not Equal)
Result6 = 1, when Operand1 is not equal to Operand2,
22
Program Examples
You must overwrite the values for the operands in the logged-in program in order
to test for proper functioning of the operators. To do this, call up an editor.
Enter the
new value
The new value is then entered as input. The value is not accepted, however, until
the menu item Online/Write values has been called up.
23
Program Examples
Function blocks and functions are not integrated into the program module in the
same manner as operators. The procedure for function blocks and functions is
designated as instantiation. This involves creating a copy of the module from the
library that is then used under a different name in the project (program module).
This is illustrated below:
24
Program Examples
The declarations can be used the same as other variables when written the same.
25
Program Examples
26
Program Examples
First, set up a project in the manner shown here. Then, mark the given point.
Using the menu item Set/Reset you can modify a simple allocation as an allocation
with a stored value.
27
Program Examples
A corresponding procedure is used for Reset, except that you must double-click
the menu item Set/Reset after marking the point.
Click twice to
generate a Reset
command
Note:
As with the RS(SR) flip-flop function block, a priority response occurs in the state
when S and R are simultaneously TRUE, which is actually prohibited. The
command that is subordinate, relative to the same output, will prevail.
Execution order
28
Resetting Setting
Program Examples
TOF is added by marking an item and then pressing F2 (see Standard Function
Blocks in IEC61131-3).
Input Output
Preset Time
Elapsed Time
29
Program Examples
30
Program Examples
Inputs can be linked with variables, or values can be input directly. It goes without
saying that for implementation the calculation rules of algebra must always be
followed.
31
Program Examples
RESET
If the input parameter RESET = TRUE (logical 1), the counter is initialized with the
value 0 and counting is performed upward from there.
PV (Preset Value)
PV is a signed 16-bit INTeger value, i.e., between -32768 and +32767. This value
is used to define the upper limit for the counter, at which Q changes to TRUE.
CU
CU (Count Up) is the edge-triggered counting input, i.e., the count is increased by
1 when a rising edge changes from FALSE to TRUE (as long as 0 is not reached).
CV
CV (Current Value) is the current value (count) for the counter. This count is
increased by 1 when a positive edge is present at input CU.
Q
Q is TRUE (logical 1) when the current value (count) CV is the same as PV.
The variables CU, RESET and Q are BOOL types, while PV and CV are of type
INT.
see: CoDeSys Help
LOAD
If the input parameter LOAD = TRUE (logical 1), the counter is initialized with the
value PV and counting is performed downward from there.
PV
PV is a signed 16-bit INTeger value, i.e., between -32768 and +32767. The
counter is initialized with this value when the LOAD input = TRUE.
32
Program Examples
CD
CD (Count Down) is the edge-triggered counting input, i.e., the count CV is
decreased by 1 when a rising edge changes from FALSE to TRUE (as long as 0 is
not reached).
CV
CV (Current Value) is the current value (count) for the counter. This count is
decreased by 1 when a positive edge is present at input CD.
Q
Q is TRUE (logical 1) when the current value (count) CV is 0.
The variables CD, LOAD and Q are BOOL types, while PV and CV are of type
INT.
see: CoDeSys Help
RESET
If the input parameter RESET = TRUE (logical 1), the counter is initialized with the
value 0 and counting is performed upward or downward from there.
LOAD
If the input parameter LOAD = TRUE (logical 1), the counter is initialized with the
value PV and counting is performed upward or downward from there.
PV
PV (Preset Value) is a signed 16-bit INTeger value, i.e., between -32768 and
+32767 (only a value greater than 0 is actually meaningful). The counter is
initialized with this value when the LOAD input = TRUE.
CD
CD (Count Down) is the edge-triggered counting input, i.e., the count CV is
decreased by 1 when a rising edge changes from FALSE to TRUE (as long as 0 is
not reached).
CU
CU
CU (Count Up) is the edge-triggered counting input, i.e., the count is increased by
1 when a rising edge changes from FALSE to TRUE (as long as 0 is not reached).
33
Program Examples
CV
CV (Current Value) is the current value (count) for the counter. This count is
decreased by 1 when a positive edge is present at input CD and increased by 1
when a positive edge is present at input CU.
QD
QD is the lower binary output of the counter. This output is TRUE (logical 1) when
the current value CV = 0.
QU
QU is the upper binary output of the counter. This output is TRUE (logical 1) when
the current value CV >= PV (preset value).
The variables CU, CD, RESET, LOAD, QU and QD are BOOL types, while PV and
CV are of type INT.
see: CoDeSys Help
34
Program Examples
3 Program Examples
On controlled. This is achieved for a fluorescent lamp with the aid of an electronic
ballast (EVG). Using an EVG, the brightness can be set from minimum to
maximum with direct current of 0-10V. An analog output is required to generate
this voltage. A variable value (e.g., integer) is transformed to an analog voltage in
this process. The analog output is not provided in this system. It therefore suffices
to define a variable whose specific value is displayed in the simulation.
D Electrical
Inputs Function block ballast
A
35
Program Examples
This function block must be linked to inputs and outputs and other elements before
it can be properly used.
Building automation requires functions that are also used in standard installations.
WAGO offers a number of function blocks for building automation to simplify these
automation tasks. You can download these function block libraries from our
Website at www.wago.de. Here, you should program a latching relay on your own
to illustrate the use of the function blocks.
Tactil Switch
Lamp
This function has been implemented in the bottom representation within the
function block Fb_LatchingRelay:
36
Program Examples
This function block can be called up from the main program PLC_PRG:
37
Exercises Exercise 1: Vehicle Traffic Tunnel
4 Exercises
Procedure description:
If one smoke detector issues a signal, fan 1 must start running. If two smoke
detectors issue signals, fan 2 and fan 3 must also be activated. If all smoke
detectors issue signals, all three fans must start running. Your task is to develop a
control system for the fans in the tunnel based on IEC 61131.
Allocations:
VAR_GLOBAL
R1:BOOL; (*Smoke detector1*)
R2:BOOL; (*Smoke detector2*)
R3:BOOL; (*Smoke detector3*)
fan1:BOOL; (*Fan1*)
fan2:BOOL; (*Fan2*)
fan3:BOOL; (*Fan3*)
END_VAR
Note:
To help solve this task you should analyze the functions of the operators AND, OR
and NOT.
38
Exercises Exercise 2: Service Water Solar Installation
Procedure description:
One task of the control system for a service water solar installation involves
switching of the pump. The solar circuit pumps is to be activated when the
collector temperature is 10°C higher than the temperature toward the bottom of the
reservoir.
classification:
Figure 4.3: Global variables for the service water solar installation
39
Exercises Fan Control
The variables for temperatures are declared as type Integer. This is necessary, as
BOOL variables would not be sufficient for digital temperature values (0 or 1 as
state). An INTEGER variable is better suited for this. An INTEGER variable can
possess values between -32768 to 32767.
Your task is to develop a control system for the service water solar installation
based on IEC 61131. The values can be subsequently manipulated to test them.
To do this, you must double-click exactly on the numerical value and input the new
value. The values are not accepted, however, until the menu item
Online/Overwrite values has been called up.
In actual practice, temperature values are linked via analog inputs (e.g., Wago
750-467), or PT100 (e.g., Wago 750-461) interface modules.
Note:
To help solve this task you should analyze the functions of the relational operators
GT, GE, LT, and those of the LE operator.
Light
S1
Fan
40
Exercises Fan Control
Function:
The control system for the light and fan is to be an element of the room automation
system. When the light is turned on after entering the room, the fan should cut in
after 5s (30s). The fan remains off if the light is switched on only briefly. When a
person leaves the bathroom and switches off the light, the fan should continue
running for a further 10s (2m).
Task:
Develop and test the project in which the function described above is
implemented.
S1
PT-TON
TON.Q
TOF.Q PT-TOF
Fan
41
Exercises Parking Lot Monitoring
Procedure description:
Initiators 1 and 2 issue a 1-signal when vehicles enter/leave. The capacity of the
parking lot is limited to 15 vehicles. The number of vehicles present on the lot must
be counted up/down as vehicles arrive/leave. The signal light should be green if
there are open parking spots available. The signal light must be red when the
parking lot is full.
Allocations:
VAR_GLOBAL
Initiator1: BOOL;
Initiator2: BOOL;
green: BOOL;
red: BOOL;
occupiedParkPl: INT;
freeParkPl: INT;
END_VAR
Task:
Develop a control system for this based on IEC61131-3.
42
Exercises Room Automation
Sliding
Push-button,
simulating a
position of a sliding
door.
Tasks:
A function module for latching and dimming must be written at the onset of
programming for this task. These function blocks are described in Section 3.
43
Exercises Room Automation
To do this, first create a new project (Section 2.1.1). You must then define the
communication parameters and PLC configuration (Sections 2.1.2 and 2.1.3). You
can then add an object by right-clicking on function blocks in the "Module" tab. The
following window is displayed after you click on "Add object":
Enter the name of
the function block
Here, you can define the type and name of the function module. The program for
latching operation is then added to the new function block. Refer to Section 3.2 for
information about the program and for a description of latching operation.
Following the same principle, you must then add a function block for dimming.
Refer to Section 3.1 for information about the program and for a description of
latching operation.
You can begin the exercise once you have completed the two function blocks for
dimming and latching.
44
Solutions
5 Solutions
45
Solutions
The elements Function block and Output, as well as others, are each assigned an
execution number in the CFC Editor. When the order (sequence) is displayed, the
assigned execution number is displayed at the top, right corner for the elements.
Display sequence
Sequence
The individual elements are calculated for the runtime in this order.
When an element is added, its number is assigned automatically in topological
order (from left to right, top to bottom). If the order has already been changed, the
new element is assigned the number of its successor in the topology and all
numbers above this are increased by one (1). The number is retained when an
elemented is moved. The number sequence affects the result and may have to be
changed is some cases.
It is therefore important that you define the order of the execution sequence of the
function blocks at the end of programming according to the direction of data flow
(see Figure 4.2).
46
Solutions
47
Solutions
48
Solutions
49
Solutions
The solution for exercise 5b is given in the same program (PLC_PRG) as the solution for
exercise 5a. Figure 5.7 only illustrates the newly initialized variables and only the program
for exercise b.
50