Training Manual V23 1006 IFM
Training Manual V23 1006 IFM
Training Manual V23 1006 IFM
Training Manual CoDeSys 2.3, 10/ 2006, from software version V020102
Guarantee note
This manual was written with the utmost care. However, we cannot assume any guarantee for the
contents.
Since errors cannot be totally avoided despite all efforts we appreciate your comments.
We reserve the right to make technical alterations to the product which might result in a change
of contents of the manual.
1.1.
1.2.
1.3.
1.4.
1.5.
2.
Installation...............................................................................2-1
2.1.
2.2.
2.3.
2.4.
Settings.................................................................................................... 2-7
New project............................................................................................... 2-7
Target........................................................................................................ 2-7
Subsequent installation of the target......................................................... 2-8
Main program.......................................................................................... 2-10
Directories................................................................................................2-11
Libraries .................................................................................................. 2-13
PLC configuration ................................................................................... 2-16
3.
The start...................................................................................3-1
3.1.
3.2.
4.
4.1.
4.2.
4.3.
5.
5.1.
5.2.
5.3.
5.4.
II
5.5.
5.6.
6.
Appendix .................................................................................6-1
6.1.
6.2.
6.3.
6.4.
6.5.
III
7.
IV
1.
Why this
manual?
Every user knows the problem: new software and new hardware. You will come
across many unknown issues which at the beginning take up a lot of time and
thus money.
When you work with the system more frequently you will find that many work
steps keep repeating themselves. You no longer concentrate on how to create a
new project or how to declare a variable but on the process to be controlled.
This manual therefore describes in many details, step by step, the procedure of
creating programs and handling the hardware.
When you use this manual as recommended, you will be able to quickly reach
your goal to effectively use the controller system ecomatmobile.
1.1.
1.2.
1-1
Headers
The header of each page on the right provides you with the title of the current
chapter. On the left you will find the current header of second order.
Footnotes
In the footnotes of each page you will find the chapter-related number of the
page.
Selective
reading
In the marginal column you will find comments which make finding certain
paragraphs easier for you.
There you will also find pictograms and markings the meaning of which is
explained below
Note
Arrow
Here you are given important notes to help you with the correct handling of
ecomatmobile.
1.3.
Printed media
1-2
Catalogue
Overview of the units with data sheets
Training manual 1
Step-by-step introduction
Electronic media
For some devices the system manual is
replaced by the online help..
Online Help
www.ifmelectronic.com
Each printed medium such as this manual will become obsolete sooner or later;
looking at the speed of technical changes, rather sooner. This also applies to
hardware and software. To find out about the current version, please see the
web address indicated on the left. Usually you will find there updates of the
software and the current version of the documentation for downloading ( e.g.
page 2-4). This concerns also the online help Figure 1.
1.4.
Hardware
In the training manual reference will be made quite often to the hardware. To be
noted:
The different types of the controller ecomatmobile type R360 (e. g. CR2500,
CR0020, CR0505) vary in their different hardware configurations.
1-3
Hardware
It would be much too complicated to write an introduction into the software for
each type. That is why as an example the handling of the controller
CR0020
will be described.
When you work with another type later on, this must, of course, be taken into
account for the examples. Another subdirectory must be set and other libraries
must be loaded. Since the type designation, here CR0020, is also used for the
directory and file name, e.g. subdirectory ifm_CR0020 etc., this should be no
problem. To keep the following text clear, this will not be pointed out separately.
When, for example, you work with the starter set of the controller CR2500,
virtually everywhere 0020 can be replaced with 2500 in the following examples.
The only difference is that with the starter set some steps can be skipped. Here
some settings have already been made to facilitate the start, e.g. the operating
system has already been loaded. No harm is done, though, if for example you
load the operating system once again for reasons of practical training.
1-4
1.5.
Features of a PLC
Cycle
The advantages of a PLC as compared to a conventional contactor controller
does no longer need to be pointed out today. Now there are also controllers
with mechanical and electrical features which are necessary for use in mobile
machines, e.g. protection IP 67, high mechanical stability and electrical noise
immunity. These may also be the reasons why the reader has decided to use
the ecomat mobile system. For those who do not yet have any experience with
a PLC some features which sometimes present problems will be briefly
described in this chapter.
Cyclical
program
processing
One characteristic of PLC systems is the cyclical program processing. This has
some consequences for programming which will be briefly shown below.
1-5
Features of a PLC
At that very moment somebody flips the selector switch. If the state of the input
were enquired about again, the condition for the next program step would also
be fulfilled: the output "move to the right" would also be switched with a possibly
spectacular result.
It may also come to conflicts which cannot be seen and prevented during
program creation.
Unambiguous
signal states
Priority
This may seem quite theoretical but it does have some consequences for
practical use. The priority of instructions can be determined in the program by
their sequence!
If, for example, there is an instruction in the program:
if limit switch reached, then stop drive
then it is usually placed behind the instruction for switch-on. Usually the
conditions for switch-on and switch-off should not be fulfilled at the same time.
If, however, due to a malfunction this does occur, then switch-off takes priority
(compare pages 4-2 and 4-3).
Thanks to the cyclical program processing, reliability is provided due to
unambiguous signal states. However, other consequences have to be put up
with.
1-6
Time response
Only timecritical
processes
If the time response is uncritical, if a ms does not matter, then the comments on
the time response do not have to be taken into account.
Cycle time
The time the controller needs for one program cycle is called cycle time.
There is no easy answer to this question. It makes sense that it is longer for
long programs and shorter for short ones. It also depends on the type of
instructions. Logical conjunctions are processed considerably faster than for
example arithmetic operations. The answer is not clear if there are jumps, for
example. If the condition for the jump is fulfilled, a program section is skipped.
In that case it is not processed. The cycle is shorter. If the condition for the jump
is not fulfilled, the cycle time becomes longer.
ms
Therefore only an estimate can be given here. You can expect a short time
from an efficient system such as ecomat mobile. It is indeed in the ms range.
For shorter programs it may be shorter, for more complex programs it may be
several ms.
To determine the actual value of the cycle time: page 4-7.
Now it is easy to understand the demands on input signals.
An input signal has to be active at least during one complete program cycle.
If a signal is shorter it depends if it happens to come at that point of time at
which the inputs are read. Only then will it be recognised.
Response
time:
This value is often used to characterise the time response of a PLC. This is the
time that is needed to switch a signal from an input to an output. If you expect
the worst case, this means twice the cycle time.
Frequency
In some cases, for example when evaluating encoder signals, you also have to
ask about the frequencies that can be processed on the input.
If the cycle time is for example 1 ms, the cycle frequency is 1 kHz. However,
this does not mean that the frequency on the input can be 1 kHz. To recognise
a pulse as a pulse, a FALSE signal and a TRUE signal have to be detected;
otherwise the pulse cannot be distinguished from a static state. The signal
frequency must be half the cycle frequency at maximum. To allow possible
fluctuations in practical use it should be significantly lower.
To be more precise, this is only one necessary condition. If the signal frequency
is higher than half the cycle frequency, the pulses can no longer be processed
accurately. If it is lower, the signal shape also has to be taken into account. If,
for example, the cycle frequency is 1 kHz and the signal frequency is 100 Hz,
you could think you were on the safe side. If, however, the FALSE signal is 9.5
ms and the TRUE signal only 0.5 ms, the pulses cannot be processed
accurately. To be on the safe side it is necessary that the FALSE as well as the
TRUE signal, each one separately, is longer than the cycle time.
1-7
Features of a PLC
An unfavourable signal shape does indeed occur in practical use. If, for
example, speed is to be monitored by evaluating the pulses of a puck, the
TRUE signal is short if the diameter of the puck is small.
An example is shown on the left side of Figure 3. Often metal screws are used
in a plastic disc. If the signals are not detected reliably, a metal strip can be
used. Its length should be 1/3 to 1/2 of the circumference. The optimum markto-space ratio of 1:1 can thus be easily obtained.
Frequency
inputs
Usually there are only higher frequencies if encoders with a high resolution are
used. To be able to process higher frequencies the controllers have so-called
frequency inputs. This ensures that signals up to 50 kHz are reliably detected.
This is an exception from the usual cyclical program cycle.
Filtering
The maximum frequency for standard inputs is limited since they have a lowpass filter. Thus increased protection in the event of noise against interference
peaks is obtained. On the other hand the frequency inputs are more
susceptible.
Optimisation
The experienced PLC programmer knows ways to optimise the cycle time for
time-critical processes. Since this manual is an introduction we will not discuss
this any further here.
Bus systems
1-8
Watchdog
A PLC monitors itself if the cycle is correctly processed. The case that a
program cycle is not complete is dangerous. Then no inputs are read. A change
of the state on the input, e.g. "limit switch reached" cannot be processed. The
status of the output cannot change, e.g. the drive keeps on running although the
limit switch has been reached.
The watchdog function exists to avoid such states. If the end of the cycle has
not been reached within a certain time which is started with each new cycle the
watchdog becomes active. The controller is stopped and the outputs are
disconnected. This time does, of course, depend on a maximum possible cycle
time. In ecomat systems it is approx. 40 ms.
What can cause such an event?
Causes
1. Hardware error
If a processor fails, for example, the controller must pass into a safe state.
2. Program error
We will describe this second point here in more detail. Those who already have
some programming experience, for example on the PC, are especially
vulnerable to such errors. In a PC program a window can be created with the
text "Enter value" and an input field.Then the keyboard is enquired about if a
value has been entered. If so, the value will be processed. If not, the keyboard
will be enquired about again until the input has been made. It does not matter if
the user has a coffee break, a lunch break or does something else during that
time.
There must not be any closed loop in a PLC program; only the program cycle
itself may be such a loop. A possible cause of an unintended closed loop may
be a backward jump. Since this is dangerous, a warning is issued during
compilation of the program.
In the worst case it is possible that the communication between the PC and the
controller is impaired. Log-in is then no longer possible. In this case the
downloader tool ( page 3-36) will help.
1-9
2.
Installation
2.1.
Hardware of the PC
Minimum
2.2.
Software setup
Set-up
The installation is started as usual. If the autostart function of the CD-ROM drive
is active, the ecolog software installer starts. The selection will be described
below.
Figure 4: Installer
2-1
Software setup
Here we are dealing with CoDeSys 2.3. This is the software for programming
the current hardware. Therefore the programming examples below were
created using this version.
Figure 5: Version
The version you use depends for example on your hardware version, on the
version of its operating systems, etc. If you use different versions it may
become necessary to also install different software versions. You can, of
course, install this and other programs subsequently, for example if you want to
work with a PDM or with CAN modules. You may also want to install the
documentation on your PC. To be able to see or print the documentation here
or on CD you need Acrobat Reader. These installations will not be described in
this training manual.
The software is installed by clicking on Setup. The individual steps will not be
described here.
We recommend to adopt the default settings, e.g. the directory name, paths
etc. This will save unnecessary work. This will also make it easier to
understand the following examples.
2-2
Installation
Documents
device-specific information
Help1
help files
Library
general libraries of 3S
there:
PLCConf
device-specific files
For CAN users: here are the EDS files. If other devices are to be connected via
CAN, their EDS files have to be copied into the directory PLCConf.
Projects2
The directories with the comment 'Temp' which are created in 'Projects' can
be compared with an automatic backup. They can be deleted without any
problems. The only file that is absolutely necessary is *.pro .
Targets
target systems
there
ifm
there
Help
ifm-specific files
and e.g.
ifm_CR0020cfg
there finally the directories with the configuration data files. If
several versions are needed, they have to be in separate
directories, e.g. the directory:
V030002
Library
there: general ifm-specific files, device-specific files in turn are in
subdirectories, e.g.:
ifm_CR0020
in which there is the operating system and the specific library.
2-3
Software setup
If you work with different versions, to be seen from the version number, e.g.
V030002, it is important to remember that the versions of the configuration data
files and of the operating system match!
This structure may seem a bit confusing. In general you are not confronted with
it and therefore you do not have to worry about it.
This structure is created by CoDeSys during installation. During program
creation CoDeSys accesses the required files and searches for them in the
defined paths. Therefore we advise against changing the directory structure
after installation.
If you work on several PCs, you have to remember that it makes the exchange
of program files easier if the same directory structure is installed on each of
these PCs.
What does e.g.
V020102
(version
number)
mean?
V02 is the actual version, 01 stands for the date of the update (release), 02 for
the patch number. The current version can be found on the web ( 1.3). The
new versions are, for example, required for the new hardware versions. We
recommend to change this version only if it is necessary. It is a lot easier, if all
systems used are of the same version, even if it is not the latest one.
2-4
Installation
This is an important tool. Again, not each and every detail can be discussed
here. Usually only the function described on page 3-33 et seqq is needed. In the
event of frequent programming it is worthwhile to study this tool in detail (
e.g. Notes in Help concerning the downloader).
The installation should not present any problem. We recommend to adopt all
default settings.
2.3.
Program start
CoDeSys is started via the icon in the start menu, for example.
Info
2-5
Program start
Error message
If one or several error messages are displayed, other paths may have been
selected during set-up. For the time being they can be ignored. Further below
we will describe the adaptations that will have to be made.
We will not deal with this any further here. The continuous work on this project
is made easier if the one opened last is loaded automatically during program
start-up. Therefore the example program will open here. If you do not want this,
you can change it via 'Project' 'Options'.
2-6
Installation
2.4.
Settings
New project
Before starting with the programming of the controller you would normally have
to make some additional settings. This has to be done for a configuration only
once at the beginning, compare page 2-19.
In the starter set all required settings have already been made. The following
descriptions are only for information if you work with it.
These settings are part of each project and they are saved with it. This way you
can easily work on projects for various hardware configurations with the same
user interface. To show how the settings are made we open a new project via
'File' 'new' or
a new project.
Target
A window to create the target system will open.
2-7
Settings
When a concrete target system has been selected, the window is enlarged
considerably. Many tabs are for functions that are not supported by this
hardware. CoDeSys is a universal programming system. The most important
tab is the one for 'Network functionality'. There the parameters for
communication are set via CAN. This is not a topic here ( Training manual 2:
Communication with CAN).
But it is easier to prepare us for working with CAN just now. For this reason,
please let the options 'Support parameter manager' and 'Support network
variables' active. Then we have to append the subelement CANopen Master in
the PLC Configuration ( Figure 30). Then the topic CAN can be ignored for
the moment.
What has to be done, if the article number is not displayed in the selection
screen?
This will only happen with new hardware. Then the respective file will be
ordered from ifm electronic or loaded from the Internet and installed
subsequently.
2-8
Installation
2-9
Settings
was opened. The files that can be seen there have the extension: TNF (for
target information). As an example ifm_CR0020_V030002.TNF is marked and
'Open' is clicked on. At first you cannot see a big difference. There is only a
new entry in the left box. By clicking on the '+' next to 'ifm' the structure is
shown in detail:
Main program
2-10
Installation
The inputs in this start window are of special importance. This will be described
in more detail further below. For the time being we select the option FBD and
confirm it by OK.
A remark beforehand: Do not change the name PLC_PRG!
Directories
Search path
This is done via the menu items: 'Project' 'Options'. Select the category
Directories in the displayed dialogue box that opens ( Figure 16).
2-11
Settings
If you work with different hardware types in other applications or e.g. in the
starter set, the entry has to be adapted accordingly. Example:
CR0020
C:\ Program files\ifm electronic\CoDeSys V2.3\targets\ifm\ifm_cr0020cfg\VXXXXXX
XXXXXX means: The version number may be different.
Settings which are usually not preset were already made in the starter set. This
makes it easy to work with the device right away.
2-12
Installation
Libraries
Predefined
functions
File size
Each added library makes the project file bigger. Therefore no unnecessary
libraries should be added. At the beginning it may be difficult to judge which
library is necessary and which is not necessary. A hint is given by the name of
the library. If, for example the name is ifm_CR0020_V030002.lib, you will only
need the library if you work with the unit CR0020. As experience increases,
differentiation is getting easier. However, the file size is only critical with very
complex programs.
A consequence resulting from the keyword file size affects the program
modules created. It is unfavourable to combine them all in one library. If they
are separated it is easier to focus on those that are actually needed.
No menu
active
If no project is open, most menu items are not active which can be seen by the
grey colour.
To activate them a project has to be opened. This is done via the menu item
(you will find an overview of the buttons
'File' 'New'or the respective button
in the appendix, page 6-1). The procedure was described above, chapter
2.4. To be sure let us compare:
The top line then reads: 'CoDeSys - (Untitled)*'
The name can be assigned when saving the file.
Step by step
The menus are context sensitive. In other words: the window 'Library
manager' only opens (of course!) when a project is open. Here it becomes
clear what is meant by "step by step" in the instructions. Those who are not
familiar with the system should strictly follow the instructions. As experience
increases more interim steps can be skipped.
CR0020 as an
example
Below we will show how to prepare a project for the controller CR0020 as an
example.
Entries
2-13
Settings
If during program creation you are not sure which module is needed or what
the inputs and outputs mean you have the possibility to call help via Help in the
toolbar. There you will find detailed descriptions and examples. Often it is faster
and easier to call the library manager and to mark the respective module there.
Then you can often find the information you are looking for in the declaration
part (Figure 22 top right). This applies in particular to the device-specific
libraries ( Figure 22). The help would be much too extensive if all devicespecific modules were explained there. A glance at the library manager can
save leafing through the manual.
2-14
Installation
2-15
Settings
We are not done yet! Programming not only requires the library files but also
e.g. the operating system or predefined system variables. It is therefore not
sufficient to only insert the libraries in the manager. In addition the settings
have to be verified and possibly adapted during PLC configuration.
PLC configuration
CR0020
Here again we refer to the device CR0020. As mentioned above, the respective
settings have already been made in the starter set so that we do not have to
worry about them. For a new project for the starter set the library
ifm_CR2500_VXXXXXX is added again. Since the features of the hardware
versions are fixed, various variables have also been declared in advance.
Declarations
As is the case with each efficient software, variables are also declared in
CoDeSys. Declarations, presentation, notations etc. are described in detail in
the manual for the program development. In our manual we will describe this
process briefly in the individual steps (e.g. page 3-44).
2-16
Installation
2-17
Settings
2-18
Installation
Master
For those who process new projects quite often it is worthwhile to save the
project as Master_CR0020_V030002, for example. The name says what it is.
Working with a master is facilitated by the menu item 'File' 'New from
master...'. This opens any project with the name '(Untitled)*'. The * indicates
that the project has not been saved yet. The new name is assigned when the
file is saved. The menu item can, of course, also be used to create a new
version of a completed project. You will get the same result as before with 'File'
'Save as...', see page 3-29.
2-19
3.
The start
This chapter is a kind of "introductory course for CoDeSys". You will get to know
the operation and the handling of the program, i.e. you will get a brief insight
into almost every function of CoDeSys.
The most important part of this introductory course is the complete creation of a
program example directly on your PC.
3.1.
What is
CoDeSys?
What is IEC61131-3?
What is a
project?
What
programming
languages are
available?
- LD
(ladder diagram)
- IL
(instruction list)
(structured text)
3-1
How is a
project
defined?
How do I test
my project?
The true test of a project is the commissioning of the actual system. On the
other hand, the simulation mode of CoDeSys has proven to be a very valuable
possibility for testing the program.
What is the
simulation
mode?
The simulation mode simulates the program run of the controller in the PC.
This type of test without using the control system or the plant enables the
elimination of errors at the desk, thus saving time and nerves. This effect can
be enhanced by displaying the simulated plant by means of corresponding
visualisation screens.
The use of the simulation in conjunction with the versatile debug functions
(troubleshooting functions) in CoDeSys allows a simple and efficient complete
program test.
Which debug
functions does
CoDeSys
have?
Execution of programs
- as single scan
- from breakpoint to breakpoint in the simulation mode
And the
documentation
?
Conclusion
3-2
The start
3.2.
Task
A lamp C is to be ON when two switches A and B are closed. This really simple
system can be shown as in Figure 32.
implement and
Start CoDeSys
Starting a new
project
To start a new project select option 'File' 'New' or alternatively click on the
button . This step was already described in 2.4, page 2-7.
Target system
and PLC_PRG
3-3
language is to be FBD.
Check if all these points
correspond
Name: PLC_PRG
Type: Program
Language: FBD
3-4
The start
If you have not yet done so, work through the sections on pages 2-11 to 2-19.
Add Program
Adding an
P_AND
Add a program with the name P_AND to the project with menu item 'Project'
'Object' 'Add... ' (Figure 35).
The name must not be AND, for details about the term 'key words' see page
3-6.
3-5
Defining variables
In the context of programming, the definition of the characteristics of a variable
is called a declaration. Variables can be displayed as a table or a text. Below
we will describe the text options.The selection Declarations as text is the
default setting. It can be changed in 'Project' 'Options' 'Editor' if requested.
Defining
variables (text
form)
Key word
The new variables A and B are to be defined as binary, i.e. boolean. To do so,
we proceed as follows:
Move the cursor to the end of line 0002 and press the Enter key (Figure
37).
3-6
The start
by clicking on
3-7
Here we want to point out a possibility to help you program more efficiently and
avoid typing errors at the same time: the <F2> key. When working with
CoDeSys you often reach points requesting a selection between several input
possibilities.
You can see an example in Figure 41. CoDeSys has entered an AND operator
here as default setting. The field with the coloured background (Windows
standard setting is blue) signals such an option. Press <F2> to open a selection
screen. Try it, and you will get a list of operators that can be used here or other
boxes. You can select the requested operator by means of a double-click. This
option saves a lot of typing and prevents typing errors! In our case the default
setting AND is okay and you should close this selection screen by pressing
(Figure 42).
3-8
A common mistake in the early stages is to open a new project and to forget the
libraries and the hardware configuration (pages 2-13 and 2-16) in the heat of
the work. You will become aware of it when you use the Input assistant for a
particular function block, for example. If you do not find it the reason why is that
you probably have not linked any hardware-specific library, for example.
The start
Operands
Add the operands A and B as inputs of the AND operator by replacing ???,
Figure 43. You can also use <F2>, Figure 44.
3-9
Position of the
cursor
Here the editor is not very flexible. It happens again and again that you want to
add an element which the editor refuses, however. In most cases the reason
why is that the cursor is not in the right position. This is meant to prevent
incorrect entries. You will usually find the right position of the cursor by trial and
error.
The entries in this window can be changed individually. In this case they are
exact. A comment should be added.
You should make it a matter of habit to add many comments. This is taking
some time at the moment. However, you will save a lot of time for
troubleshooting or modification of the program.
After entering the comment you can acknowledge by clicking on
. The
variable declaration is now entered in the top part of our module window.
3-10
The start
3-11
Local
In the fields class and type the default settings were simply adopted. We just
want to point out that the variables in the example were declared locally. That
means that the declaration only applies to the POU in which it is located, here in
the program And. If a variable, e.g. an input, is to be used in several POUs it is
easier to declare it as a global variable. Using the selection field type helps to
avoid invalid declarations. During declaration the 'Autodeclaration' option also
helps to prevent syntax errors which may cause confusing error messages in
compilation, especially at the beginning.
This completes our little POU.
Activating
P_AND in
PLC_PRG
Box
1. Open
PLC_PRG by
double
clicking
2. Enter the
program call
Figure 51: Enter program call in PLC_PRG
At first the default box, the AND operator, is added. By clicking on F2 the Input
assistant opens. Select the 'User defined Programs' option on the left (Figure
in the box on the right. You activate P_AND
52) . Then select AND and
in network 0001 of PLC_PRG.
3-12
The start
Saving
At first, it will take some time for you to achieve this result. Later you will be able
to program an easy link very fast.
In each case it should become normal to save the result after each work step.
This can be done e.g. via 'File' 'Save' or
3-13
Other languages
And what about
the other
languages?
At this point it would go too far to explain the other languages in more detail.
Still, we want to show you our little program example in Instruction List, in
Structured Text and in Ladder Diagram (Figure 55).
3-14
The start
What have we
achieved so
far?
So far we have written two programs (PLC_PRG and P_AND). The subroutine
P_AND was entered in PLC_PRG so that P_AND is now also activated by
PLC_PRG.
Program test
How do we
continue?
Our project has now reached a stage where we can test if it meets our
expectations. The first program test is normally carried out as follows.
'Online'
'Simulation
Mode'
Select the option 'Online' and make sure that the simulation mode is active.
This is the case when you see a tick () before Simulation. Should that not be
the case, click on 'Simulation Mode' (Figure 56).
'Online' 'Start'
Activate the program by 'Online' 'Start' ( Figure 56) or press the F5 key or
click on . The status line (shown below in the program window) should now
show
.
3-15
Display the P_And program on the monitor (double click on the program name
in the POU list on the left in the program window). The program window should
look like Figure 57.
Change
variable values
As shown in Figure 57 the values of the three variables A , B and C are FALSE
(OFF). By means of the option 'Online' 'Write Values' the values can be
changed as follows:
Double click on FALSE at A and B and TRUE appears as shown in Figure 58.
This figure shows that the changes are not yet active! They have to be sent to
the (simulated) controller first.
3-16
The start
3-17
Forcing
Example
Besides the "manual" preset of input states, e.g. on the simulator box ( 3.3), it
is also possible to force the states in the controller. This means that e.g. the
state of an input is defined without any consideration of the actual state. When
playing with the software without any inputs and outputs connected there is,
however, no difference to the off-line program test in the simulation mode. In
practice this function is more useful to the skilled user for debugging. The user
should be skilled because forcing might start unintended processes when the
controller is connected to the peripheral equipment. If you use this function you
should know exactly the kind of damage that might be caused by a possible
avoidance of safety scans in the program.
When a new program or a new machine construction is tested, it is possible that
a drive stops in an interim position without the end position having been
reached. Then the drive has to be driven to the end position "manually". When
the limit switch is used as a condition in a program module to stop the drive, the
output for the drive can be set to TRUE using 'Write Values'. As soon as the
limit switch has been reached, the drive is stopped by the program. Here the
program is of higher priority ( also page 4-9). E.g.:
If 'Force Values' is used, the drive will no longer be stopped by the limit switch.
This means that forcing the outputs should be avoided, if possible. It is only for
inputs that forcing cannot be avoided.
3-18
The start
Visualisation
Now that we have tested the function of the system let's move on to
visualisation which will be explained below.
Safety
Visualisation with CoDeSys has to be done offline. To be on the safe side you
should try to remember to stop program processing by
before logging out.
Then log out CoDeSys by activating the option 'Online' 'Logout' or by clicking
on .
The moment the program has not yet been completed, maybe even still
contains errors, dangerous situations may arise. The controller could start e.g.
unintended and unexpected processes, drives, movements, etc. if locking has
not or not yet been programmed correctly.
Select
'Visualisations' and
'Project' 'Object'
'Add...'
Add new
visualisation
screen
Upon activating the option 'Project' 'Object' 'Add...' you will be asked to
indicate the name of the new visualisation screen (Figure 62). We have chosen
the name AndVis. Once the name has been entered a new empty visualisation
screen appears ( Figure 63).
3-19
At first a grid is displayed in the default setting. If you do not need it, you can
eliminate it in 'Extras' 'Settings...' .
Drawing a
picture
Eighteen different types of elements can be drawn and animated with the
visualisation. First, we will use the rectangle. The other elements are created
and animated in the same way.
Activate the option 'Insert' 'Rectangle' (Figure 64) or click on the button
draw a rectangle by
pulling the mouse to the bottom right until a rectangle of the required size
appears
3-20
and
The start
Context
To establish a context between picture element and module variable you need
to define a context between (visualisation) action and (variable) value.
These entries are made in the screen 'Regular Element Configuration'. For
entering variables <F2> can be used again. But first, the project needs to be
rebuilt in order to generate the variable list. For this purpose, call option
'Project' 'Rebuild all'. In this case, however, it is not necessary since we were
logged in before (page 3-16 and the project is rebuilt automatically after login.
Configuring
element
A double click on your new rectangle opens the window for the configuration of
picture elements in the visualisation (Figure 66). For each category there are
input fields describing the picture element. It is not necessary to make an entry
for each field. First select the category Variables.
3-21
3-22
The start
Interaction
Interaction between the user and the variables of the system is to happen via a
mouse click on the picture element. The state (TRUE/FALSE) of the assigned
variable is to be changed and displayed accordingly (the so-called toggling, see
Figure 69).
Change colour
The status of the variables is indicated by the colour of the picture element. This
happens after the following assignment between picture element and variable
value has been made:
Activate
interaction
color
alarm color
variable TRUE
variable FALSE
3-23
Click on
to open the colour selection screen in the category
Colors Figure 71. Select a colour by clicking and confirm with
. As this is
the colour for the FALSE state of the variable, we have selected grey for our
example.
3-24
The start
To give our rectangle a name, enter the letter A in the category Text. This
designation is entered in the centre of the element.
The window 'Regular Element Configuration' should now look like Figure 72.
.
If this is the case, close by pressing
3-25
Variable B (a
simple copy)
We now want to create another picture element for variable B that should look
like the one for variable A. The option Copy/Paste will be helpful. To do so:
Click on element A
Click on
Click on
3-26
The start
Variable C
Copy the element of variable A again for the presentation of variable C. Change
the configuration of the new element as follows:
Shape
: ellipse
Input
: no input
Color/Alarm Color/Inside
: red
Variables/Change color
: P_AND.C
Text
:C
The display of the elements has been slightly changed as compared to A and B
to make clear that they are different variables (inputs and outputs).
An entry in the entry field does not make sense here because the presentation
of the variables (of the output) is controlled by the program.
It is an interesting option to control an output "manually" for test or maintenance
purposes, i.e. via visualisation. However, this has to be taken into account to
reliably avoid conflicts, Figure 130.
Whichever way you have taken - the configuration window should look like
Figure 75.
3-27
We can now test the newly created visualisation picture. Log in CoDeSys and
start the program. Proceed as described before. The following points will serve
as a reminder:
Online Login'
Online Start'
3-28
The start
To save your project, use the option 'File' 'Save as...' ( Figure 53).
3-29
When the correct option is activated ('Project' 'Options' 'Ask for Project Info')
is activated, a dialogue box for project information is shown automatically before
saving (Figure 80).
3-30
The start
3.3.
Online test
We now want to load the same program into the controller and test it there.
Preparations
Simulator
We will now work with the physical hardware. You will need to define the input
states and watch the reaction of the outputs. That is what we use the EC 2014
simulator for. It can be used directly for testing simple program functions. A
different simulator box is used for the starter set.
Starter set
When working with the starter set the following section can be skipped.
Familiarise yourself with the accessories of the simulator. It consists of:
EC 2022
EC 2023
EC 2014
the actual simulator. The plug on its cable is a special version. An additional
socket is brought out of it which permits the connection of another CAN
component.
Adapter RS 232
Adapter
Supply voltage
The connecting cable is firmly connected with the simulator. On the controller
side it has a 55-pin connector used in mobile controllers to ensure the high
protection rating.
Control box
PC
The connection is made via the supplied cable. It has a 9-pole socket on the
side of the PC. If the PC has COM2 as a 25-pole connector, an additional
adapter is required. It has a multi-way connector strip on the side of the
simulator. The corresponding location on the simulator is marked RS 232/RxD
3-31
Online test
and RS 232/TxD. Above it there is the marking CANH and CAN L to point out
that the CAN bus can be connected to the unassigned terminals.
A power supply is integrated in the control panel used during the trainings. As
long as you work with the simulator, the supply voltage can be taken via the
CAN connection because the supply voltage is on the same potential in the
whole (simulator) system.
Operating system
In principle, the steps for loading the operating system must be executed only
once. When the system is delivered, no operating system is stored in the
controller. It must be loaded only once. The procedure must only be repeated
(again only once) when a new version of the operating system is required. This
shows how flexible the control system is. For a PC for example the installation
of a new BIOS requires the exchange of an EPROM. This is only successful if
hardware compatibility was checked thoroughly. This has only changed for the
current version. For the ecomat R360 only the software has had to be loaded.
For the controller in the starter kit the operating system (and the first test
program) has already been loaded.
If you have to load another operating system version or if you want to load an
operating system into a new controller, use the program downloader. This
program is on the CD "Software, tools and documentation" and can be installed
via the installation platform. Here you will also find the description of the
downloader, 2.2.
If you have not prepared this step, the downloader will now have to be installed.
Start set-up as described in 2.2, Figure 4 to Figure 6. By clicking 'ecolog
downloader' , Figure 81 will take the place of Figure 6.
3-32
The start
3-33
Online test
3-34
The start
If you want to continue working right away, skip the following short overview of
the downloader.
Downloader
For detailed information about the downloader see Documentation on the CD.
Using the downloader ensures, e.g.:
- to load the operating system in the controller (which happens in the next step)
- to read the program file from the controller
- to write the previously read program file into a new controller
- to save data from the controller
To be more precise, the program file is read as a hex file. This depends on the
fact that the entire file for the project, the source file, with visualisation,
assignments, declarations, comments, etc. is stored on the hard disk of the PC.
The compiled program file is then loaded into the controller as a hex file. After
reading, this file can virtually not be edited. Reading would make sense, e.g., if
you want to transfer a program from one controller to another and the source
file is not accessible. The other functions are self-explanatory.
To save a program file only use the Downloader tool, not the items 'Write file
into controller' and 'Load file from controller' in the 'Online' menu of
CoDeSys.
We will show you briefly how to load the operating system. Here it would not be
necessary because one system has already been loaded.
The file needed has been opened in the downloader. The only thing that
remains to be done is to click 'Load into controller' (Figure 85) and to wait
until the process is completed.
Interface
If you receive an error message while the connection between the PC and the
controller is being established, (Figure 86 or Figure 83 instead), you should
check if:
- the controller is switched on or
- the correct interface is set up.
E.g.:
3-35
Online test
3-36
The start
Of course, we have to modify the first project EasyAnd for the online test. For
this purpose we will first create a copy with the name ANDOL with 'Save as...'
as described above.
Login
First of all the connection to the controller is established via 'Online' 'Login' or
('Simulation Mode' off!). If this does not work more settings will have to be
made.
The following message may be displayed:
3-37
Online test
next to Tcp/Ip.
3-38
The start
3-39
Online test
If other error messages are displayed during log-in, it may help to increase the
baud rate. The advantage is that the program is loaded faster. It has to be noted
that it is not sufficient to increase the baud rate on the PC. The baud rate in the
controller must be adapted to these values. To do so, the downloader has to be
started in a special "expert mode". Ask your sales specialist.
This setting procedure may seem to be somewhat complicated. However, it only
has to be followed once at the beginning.
Let us assume now that communication runs correctly.
After log-in you will get the message to download the program.
If no program had been loaded into the controller before, you will receive a
message that is slightly different from Figure 97. If, however, there is already a
program in the memory of the controller, it will be overwritten by the new one
and thus it is lost if the source program is no longer available.
Before overwriting the loaded program you can, if required, save it with the
independent downloader program ( page 3-35). You can, of course, only save
the program file of the controller, the source program is not saved in the
controller. The program file has been saved, but cannot be edited.
If you are not sure if a source file is available, a saving process should be
carried out. Otherwise the program in the controller will be overwritten and
cannot be restored without the source file.
The message can now be acknowledged with
Start program
When the program has been loaded in the controller, program processing has
to be started. The line at the bottom, the status line, reads (after starting):
3-40
The start
Assignment
At first you cannot see any difference to the simulation mode. But the simulator
has not even been used yet! The state of the inputs does not influence the state
of the variables A, B and C! This would not be possible anyhow since no
assignment has been made. In our example it would make sense to assign A
and B to inputs and C to an output.
But how can the controller start processing the program without this
assignment? A, B and C were declared as BOOL. This is a declaration for bits
that are not assigned to any input or output. In a PLC such bits are a useful tool.
They are flags. That means that the program is only processed in the flag
range. It is also possible to assign a defined address to a flag. If this
assignment is not made by the programmer, it is done automatically by the
program. In many cases it is of no importance which flag address is used.
So the project still needs some modification before it can be tested with the
simulator.
Declarations
To demonstrate the process again, we will simply delete the declarations. The
common editing functions can be used: Mark and Delete. The new declarations
are entered automatically so that the blank lines can also be deleted.
opens:
3-41
Online test
%IX0.08
Mark for physical
address
Type
I: Input
Q: Output
M: Flag
depending on the
controller configuration
Length
X: 1 bit (BOOL)
B: 8 bits (BYTE)
W: 16 bits (WORD)
D: 32 bits (DOUBLE WORD)
3-42
and
The start
Note the key word AT which stands for the actual assignment.
The assignment of the inputs results from the location of the control box (
labelling of the simulator). B and C are declared accordingly, C of course as an
output (%IX0.09 and %QX0.04).
The visualisation also needs to be adapted. Above the window Regular Element
Configuration was opened by double clicking the object designated A. In Input
the function Toggle Variable was selected. However, this does not make sense
any longer. It is the real states that are to be displayed. Therefore the tick is
removed in Input for A, B ( Figure 69), for C it should not have been possible
before to make an entry.
The project has now been modified for testing in the controller.
Before the online test, you should check if controller and simulator are ready.
Login
The program is then compiled again via menu item 'Online' 'Login' or
(compilation is started automatically after a modification) and loaded in the
controller 'Online' 'Simulation' not active!).
A look at the status line reminds us that the program needs to be started. That's
what we are going to do now.
3-43
Online test
Online
The declaration part shows the current states. In addition, the function AND
simplifies the checking of the state of the variables by showing them in different
colours depending on their state. The presentation on the monitor, in AND and
in the visualisation, should show no change as compared to the simulation.
The difference is that we do not work with flags any longer which change their
state via mouse click, but with the physical inputs and outputs. The state of the
inputs is defined by switches of the simulator box.
Output
So the program should now be processed as in the simulation. The state of the
inputs can now also be verified on the simulator. In doing so it is noticeable that
the state of the output changes according to the state of the inputs in AND as
well as in the visualisation (see page 3-19 above for the description of how to
activate it). However, it does not change on the simulator. Why is that so?
In this context we have to remind you of the monitoring concept, system
manual. There it is described that the RELAY bit has to be set so that the
outputs are not only switched internally like flags but also externally.
RELAY
For the time being, this bit will not be further processed by the program in this
simple example. It can be easily used as the first program network. Before the
first network a new program network is created by 'Add' 'Network (before)' in
the window PLC_PRG . The content reads:
TRUE RELAY
The name and the assignment to a flag address are predefined. This
information is given in the window PLC Configuration. In the Input assistant
(F2) you will find the variable as System variable.
Program test
3-44
After login during which the changed program is compiled again the program
has to be restarted. The relay should now energise with a perceivable click.
Now you can also see on the simulator that the output is switched.
The start
Sampling Trace
For a program test it is very useful that the current states of the variables are
displayed. But there are limits. If, for example, you want to simultaneously
monitor several variables defined in different windows, it is not always possible
to change the windows fast enough. For this purpose you can enter different
variables in a special window, the Watch Window. This is done via 'Window'
'Watch Variables'. We will not go into any further details here. You can find a
detailed description in the Manual for the Program Development.
Trace Tool
It is a matter of luck (even in the Watch window) to detect e.g. short input
pulses on the monitor. In many cases it would be of advantage if the variables
were shown in a timing diagram, like on an oscilloscope. CoDeSys provides this
possibility. It is called Sampling Trace. Since it is an important tool we will give
you a brief example.
Sampling Trace
3-45
Online test
You find the other functions via the context-sensitive menu Extras. First, we
define the variables to be monitored. This is done via 'Extras' 'Trace
Configuration...'.
3-46
The start
Let us first explain the background. Max. 500 values of each Trace Variable
can be saved. When the memory is full, sampling starts again from the
beginning. The oldest values are overwritten. If you want to evaluate the
Sampling Trace in peace, for example, you have to stop it so that the values
are not overwritten. That can be done "manually, via the menu, or
automatically by means of the Trigger Variable. If you enter A here, for
example, the next 50% of the values will be sampled after A has changed its
state from 0 to 1. Sampling would then be stopped.
In the example the Trigger Variable is not used. The field remains empty.
Sample rate
Trace variables
To enter the Trace variables in the list, enter them in the bottom field first. Use
<F2>. Double-click on P_AND. and A, B and C are displayed. They are
selected and entered in the list. Since they were defined in the P_AND POU,
the POU name, separated by a dot, is used as a prefix.
In the Input assistant the variables can only be found, in visualisation as well as
in sampling trace, if the project has been compiled once, e.g. with 'Project'
'Rebuild all'.
3-47
Online test
The window Sampling Trace is empty. The variables now have to be assigned
the colours with which their state is shown. Click on
next to the field below
Var 0 and the variables that can be selected are shown. Click on P_AND.A and
Var 0 is assigned to variable A. Do the same to enter P_AND.B and P_AND.C.
To be able to monitor the state of the variables, establish the connection to the
controller via 'Online' 'Login' or .
The trace is sampled in the controller as communication is too slow to save all
values in the PC. The Trace Configuration therefore has to be downloaded to
the controller.
After the program has been started, the Trace configuration has to be
downloaded to the controller and activated with 'Extras' 'Start Trace'.
3-48
The start
At first you see nothing. Sampling is started in the controller but you first have to
give the instruction to transfer the contents of the Trace Buffer to the display.
For this purpose use menu item 'Extras' 'Read Trace'. A kind of snapshot is
loaded. It is more interesting to have a dynamic presentation of the state by
means of 'Extras' 'Auto Read Trace'.
It is worthwhile to have a quiet look at all the possibilities of the sampling trace.
This tool is very powerful. You can say: CoDeSys saves the oscilloscope. And
during the normal hectic during set-up you might lose too much time if you are
not really familiar with the sampling trace.
Buttons
When working with the sampling trace some (context sensitive) buttons appear
which help you speed up your work. These buttons are described in the
appendix, page 6-1
Examples
3-49
Online test
3-50
The start
Documentation
A complete project, of course, also requires documentation. Again, please refer
to our Manual for the Program Development. Below we will only show some
examples.
Documenting
In the 'Project' menu you will find e.g. the item 'Document...'.
3-51
Online test
3-52
If you don't like the form of the documentation, you can click on e.g. 'File'
'Printer Set-up...'.
The start
3-53
4.
Exercises
4.1.
Logic functions
In the brief introduction of chapter 3 only a simple logic function (AND) was
used as an example. Those who have studied this chapter should not have any
problems to set up other logic functions or networks from linked logic functions
without any help. This will not be described in detail here. Some exercises
should help you become more familiar with the subject. For some short hints for
the solution see the appendix.
Some brief remarks should help to clearly structure the programs. Experience
has shown that even experienced programmers do not understand their own
program any more after some weeks. The meaning of a good structure
becomes particularly evident if some people work on partial programs or if
several people are to make modifications. In such cases it is necessary to make
exact agreements and to set up rules how the program is to be structured. Even
though this takes quite some time in the beginning and seems to be quite
complex, it will become clear during the first search for errors at the latest, that
this time was a good investment.
Documentation
Besides the item "structure which will be dealt with in detail below, we also
want to remind you that detailed and clear comments are always helpful.
Program
structure
There is not THE ideal program structure so that you can simply give an
example solution which can serve for orientation. Therefore you will find below
tips which should be seen as suggestions.
Networks
It is confusing to create one network for each link. In principle you could assign
a flag to the result of a link and to further link this flag in the next network. Then
it is pretty tiring to pursue the effects of the change of a bit in the first network
via many other networks.
Vice versa it is also confusing when there are many links in one network. This is
in particular the case if lateral scrolling is necessary because the chain of links
is too long. Then the process described above is of advantage.
Conclusion
S/R
It helps to set up the program in a clear way if you regularly use the self-hold
function. This does not have to be done for each auxiliary flag. The author
prefers a program structure that has two networks for each output. At the end of
one of them you find "SET OUTPUT", at the end of the other one "RESET
OUTPUT". This structure has the following advantages:
4-1
Logic functions
Division
Troubleshooting
Priority
The priority is also easily defined. An alarm lamp should for example be
protected against unauthorised switching off; a drive, however, should not start
running once the limit position has been reached. The sequence of the two
networks defines the priority.
Consequence
If you decide for the function block diagram - which is often the case - you
should stick to it consistently. You have to bear in mind: The sequence of the
networks has nothing to do with the chronological sequence of the process. An
example for illustration.
Example
conveyor
Here other
conditions and
links for Start1 and
Start2 are
inserted.
4-2
Exercises
Example 1! Error!
Q and I are meant to stand for output and input. Study the following example:
4-3
Logic functions
Example 2
Material
Length
Position
Cap
OK
ALARM
Reset
Task 2
Implementation
4-4
The correct function of the programs can be tested using a simulator if the
hardware is present and ready for operation. It can also be tested without any
hardware in the simulation mode. A visualisation is a good choice. If more
inputs are needed than there are on the (small) simulator (e.g. maximum level
or reset button), you can work with a combination of physical inputs on the
simulator box and inputs in a "simulated" inputs visualisation.
Exercises
4.2.
Higher-level functions
Timer and counter function
There are very many functions. In the following examples, however, we only
want to practise the most important and most frequently used functions, to be
more precise, function blocks. These are the timers and the counters.
Details about these functions will not be treated here any more. We want to
remind you only where this information can be found.
The library manager is opened in 'Resources' in 'Window' 'Library Manager'.
There you click on STANDARD.LIB. By selecting the function block TON or
CTU ( further below) the meaning of the inputs and outputs and/or types of
variables can easily be seen. If you want to get more detailed information, look
at Help. It has to be noted, however, that it is easier to find this information if
you look for the term TIMER.
Task 3
Task 4
A ventilator starts running when the light is switched on. There is an after-glow
of 10 s when the light has been turned off (new project).
Now on to the counter:
Task 5
The vessels in the example above (Figure 123) have been filled, closed by
means of the lid and they are counted by a photoelectric sensor when they
arrive at the packing station. The package consists of 12 vessels. One output
(e.g. full: lamp) is set when the preset value 12 has been reached.
Implementation using up counter
Implementation using down counter
What is to happen when the package is full?
4-5
More details
Practical application
Start
Drive
A workpiece is put onto a pickup plate (e.g. by a handling robot) and detected
by a photoelectric sensor. After activation of the start button the slide moves to
the right. It remains in its right end position for 3 s and then it moves back left. It
remains in the left end position until the next start.
The photoelectric sensor further to the right, at the beginning of the conveyor,
does not need to be considered here.
When this process is simulated, whether in the simulation mode with
visualisation or with the simulator box, in each case it has to be ensured that no
"impossible situations occur. If e.g. the process has been started, the output
S_off (slide out) has been switched, then the workpiece should be moved on.
That means the slide leaves the left limit switch and the photoelectric sensor at
the workpiece pickup is free again.
If these tasks are not very difficult for you, you are ready for practical
applications.
4.3.
More details
Notes
There are different requirements for each project. We could give more tasks
here and still there would not be an example for each application. In this manual
some more useful functions are given as examples. Other examples will follow.
So as not to take them out of their context, they are only mentioned briefly here:
Self-defined function block (page 6-21)
4-6
Exercises
Cycle time
In this chapter a somewhat special subject will be treated. Those to whom it is
important to get a deeper understanding of a PLC, should study it. It can be
skipped. Then continue on page 4-9.
It is assumed that the contents of chapter 1.5 is known.
When to skip?
if the processes in the application are not time-critical ( page 1-7 et seqq)
Those who are making their first experience with a PLC should study this
chapter later on.
Made on your
own
For test purposes it may be interesting to measure the processing time for
function blocks, networks, combinations of them or program modules yourself.
With some routine it should not be difficult to create such function blocks. Here
we only want to mention some points briefly.
Cycle counter
A cycle timer you have created on your own for the number of processed
program cycles may look like
PLC browser
4-7
More details
Restriction
Please note, however, that this function is to be used for all targets (that support
such a timer). The method described above with the 'TIMER_READ_US'
module can be used more precisely and flexibly.
4-8
Exercises
Visualisation
A visualisation is useful to give an overview of the process. This process was
described in detail on pages 3-19 et seqq.
Manual
operation
4-9
More details
How does the program have to be extended for the following function?
The slide should only move while the button for manual operation (here the
mouse button when the cursor is on the button) is activated. It is to stop once it
is released.
This was only meant to be a brief example. To test a program you can proceed
as follows. If the manual operation should also be possible later on for the
maintenance people, another program structure is necessary.
The following aspect has to be considered:
In practical use it is required that either manual or automatic Mode is possible
and the other one is blocked.
Below we will mention briefly how this requirement can be met. If the two
operating modes are to be independent from each other, a clear structure is
4-10
Exercises
ensured if two POUs are added to PLC_PRG. This will look somehow like in
Figure 133:
4-11
5.
Models
5.1.
Overview
A concrete
project
Once the offline and online program creation and program test have become
more familiar using the simulator, it is about time to start processing a concrete
project.
Model
For training purposes but also to avoid errors and thus costs for setting up a
real plant it is useful to work on a functioning model.
Protection
During the trainings of ifm electronic such models are used. There is no reason
to be afraid that they can be damaged by programming errors. The end
positions of the respective movements are protected by mechanical limit
switches.
The models are a kind of processing street with various stations. Three parts
are distinguished for a better overview:
Robot
Drill
Milling system
5-1
Task Drill
5.2.
Task Drill
Start
S aus
S ein
A workpiece is put onto a pickup plate onto which it was put by a handling robot
( next section) where it is detected by a diffuse reflection sensor.
Slide
The slide is in its home position on the left (view from the front onto the model)
which is monitored by an inductive sensor. After activation of the start button the
slide moves to the right and pushes the workpiece to the conveyor. When the
right end position of the slide has been reached, the movement to the right
stops. The travel back is not started right away but the slide waits in its end
position for approx. 2s. Then it moves to the left until it has reached its home
position again.
At the beginning it is easiest to start with programming the movement of the
slide. It can run completely independently from other processes. Experience is
made which helps become more familiar with this system and which makes it
easier to program the rest of the process.
Conveyor
5-2
Models
Drill head
Drill
It is reasonable that the drill head moves downwards and upwards with the drill
running. With a high-power drill you would have to wait for some time so that it
reaches its full speed. However, this is not required here.
It is important for a correct process to be able to decide if the workpiece has
already been drilled or not. It is recommended to use a flag as an indicator. This
ensures that the interaction of conveyor, drill head and drill can be controlled
easily and clearly.
5.3.
Task: Robot
-y
+y
underneath this
arm there is a
solenoid holding
the workpiece
-x
Start
+x
5-3
Task: Robot
Rotation
At the beginning the robot is in its home position on the right which is monitored
by an inductive sensor. After the start button has been activated, it starts
rotating to the left (counter clockwise as seen from above). In the pickup
position the rotation stops and the workpiece is received. Then rotation is
continued up to the release position. There it stops and the workpiece is put
onto the pickup table in front of the drill. Then the robot turns back into its home
position.
Direction of
rotation
The direction of rotation, e.g. clockwise, and the position of the limit switch on
the robot always refer to the view from above.
How does the robot know which position it is in? An encoder is connected to the
drive for the rotational movement. By counting the pulses which are generated
during the rotation, the position is determined. This means a counting function
for the program. In this case the counter value is compared with two values. To
prevent malfunction due to lag, the comparison greater than or greater than or
equal to should be made at any rate. If the respective condition is met, the
corresponding flags can control the rotational movement. Here it is easiest to
first of all estimate the counter values for the pickup and release positions. They
can be corrected after a test run.
The position switch on the left should not be reached. It acts as limit switch for
the safety of the plant. Should it be reached nevertheless, there is an error in
position definition. It can be used as an additional condition so that the
rotational movement to the left is stopped here at the latest. The counter does
not have to be used for the rotational movement to the right (clockwise). The
limit switch on the right is sufficient to stop the rotation. It can also be used as a
reference point to set the counter to zero.
Robot arm
The robot arm goes downwards twice. The first time in the pickup position to
pick up the workpiece. The second time in the release position to release the
workpiece. It remains again in the lower position for 2s ( see the drill head).
Then it moves upwards again. The upper and lower end positions are
monitored by diffuse reflection sensors.
Do not confuse: for "technical reasons" the diffuse reflection sensor for the
"upper end position" is mounted on the lower end of the arm and vice versa.
Solenoid
The solenoid can be switched using simple conditions. When the arm is in the
lower pickup position, it is to be switched on. When the arm is in the lower
release position, it is to be switched off.
Workpiece
picked up
Similar to the drill the information whether the workpiece has already been
picked up or not is important to correctly control the process. For example, the
arm in pickup position should only go downwards if the workpiece has not yet
been picked up. It is possible to assign this meaning to a flag. In this example
there is an easier way. The state of the solenoid can be used as a condition by
means of which the two cases can be distinguished.
5-4
Models
Start
Once the program for the robot and the drill has been created and tested, the
condition "start button" for starting the slide has to be deleted or replaced by
suitable conditions. Otherwise the user has to delete each partial step manually.
5.4.
Start
The milling system is not wired in parallel to the inputs and outputs of the
controller like the robot and the drill. The inputs and outputs of the milling
system are connected to the controller via a CAN module. We will only start
working with the milling system in connection with CAN.
The process is similar to the drill.
Change of tools The considerable difference is that after processing with the first tool, after the
milling head has been moved up again, the workpiece is not further transported,
yet. The drive of the milling system is stopped. Then the drive of the tool
changer is started. The position sensor indicates that the next tool is in its
position. Then a processing step is also started by it, the same with the third
tool.
Finally the photoelectric sensor at the end of the conveyor of the milling system
signals that processing is completed and the workpiece can be removed again.
5-5
Addressing
Addressing
Addresses with
the model
For each new project you can decide if the declaration of the variables
especially the assignment of the inputs and outputs to physical addresses is
made before or during the actual program creation. Experience shows that it is
usually easier to declare the variables during program creation. It is made a lot
easier due to 'Project' 'Options' 'Autodeclare'. Usually it shows during
programming how the program can be clearly structured by splitting it up into
modules. You only have to consider which variable has to be declared locally
(default setting) or globally. Should it turn out later on that a variable was
declared locally although it is used in several modules, it can be changed easily,
e.g. using the edit functions 'Cut' and 'Paste' via the clipboard.
Inputs
5.5.
5-6
Designation
Unit
Address
Start button
%IX0.7
%IX0.8
%IX0.9
%IX0.10
%IX0.11
Encoder channel A
%IX0.14
Encoder channel B
%IX0.15
%IX1.0
%IX1.1
%IX1.2
%IX1.3
%IX1.4
%IX1.5
%IX1.6
Features
up to 50 kHz
Models
Outputs
Designation
Unit
Address
Solenoid
%QX0.8
%QX0.9
%QX0.10
%QX0.11
%QX0.12
%QX1.0
%QX1.3
%QX1.4
%QX1.5
Drive drill
%QX1.6
%QX1.7
Features
O, I, and K stand for photoelectric, inductive and capacitive sensors and R for
encoders.
Direction of
rotation of the
robot
Do not confuse!
5.6.
Other remarks
Declaration
In the table above you do not find names that are assigned to the addresses
during declaration. You can chose the names individually. For the names a
compromise between two conditions has to be found. The name should show
clearly which address is meant. A name such as Input1 would be meaningless.
It would also be possible to work with the physical address and to do without a
symbolic name. On the other hand the name should not be too long since
otherwise the modules will be confusing.
Safety
Only "minimal" conditions for the correct course of the process were indicated
above. They should be completed by safety enquiries. For example, the
conveyor at the drill should not start unless the drill head is up. The robot
should only rotate when the arm is up etc.
The direction of rotation, e.g. clockwise, and the position of the limit switches on
the robot always refer to the view from above.
5-7
Other remarks
Program
structure
There should not be a fixed specification for the program structure. The
structure of a program depends partly on the previous knowledge and
experience of the programmer. It is only important to have a structure for the
program. It would be quite confusing, e.g. to write the program completely in the
PLC_PRG POU. This leads to the so-called "spaghetti code" from which
nobody, not even the programmer himself, understands later on which belongs
to which. On the other hand it is confusing to use many small, nested modules.
Some experience will help to find a sensible compromise between these two
extreme cases ( also page 4-1).
Language
Visualisation
Here we want to recall the example on page 4-9 et seqq. Visualisation belongs
to virtually any project. It helps:
- with program creation (program test)
- with maintenance (trouble shooting)
5-8
6.
Appendix
6.1.
Buttons
Toolbar
This appendix will give you a short overview of the different buttons in the
toolbar.
The toolbar, the third bar from the top, offers a variety of buttons (if activated via
'Options' 'Toolbar'). Regularly used functions can be started with a single
mouse click. They are, of course, also available as menu items. Just like the
menus they are context sensitive. That means the buttons can vary depending
on the open and active windows. Some can be seen at virtually all times and
they will be described first. Later, we will explain those buttons that can e.g. only
be found in the FBD editor.
For detailed descriptions of the functions please refer to the manual for program
development. This short overview will not describe if the function can e.g. be
found in the menu 'Extras' or 'Insert'. In most cases that is obvious in the
context. To save space we do not state "... at the marked position" for each
function. It is self-understood that the position in which e.g. something is to be
inserted requires marking. Neither will we state that it might not make sense to
insert an element in just any place depending on the function. It does not make
sense e.g. to insert an operator following an assignment. Some elements have
a default value, e.g. TRUE for Boolean variable. This default value can be
overwritten with the requested entry. The F2 key can be useful again.
File functions
'File new'
Opens a file named Untitled.
If no file is open (e.g. following the instruction File Close) almost all (context
sensitive) menus are empty or the menu items are shown in grey, i.e. they are
inactive. To do something, a file has to be open.
'Open file...'
Opens the window for selecting a file.
'Save file'
Saves the open file.
It is recommended to click on this button repeatedly during your work.
6-1
Buttons
Online functions
'Start'
Starts the program processing.
'Stop'
Stops the program processing.
'Single step to'
Carries out the next instruction (debugging).
'Breakpoint on/off'
Stops the program processing at the current instruction (debugging); useful e.g.
in combination with Single Step To.
'Login'
Establishes the connection to the controller (only if the program is correct).
If the program was changed a new compilation is started.
In the simulation mode, only the compilation is carried out, if required.
Remember: Program processing has to be started additionally.
'Logout'
Separates the connection to the controller.
E.g. to change the program or to configure the trace.
6-2
Appendix
6-3
Buttons
6-4
Appendix
6-5
Buttons
'Alarm table'
Inserts an alarm table for an overview of alarms that are defined as events.
When a wild-card has been inserted, a window for configuration opens.
'Pointer instrument'
Inserts a pointer instrument to display values as angled position. When a wildcard has been inserted, a window for configuration opens, e.g. for marking
ranges.
'Bar graph'
Inserts a bar graph, similar to the pointer instrument. When a wild-card has
been inserted, a window for configuration opens.
'Histogram'
Inserts a histogram, similar to a bar graph for displaying an array with several
vertical bars. When a wild-card has been inserted, a window for configuration
opens.
6-6
Appendix
6.2.
Target system
First of all the target system is specified. Here the device type is selected that is
to be worked with.
Figure 11
PLC_PRG
Figure 33
Please note:
The name of this POU must not be changed!
Click on
6-7
Figure 34.
If you prefer another language, the module will, of course, look different.
Add object
The next step should always be to add a new object in 'Project' 'Object' 'Add'.
Figure 35
In the example in chapter 3 it was the object P_And in FBD.
The program becomes very confusing if you write everything in PLC_PRG.
There may, of course, be exceptions. One exception is e.g. setting the RELAY,
Figure 105.
6-8
Appendix
Figure 18
Figure 22
6-9
Saving work
Figure 27
Figure 31
Relay
When the relay has been set (if applicable), the preparations are completed.
Now the actual programming can start.
6.3.
Saving work
Under this hopefully interesting headline we will describe briefly how already
created programs, modules, networks, etc. can be transferred from one project
to another. As usual there are several ways to reach the goal. Not all of them
can be shown here; we have to refer to the programming manual. Here we only
want to discuss some of the most frequently used methods.
'Save as...'
This is the easiest and probably best known way. The following procedure
makes sense to program an R360 controller, for example. It is relatively
complex to always integrate the hardware configuration etc. for each new
project if always the same hardware version, e.g. CR0020, is used. Then it is
worthwhile to create an empty project as master in which all settings have
already been made. With 'Save as...' you will get a project in which you can
work right away, without any other preparation.
6-10
Appendix
'Project' 'Merge...'
This function is not often used, perhaps because the name may be misleading.
No copy of the project is created. This is simply done by 'File' 'Save as...'.
With this function another project or parts of it can be inserted in the currently
processed project.
In the example above not much work is needed to create the P_AND module.
Nevertheless we want to show how it can be copied into another project. If this
menu item is clicked on in an open project, a selection screen will open.
6-11
Saving work
Library
Projects that in this case must not contain a PLC_PRG with one or several
objects can be saved as library by means of 'Save as...'. As above they can be
integrated in other projects. This is e.g. useful if you do not want the operator of
a plant to change certain function blocks, if he has access to CoDeSys. It is not
possible to edit in a library; a source code has to be available. Another aspect is
that in this way special know-how can be "hidden".
Clipboard
Everybody working with Windows is familiar with the clipboard. Therefore we
will not go into any further details here.
Templates
An already created project can be opened as a template in 'File' 'New from
template...'. A copy with the name (Untitled)* is created. If the file is copied with
another name, you will virtually get the same result as with 'File 'Save file
as..., page 6-10. It is especially recommended to create a file as template
with all configuration settings if new projects for the same hardware are created
often, page 2-19.
Another possibility is to click on 'Save as template' (right mouse click) in the
context menu, e.g. a program module for an object, e.g. a program module.
Then all declarations are saved and not only the links.
Other steps
Adapt
Done?
When the module has been completely edited, you are not done yet.
Remember!
In the heat of the moment it also happens to the experienced programmer that
he forgets to integrate the completely edited POU in his project. It is absolutely
necessary to take the following step!
Activating
P_AND in
PLC_PRG
6-12
Appendix
6.4.
Example 1
(page 4-3)
The second network defines the state of the output. The first one can be left
out.
It would serve the obviously intended purpose to combine the two networks and
to link the results of the AND operation with an OR operator. Here you can see
again that an S (set) function is of advantage. If you had an S before the output
of networks 1 and 2 there could be no conflicts. You need, however, more
networks for resetting.
Task 2 (page44)
6-13
OR operator before the timer function, then both inputs are debounced or
other timer functions between Length' and OR operator so that the second
input can be debounced with another timer value, etc.
Hopefully, the timer functions CTU or CTD should not be too difficult. Only the
case "package full" has to be considered more closely. If you simply use the
condition "actual value = preset value" to reset the counter, then the output Q of
the counter is on TRUE for just a short time. The signal has to be "retained".
Here we want to recall the remarks about the program structure, page 4-1 et
seqq and 5-8. At any rate a program module, e.g. name 'Slide' type 'Program'
and language 'FBD', should be created with 'Project' 'Object' 'Add...'. Then
there are two alternatives:
For this relatively easy and clear process all networks for controlling the
slide can be integrated in this module.
6.5.
6-14
Appendix
Declarations
In the examples given so far the variables were declared locally. This is, of
course, also possible for the models. Below an example will be given how to
declare the variables directly during hardware configuration.
6-15
6-16
Appendix
Consistent
Whichever possibility you may decide for: You should always be consistent and
declare in the same way!
Watch list
A method to help is to create a watch list. It is also very useful for maintenance
(troubleshooting). You collect all variables that are important for a certain
context and save the list as a freely selectable name.
This is done in 'Resources' Watch and recipe manager'.
6-17
Sequence
It is confusing to program the conveyor and the drill in only one program
module. This easily leads to an unfavourable arrangement of the networks like
in the example below (see page 4-2):
- network for starting the conveyor
- network for stopping the conveyor
- various networks for the drilling process
- network for another start of the conveyor
- network for another stop of the conveyor.
The basis is the sequence of the individual processes. This can also produce
the desired result. As soon as there is a malfunction of the conveyor, it is twice
as difficult to find the cause since the conveyor is found twice. The sequence of
the networks described above would be suited for the structure of a module in
SFC. However, it does not come up to the idea of the FBD. It would be
considerably clearer to use one single POU for the conveyor and one for the
drilling process. The process will also be less susceptible to interference if these
two POUs are combined with only very few links.
The conveyor starts twice. This simply corresponds to the logic OR function.
You only have to consider which conditions or links are required for the first and
which for the second start. Then the necessary considerations for the stops are
made. The sequence of the conditions is absolutely irrelevant for the switching
logic. Only the conditions are important for the correct process and not the OR
function. Once the program module for the conveyor has been completely
programmed, it can be tested, independently of the drill.
This leads to the question: How can the conveyor be tested without the drill
running?
Flag
Using a flag is a good solution. It does not simply have the function "auxiliary
flag" but it can rather be called a "control flag". It is simply given the name
'drilled'. It is to have the state TRUE when the drilling process is completed and
FALSE when drilling is still performed. For the program test this process can at
first be controlled "manually" by changing its value via 'Online' 'Write values'.
Once you have ensured that it is used so that the process is running correctly,
you can take a next step and consider meaningful conditions changing the state
of the flag automatically (see page 6-19).
Recap
This effect can e.g. be found with programming of the drill head. You gather
conditions, e.g. workpiece in drilling position, conveyor stands still and drill (tool)
is running. They are linked with logical AND. With the result the drive is set that
moves the drill head downwards. This looks completely right. Let us assume
that the further process (stopping the movement downwards, waiting for the
drilling process and movement of the drill upwards) has been correctly
programmed and then the following happens during the program test:
6-18
Appendix
As soon as the drill head has arrived its upper position, these conditions have
been met (it is better if the conveyor starts moving when the head is in its upper
position so that the tool does not break off and the drill head should leave the
workpiece with the tool running). The consequence is that the drill head moves
downwards etc. in all eternity. Therefore the model has got its nickname
"sewing machine".
What is to be
done?
The flag 'drilled' that was described above in section Sequence is also very
useful in this case. It is also useful for the program test of the module for the
conveyor.
An edge detection e.g. R_TRIG of a suitable variable is also a good solution.
Flag
Only those who do not have any idea how the flag is controlled by the program
should go on reading here. There are several solutions, as usual. Then there
will be some notes for an example
When a new workpiece has been placed, it has not been drilled yet.
When the drill head is in its lower position, drilling has been effected.
Program structure
Those who prefer to program on their own should skip this section or compare
their own program with the following examples upon completion. A possible
program structure will be presented. We do not claim to give a perfect solution
here. The example can certainly be improved, e.g. by additional enquiries to
increase the safety of the process. In this respect it is not only the list of
modules that is shown. The program structure cannot be directly seen from this
list in alphabetical order. The structure becomes clear when you select 'Project'
'Show Call Tree'.
6-19
program the entire movement of the arm there. Above we already pointed out
that the preset structure is nothing but an example.
Consistent
The user should see to it that a uniform structure is used. This is in particular
important if several people are to work with the program, e.g. also in
maintenance (troubleshooting).
The numerous CAN functions are implemented automatically. They need not be
taken into account here.
POUs with
folders
The program structure will become clearer if the subdirectories are inserted via
the context menu (right mouse button) (see Figure 147). Please note that this
tree is only a view. It does not reflect the actual call hierarchy like the call tree
(see Figure 146).
Below we will give an example how to implement the notes on the program
structure on pages 4-1 et seqq for a concrete module.
6-20
Appendix
6-21
It gets e.g. the name To_and_Fro for moving it away from its home position
and back. The language used is again FBD.
6-22
Appendix
6-23
6-24
7.
Index
%IX0.08 .......................................................3-42
.pro ...............................................................3-29
CoDeSys........................................................ 3-1
'Coil'............................................................... 6-3
Color............................................................. 3-23
3S................................................................... 2-3
Compilation...........................................3-40, 6-2
Adapt............................................................6-12
Compilation.................................................. 3-43
Address........................................................3-42
Addressing..................................................... 5-6
'Contact'........................................................ 6-3
Alarm colour.................................................3-23
Copy....................................................3-37, 6-11
Append Subelement....................................2-19
CR0020.......................................................... 1-3
AT.................................................................3-43
CR0505.......................................................... 1-3
CR2500.......................................................... 1-3
Autodeclaration............................................3-11
'Cut'................................................................ 6-2
Cyclical........................................................... 1-5
Breakpoint...................................................... 3-2
Button...........................................................4-10
'Button'.......................................................... 6-5
Default...................................................3-14, 6-1
Buttons........................................................... 6-1
CAN.........................................................2-3, 5-5
Catalogue....................................................... 1-2
CFC................................................................ 3-1
Clipboard......................................................6-12
7-1
Grid...............................................................3-20
Guarantee ......................................................... II
Hex file..........................................................3-34
EDS ................................................................2-3
'Histogram'....................................................6-6
IEC-61131-3...................................................3-1
'Ellipse' ..........................................................6-5
Encoder ..........................................................5-4
Import ...........................................................6-12
Input..............................................................3-23
'Input' .............................................................6-4
InstallTarget....................................................2-8
File ..................................................................2-4
Interface parameter......................................3-35
'File new'........................................................6-1
Internal variable............................................6-24
'Find next'......................................................6-2
'Find...' ...........................................................6-2
Fixed............................................................ 6-13
Key .................................................................3-8
Forcing......................................................... 3-18
Frequency ......................................................1-7
Language .......................................................5-8
Frequency inputs............................................1-8
Logging out...................................................3-19
Login.............................................................3-15
'Login' ............................................................6-2
'Logout'..........................................................6-2
'Graph' ...........................................................6-5
7-2
Index
'Paste'............................................................ 6-2
Manual mode...............................................4-10
Path................................................................ 2-4
Mobile............................................................. 1-5
ms................................................................... 1-7
Priority............................................................ 1-6
Network.......................................................... 3-7
Notes.....................................................1-2, 6-14
Online.................................................3-28, 3-37
Project.....................................................2-7, 3-1
Protection....................................................... 1-5
Online Test...................................................3-37
Operating modes.........................................4-11
Rectangle..................................................... 3-20
Operator......................................................... 3-9
'Rectangle'.................................................... 6-5
Orientation guides
Relay.....................................................3-44, 6-8
Oscilloscope ................................................3-45
Other languages ..........................................3-14
'Output'.......................................................... 6-4
'Parallel branch (left)' .................................. 6-3
'Parallel branch (right)'................................ 6-3
'Parallel contact' .......................................... 6-3
7-3
Subdirectory .................................................2-11
Subelement ..................................................2-19
System variable..........................................3-44
'Table' ............................................................6-5
'Selection'......................................................6-5
Target information........................................2-10
'Set/reset'.......................................................6-4
Settings...........................................................2-7
Signal shape...................................................1-8
Task 7...........................................................4-10
Text...............................................................3-25
Solutions...................................................... 6-13
TNF...............................................................2-10
Toggle variable.............................................3-23
Toggling........................................................3-23
'Start'..............................................................6-2
Toolbar ...........................................................6-1
Trace Buffer..................................................3-49
Starter set.......................................................2-7
State ...............................................................1-6
'Trend'............................................................6-5
Unambiguous.................................................1-6
'Stop' ..............................................................6-2
Variable classes...........................................6-22
'Stretch'..........................................................6-4
Variables ........................................................3-6
7-4
Index
Version..................................................2-4, 3-34
Watchdog....................................................... 1-9
'Visualisation'............................................... 6-5
7-5