Sunteți pe pagina 1din 559

Overview

TwinCAT 3 New Automation Technology

Training fr Umsteiger

TwinCAT 3 | New Automation Technology

Object-orientated programming in IEC

Training fr Umsteiger

TwinCAT 3 | New Automation Technology

Overview of contents

Object orientation with


IEC 61131-3 3rd edition
Extension Details
Example applications for
OOP

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

TwinCAT 3 | New Automation Technology

Requirements of the OO in automation technology


Integration into one PLC development environment (with online functions, online
change etc.)
Mixing of procedural and object-orientated code (existing projects must be capable
of being integrated simply and without expenditure)
Extension of the familiar IEC languages instead of an extra language for OOP
OOP universal in all IEC languages (not only ST)
Standardisation of the language by the IEC
New third edition of the IEC61131-3
Standardisation expected at beginning of 2011

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

TwinCAT 3 | New Automation Technology

Advanced IEC features | Keywords


Six new keywords:
METHOD : action on FB with own variables
PROPERTY: POE pair for Set/Get of attribute
THIS : in Methode/Property for the current FB instance
SUPER : in Method for access to the basic class instance
EXTENDS : inheritance between FBs
INTERFACE : defines abstract object type (FB without implementation)
IMPLEMENTS in the FB: instances can be called via the named interface

Call syntax for methods:


Objekt.Methodname()

Special methods:
FB_Init, FB_Exit, FB_Reinit
TwinCAT 3 | Training | Object-orientated
programming in IEC

03.05.2012

TwinCAT 3 | New Automation Technology

Advanced IEC features | Application


Object-orientated extensions of IEC 61131-3, 3rd edition:
the concept of the functional blocks has been extended by
Classes
Interfaces
Methods
Inheritance
Attributes
Keywords such as THIS, SUPER

Use of the extensions


Possible in all IEC languages
Independent of the hardware employed
Not absolutely necessary
TwinCAT 3 | Training | Object-orientated
programming in IEC

03.05.2012

TwinCAT 3 | New Automation Technology

Advanced IEC Features | SUPER and THIS

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

TwinCAT 3 | New Automation Technology

Overview of the language properties


Language properties

2nd Edition
IEC 61131-3

3rd Edition
IEC 61131-3

C++

Java

C#

Multilingual capability

OOP/procedural mixed

Classes

~ (FB)

Methods

~ (Actions)

Interfaces

Partially abstract classes

Polymorphism

+/-

Reference semantics

+ (Interfaces)

Constructor/Destructor

Properties

Visibility

~ (Variables)

~ (Variablen)

Dyn. memory (new)

- (in TC3)

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

TwinCAT 3 | New Automation Technology

Overview of contents

Object orientation with


IEC 61131-3 3rd edition
Extension Details
Example applications for
OOP

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

IEC 61131-3 3rd Edition

History
1st edition 1993
2nd edition 2003: bugfixes and small extensions
3rd edition 2011
working at 3rd starts 2008
1st draft in july 2009
release 2010

IEC61131-3 3rd Edition

10.12.2012

IEC 61131-3 3rd Edition

Typography
3rd edition = 2nd edition + extensions
single line comment
nanoseconds
enum type with named values
pointers allowed
references
object oriented extension
namespaces
call a program from other programs
mixed data types in expressions and implicit conversions.

IEC61131-3 3rd Edition

10.12.2012

10

IEC 61131-3 3rd Edition

New datatypes
LINT, ULINT, LWORD
64 bit length.
LTIME, LDATE, LDATE_AND_TIME, LTIME_OF_DAY
tTime:= LTIME#12s34ms2us44ns
DT:= CONCAT_DATE_TOD(DATE, TOD);
DATE:= CONCAT_DATE(YEAR, MONTH, DAY);
UNION
several datatypes in a single memory space
WSTRING
Unicode format

IEC61131-3 3rd Edition

10.12.2012

11

IEC 61131-3 3rd Edition

Enum Type
Explixitly specify the datatype of an enumeration.
Default type is INT.

IEC61131-3 3rd Edition

10.12.2012

12

IEC 61131-3 3rd Edition

UNION
All variables have the same memory offset.
All variables occupy the same memory location.
Size of the memory is defined by the major variable.

IEC61131-3 3rd Edition

10.12.2012

13

IEC 61131-3 3rd Edition

VAR_TEMP - Temporary Variables


Temporary variables get initialized each call of the POU.
Usable in programs and function blocks.
In methods and functions every declared variable is temporary!

IEC61131-3 3rd Edition

10.12.2012

14

IEC 61131-3 3rd Edition

VAR_STAT - Static Variables


Static variables get initialized only at the first call of the POU.
Static variables get stored and dont lose their value.
Usable in methods and functions.
In programs and function blocks every variable is static!

IEC61131-3 3rd Edition

10.12.2012

15

IEC 61131-3 3rd Edition

Expression for variable initialization


initialize variables with ST expressions

IEC61131-3 3rd Edition

10.12.2012

16

IEC 61131-3 3rd Edition

Pragma Instructions
{defined identifier}
{undefined identifier}
{IF expr}
{ELSIF expr}
{ELSE}
{END_IF}

{IF defined(variable:iInput)}
{IF defined(pou:CheckBounds)}
{IF defined(type:ST_DataType)}
{IF hasattribute(variable:iInput, DoSomething)}
{IF hastype(variable:iInput, UINT)}

IEC61131-3 3rd Edition

10.12.2012

17

IEC 61131-3 3rd Edition

Pragma Instructions
Messages
{text 'Hello World!'}
{info 'Information!'}
{warning 'Warning!'}
{error 'Error!'}

IEC61131-3 3rd Edition

10.12.2012

18

IEC 61131-3 3rd Edition

Pragma Instructions

IEC61131-3 3rd Edition

10.12.2012

19

IEC 61131-3 3rd Edition

References
A reference is an alias for an object.
Instead of pointers.
Typesafe.
No dereferencing.

IEC61131-3 3rd Edition

10.12.2012

20

IEC 61131-3 3rd Edition

Object Oriented Extensions


METHOD
PROPERTY

FB_Init, FB_Exit, FB_Reinit

EXTENDS
INTERFACE
IMPLEMENTS

THIS
SUPER

IEC61131-3 3rd Edition

10.12.2012

21

IEC 61131-3 3rd Edition

METHOD
Methods are describing a sequence of instructions.
Like a function that depends to a function block.
Extends the existing ACTION functionality.
VAR_INPUT, VAR_IN_OUT and VAR_OUTPUT
Access to variables of the belonging function block.

IEC61131-3 3rd Edition

10.12.2012

22

IEC 61131-3 3rd Edition

PROPERTY
Gives access to internal states or values.
Provides methods how to get and/or set the value.

IEC61131-3 3rd Edition

10.12.2012

23

IEC 61131-3 3rd Edition

FB_init, FB_reinit, FB_exit


FB_init
Contains explicit initialization code for the function block.
Gets called before starting the PLC. (SAFEOP => OP)
Implicit initializations have already been done.
User defined inputs: fbVal: FB_Val(iVal:= 3);
FB_reinit
Contains explicit reintinialization code for the function block.
Gets called when the instance gets copied. (online change)
FB_exit
Contains explicit deinitialization of ressources.
Gets called before a download, a reset or online change.

IEC61131-3 3rd Edition

10.12.2012

24

IEC 61131-3 3rd Edition

Sample: FB_init, FB_reinit, FB_exit

IEC61131-3 3rd Edition

10.12.2012

25

IEC 61131-3 3rd Edition

Execution order while online change.


Exit old instance.

old_inst.fb_exit(bInCopyCode := TRUE);

Initialize new instance.


new_inst.fb_init(bInitRetains := FALSE, bInCopyCode := TRUE);
Copy instance.
copy_fub(&old_inst, &new_inst);

IEC61131-3 3rd Edition

10.12.2012

26

IEC 61131-3 3rd Edition

THIS
Every function block provides the pointer THIS.
THIS points to the current function block.

IEC61131-3 3rd Edition

10.12.2012

27

IEC 61131-3 3rd Edition

EXTENDS
Structure includes all variables from the extended base.

IEC61131-3 3rd Edition

10.12.2012

28

IEC 61131-3 3rd Edition

EXTENDS
Function block includes all variables from the extended base.

IEC61131-3 3rd Edition

10.12.2012

29

IEC 61131-3 3rd Edition

EXTENDS
function block includes all methods from the extended base.

IEC61131-3 3rd Edition

10.12.2012

30

IEC 61131-3 3rd Edition

SUPER
Every function block provides the pointer SUPER.
SUPER points to the basic function block.

Usable for overwriting existing methods from the base.


Change the behaviour of a existing function block.

IEC61131-3 3rd Edition

10.12.2012

31

IEC 61131-3 3rd Edition

INTERFACE

POU which defines/describes.


methods and properties.

Just declaration, no implementation.


Only input, output and inout variables.

No body (implementation).
No declaration of internal variables.

IEC61131-3 3rd Edition

10.12.2012

32

IEC 61131-3 3rd Edition

IMPLEMENTS
A function block implements
the interface.

Provides the implementation


of the declaration.

IEC61131-3 3rd Edition

10.12.2012

33

IEC 61131-3 3rd Edition

Interface Usage
Declare an instance of the function block,
implementing the interface.
Declare an variable of the interface.
Store a reference to the function block in the interface.

IEC61131-3 3rd Edition

10.12.2012

34

IEC 61131-3 3rd Edition

Interface Benefits
Use different implementations depending on the situation.
If use mem instance is active, FB_MathMem would be used.
Otherwise the FB_MathErase would be used.

IEC61131-3 3rd Edition

10.12.2012

35

IEC 61131-3 3rd Edition

Attention while using interfaces!


Function blocks are value types. Copied by value/memory.
Interfaces are reference types. Copdied by reference/address.
Interfaces are pointers!

IEC61131-3 3rd Edition

10.12.2012

36

IEC 61131-3 3rd Edition

Extended Structured Text - ExST


TwinCAT 3 specific extensions.

Dynamic Memory
__NEW
__DELETE

Adressing, Pointers and References


__ISVALIDREF
__QUERYPOINTER
__QUERYINTERFACE

IEC61131-3 3rd Edition

10.12.2012

37

IEC 61131-3 3rd Edition

Not yet implemented


Extensible Function PARAMS

ANDN, ORN, XORN

ANY_TYPE
ANY_NUM_TO_<NUMERIC>
ANY_TO_<TYPE>

IEC61131-3 3rd Edition

10.12.2012

38

TwinCAT 3 | New Automation Technology

Overview of contents

Object orientation with


IEC 61131-3 3rd edition
Extension Details
Example applications for
OOP

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

39

TwinCAT 3 | New Automation Technology

Example applications for OOP


Sample01: Classic inheritance
EXTENDS : Inheritance between FBs
METHOD : Action on FB with own variables
Sample02: Inheritance with abstract upper class (late Binding)
EXTENDS : Inheritance between FBs
METHOD : Action on FB with own variables
INTERFACE : defines abstract object type (FB without implementation)
IMPLEMENTS in the FB: Instances can be called via the named interface
SUPER : in Method for access to the basic class instance
Sample03: Access via Property by means of Get/Set
PROPERTY: POE pair for Set/Get of attribute
Sample04: Cylinder
EXTENDS, METHOD, INTERFACE , SUPER
Sample05: Crossroads
Sample06: Overshadowing with THIS and SUPER
TwinCAT 3 | Training | Object-orientated
programming in IEC

03.05.2012

40

TwinCAT 3 | New Automation Technology

Sample01: Classic inheritance


EXTENDS : Inheritance between FBs
By setting the keyword EXTENDS, the respective function block gets all the
properties (variables, actions, methods, etc.) of the basic function block as an
extension to its own!

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

41

TwinCAT 3 | New Automation Technology

Sample01: Classic inheritance


METHOD : Action on FB with own variables
Methods strongly resemble the familiar functions (FUN), i.e. all data are only
present temporarily!
Permitted variable classes: VAR, VAR_INPUT, VAR_OUTPUT
Not permitted: VAR_IN_OUT, VAR_TEMP

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

42

TwinCAT 3 | New Automation Technology

Sample02: Inheritance with abstract upper class


INTERFACE : defines abstract object type (FB without implementation)
Used on function blocks for the management/organisation of methods
An INTERFACE describes a collection of method prototypes, i.e. methods that are
only declared but not implemented. All methods of the interface are implemented
by the FB (IMPLEMENTS).
The instance of an INTERFACE is filled in with code by assigning the FB that
implements this INTERFACE at runtime (dynamically)

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

43

TwinCAT 3 | New Automation Technology

Sample02: Inheritance with abstract upper class


Characterisation of the interface with the respective FB instance that implements
this interface.

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

44

TwinCAT 3 | New Automation Technology

Sample03: Access via Property by means of Get/Set


A PROPERTY can use the private variables of the block module in a program block
(PRG) or function block (FB) by means of SET and GET
The SET and GET methods are added automatically by appending a PROPERTY. A
PROPERTY must always have the return type of the variable to be used.

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

45

TwinCAT 3 | New Automation Technology

Sample04: Cylinder
Example: Cylinder

Task:
Cylinders should all look the same
Identical behaviour
Special form: cylinder with diagnosis

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

46

TwinCAT 3 | New Automation Technology

Sample04 : PLC | OOA cylinder


ICylinder
+M_StateMachine() : bool

FB_Cylinder
+bAtLeftPos : bool
+bAtRightPos : bool
TimerReach
TimerStart
iState : int
+M_StateMachine() : bool

FB_CylinderDiag
+tTimeOut
WatchDogTimer
+M_StateMachine() : bool
+M_Diag() : bool
TwinCAT 3 | Training | Object-orientated
programming in IEC

03.05.2012

47

TwinCAT 3 | New Automation Technology

Sample04 : PLC | Cylinder | Interface


Definition of an abstract upper class (INTERFACE): ICylinder
Associated METHOD is only created, associated data are only defined on
implementation!

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

48

TwinCAT 3 | New Automation Technology

Sample04 : PLC | Cylinder | Function block


Definition of a (basic) function block that implements the interface ICylinder.
All functions required for a (basic) cylinder are defined here.

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

49

TwinCAT 3 | New Automation Technology

Sample04 : PLC | Cylinder | Method


METHOD for controlling all cylinders:

Implementation
of the interface
method

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

50

TwinCAT 3 | New Automation Technology

Sample04 : PLC | Cylinder | Inheritance


Creation of a further FB, which extends the basic type (EXTENDS):

Overloading the METHOD: M_StateMachine from FB_Cylinder


TwinCAT 3 | Training | Object-orientated
programming in IEC

03.05.2012

51

TwinCAT 3 | New Automation Technology

Sample04 : PLC | Cylinder | Further methods


Extension of the inherited METHOD by special types for diagnosis:

Overwriting the
interface
method

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

52

TwinCAT 3 | New Automation Technology

Sample04 : PLC | Cylinder | Call via interface


Call of an FB - independent of the type - via the INTERFACE:

TwinCAT 3 | Training | Object-orientated


programming in IEC

03.05.2012

53

TwinCAT 3 | New Automation Technology

Object-orientated programming in IEC

Training fr Umsteiger
Thank you very much
for your attention!

Presentation of the system

TwinCAT 3 New Automation Technology

Training fr Umsteiger

Overview of contents

eXtended Automation
(XA) overview
Architecture (XAA)
Engineering (XAE)
Runtime (XAR)

Connectivity
TwinCAT 2 Migration
Functions

TwinCAT 3 | Overview

23.05.2012

eXtended Automation (XA) overview


Architecture (XAA)

Engineering (XAE)

Runtime (XAR)

TwinCAT 3 | Overview

23.05.2012

eXtended Automation (XA)


Architecture (XAA)
eXtended
Architecture (XAA)

TcCOM

Safety

C++
Module

TcCOM

TcCOM

TcCOM

eXtended
Automation
Runtime (XAR)

PLC

TcCOM

Modular runtime system


NC

TwinCAT 3
eXtended
Automation (XA)
eXtended
Automation
Engineering (XAE)

TwinCAT 3 development environment


based on Visual Studio 2010
TwinCAT 3
Standard

TwinCAT 3
Integrated

Visual Studio
2010 Shell

Visual Studio
2010

TwinCAT 3 | Overview

23.05.2012

eXtended Automation (XA)


Architecture (XAA): subdivision into
engineering/runtime
eXtended Automation
Engineering (XAE)

eXtended Automation
Runtime (XAR)

Visual Studio 2010 for


real-time programming in
IEC 61131-3 and C/C++

Execution of the created


modules in real-time

Visual Studio 2010 for


the configuration of the
complete system

Support for multi-core


CPUs
Support for 64-bit systems

TwinCAT 3 | Overview

23.05.2012

Architecture (XAA)
PC System
Windows 32/64 bit
TwinCAT 3 Engineering Environment based on Visual Studio
System Manager
- Configuration

Programming
- IEC 61131-3
- objectoriented extensions
- C/C++

eXtended
Automation Engineering (XAE)

TwinCAT Transport Layer - ADS


TwinCAT 3 Runtime

TcCOM

TcCOM

CPLC
Module

C++
PLC
Module

TcCOM

Simulink
PLC
Module

NC
PLC

TcCOM

TcCOM

CNC
PLC

Safety
PLC

TcCOM

TcCOM

PLC
PLC

TcCOM

Real-time Kernel

PLC
PLC

eXtended
Automation Runtime (XAR)

TwinCAT Automation Device Driver - ADD

Fieldbus

TwinCAT 3 | Overview

23.05.2012

eXtended Automation (XA) overview


Architecture (XAA)

Engineering (XAE)

TwinCAT 3 Standard
TwinCAT 3 Integrated
System Manager
PLC
Motion Control
C/C++ programming
Matlab/Simulink
Integration
C#/ .NET programming

Runtime (XAR)

TwinCAT 3 | Overview

23.05.2012

eXtended Automation
Engineering (XAE)

TwinCAT 3 | Overview

23.05.2012

eXtended Automation
Engineering (XAE)
eXtended Automation Engineering (XAE)
TwinCAT 3
One programming environment
One project folder
One debugging environment for IEC and C/C++ - code
Integration of the familiar TwinCAT System Manager
Programming in IEC 61131-3 3rd Edition (NEU:
NEU object-orientated extension)
Real-time programming in C/C++
Integration and sequence of the C/C++ - program in the IEC environment or
execution as independent real-time code
Link to Matlab/Simulink
TwinCAT 2 PLC projects can be converted into a TwinCAT 3 PLC project
The old TwinCAT System Manager file (*.tsm file) can be converted
Embedded in Microsoft Visual Studio 2010
TwinCAT 3 | Overview

23.05.2012

10

eXtended Automation
Engineering (XAE) - variants

TwinCAT 3 Standard
Based on the Microsoft
Visual Studio Shell
Integrated System
Manager
Integrated IEC-61131-3
3rd edition programming
(OOP)
Integrated Safety PLC

TwinCAT 3 Integrated
Integration in an existing
Microsoft Visual Studio 2010
Integrated System Manager
Integrated IEC-61131-3 3rd
edition programming (OOP)
Integrated Safety PLC
C/C++ programming
Matlab/Simulink
C# and .NET programming for
non-real-time applications
Optional: implementation of thirdparty software tools
TwinCAT 3 | Overview

23.05.2012

11

Engineering (XAE)
TwinCAT 3 Standard

For (standard) PLC


programmers and users
of existing, compiled
modules (e.g. C/C++,
Matlab/Simulink)

TwinCAT 3 Engineering Environment

System Manager
Configuration
I/O
PLC
MC
NC
CNC
Safety
others

Configuration,
parameterisation and
diagnosis
Debugging of the PLC
code

Programming

IEC 61131

Objectoriented
extensions

IEC Compiler

TwinCAT Transport Layer ADS

TwinCAT 3 Runtime

TwinCAT 3 | Overview

23.05.2012

12

Engineering (XAE)
TwinCAT 3 Integrated

For PLC and C/C++


programmer
Configuration,
parameterisation
and diagnosis
Module development
(C/C++ or
Matlab/Simulink)
Debugging (PLC,
C/C++,
Matlab/Simulink)

Matlab/
Simulink

TwinCAT 3 Engineering Environment based on Visual Studio


System Manager
Configuration
I/O
PLC
C/C++
MC
NC
CNC
Safety
others

Third-party
programming
tool

Programming
Non
real-time

Real-time
Real-time
Workshop

C#.NET

IEC 61131

Objectoriented
extensions

IEC Compiler

C/C++

C/C++

Microsoft C Compiler

TwinCAT Transport Layer ADS

TwinCAT 3 Runtime

TwinCAT 3 | Overview

23.05.2012

13

Engineering (XAE)
TwinCAT 3 Integrated integrated working area
Workbench integration - integrated working area
TwinCAT 3 framework = Microsoft Visual Studio 2010
Use of the commonest development environment
Supported by Microsoft

Ultimate

Extendable via plug-ins (e.g. third party modules)


Usable with many common source-safe databases
Use of C/C++ source code for the programming of automation
devices
Use of .NET languages for non-real-time applications (e.g.
visualisations)

Professional

Improved help system on the basis of Microsoft Visual Studio


2010 Help (Microsoft Help system)
Premium
TwinCAT 3 | Overview

23.05.2012

14

Engineering (XAE)
Parallel programming of IEC 61131 and C++
C++ Code

IEC Code

TwinCAT 3 | Overview

23.05.2012

15

eXtended Automation (XA) - overview


Architecture (XAA)

Engineering (XAE)

TwinCAT 3 Standard
TwinCAT 3 Integrated
System Manager
PLC
Motion Control
C/C++ programming
Matlab/Simulink
Integration
C#/ .NET programming

Runtime (XAR)

TwinCAT 3 | Overview

23.05.2012

16

Engineering (XAE)
Integrated System Manager | Directory tree

System configuration

Motion control configuration

PLC configuration
Safety PLC configuration
C++ module configuration

I/O configuration
TwinCAT 3 | Overview

23.05.2012

17

Engineering (XAE)
Integrated System Manager | Mapping
Mapping of the process image
Open for all common fieldbuses
Support for all PC hardware interfaces
Simple diagnosis of the fieldbus data
Correlation between logical and physical fieldbus
A change of the bus system does not entail a
change of the PLC code!
TwinCAT process images
Virtual
process
images

Physical
process
images

Inputs

Inputs

Outputs

Fieldbus 1

Outputs

Inputs

Outputs

Inputs

Fieldbus 2
TwinCAT 3 | Overview

Outputs

Fieldbus 3
23.05.2012

18

eXtended Automation (XA) - overview


Architecture (XAA)

Engineering (XAE)

TwinCAT 3 Standard
TwinCAT 3 Integrated
System Manager
PLC
Motion Control
C/C++ programming
Matlab/Simulink
Integration
C#/ .NET programming

Runtime (XAR)

TwinCAT 3 | Overview

23.05.2012

19

Engineering (XAE)
TwinCAT 3 PLC
Multiple numbers of PLC projects:
Number of possible tasks: 256 (compare here to TwinCAT 2: 4x4)
Number of possible PLC projects limited only by the memory capacity of the automation
device (instead of 4 runtime systems in TwinCAT 2)
Programming
Standard IEC 61131-3 languages (IL, ST, FBD, LD, SFC) +CFC
Use of the object-orientated extensions of IEC 61131-3, 3rd edition
Call and data exchange of code developed in C/C++ and Matlab/Simulink
Large number of import and export interfaces
No direct addressing (necessary)
Commissioning/maintenance
Source code upload/download
Online Change
Complete debugging (breakpoints, monitoring, sequence control etc.) of IEC and C/C++
code

TwinCAT 3 | Overview

23.05.2012

20

Engineering (XAE)
TwinCAT 3 PLC | Development environment
Common tree structure for hardware and software

Common output of diagnosis and error messages (PLC, C++, system etc.)
TwinCAT 3 | Overview

23.05.2012

21

eXtended Automation (XA) - overview


Architecture (XAA)

Engineering (XAE)

TwinCAT 3 Standard
TwinCAT 3 Integrated
System Manager
PLC
Motion Control
C/C++ programming
Matlab/Simulink
Integration
C#/ .NET programming

Runtime (XAR)

TwinCAT 3 | Overview

23.05.2012

22

Engineering (XAE)
TwinCAT 3 Motion Control
Scalable solutions (from stepper motor to servo)
Higher flexibility in use and exchange of technology
Shortened development time faster delivery
Fast commissioning, diagnosis and maintenance
Abstraction level - identical access:
PLC/SCADA/HMI always access the same objects, irrespective of the type of
axis or fieldbus employed.
Conversion of mechanical to electronic systems:
Electronic cam plate
Electronic gearing
Electronic coupling
Electronic cam shaft
Flying saw

TwinCAT 3 | Overview

23.05.2012

23

+
PLC

SP

Pos Ctrl
Velo Preset

Limit
+

+
Scale & Limit

Pos Meas.

Drives
Layer

Fieldbus
Layer

Soft Motion
Layer

Soft SPS
Layer

Engineering (XAE)
TwinCAT 3 Motion Control | Abstraction level

TwinCAT 3 | Overview

23.05.2012

24

Engineering (XAE)
TwinCAT 3 Motion Control | From PTP to Robot Control
Covered functionality

NC PTP

NC I

CNC

Robotics

Point-to-Pointmovement

Interpolated motion
with 3 axes and
5 additional axes

Complete CNC
functionality

Interpolated motion
for robotic control

interpolated
movement for
up to 32 axes
per channel
various
transformations

support for a wide


rande of kinematic
systems
optional torque
pre-control

gearing
camming
superposition
flying saw

programming
according to DIN 66025
technological features
straightforward
utilisation through
function blocks from
the PLC

TwinCAT 3 | Overview

23.05.2012

25

eXtended Automation (XA) - overview


Architecture (XAA)

Engineering (XAE)

TwinCAT 3 Standard
TwinCAT 3 Integrated
System Manager
PLC
Motion Control
C/C++ programming
Matlab/Simulink
Integration
C#/ .NET programming

Runtime (XAR)

TwinCAT 3 | Overview

23.05.2012

26

Engineering (XAE)
C/C++ programming languages
Reusability of already existing C/C++ code
Common use of C/C++ and PLC code
Real-time applications available for all platforms (CE, 7)
Opening up of a completely new world for automation technology
Renowned and well-known programming language
Standardised (C: ISO/IEC 9899 TC3, C++: IEC 14882)
The creation of Automation Device Drivers (ADD) enables you to implement your
own drivers (e.g. for your own fieldbus system or the like)
Beckhoff SDK supports (similar to PLC libraries)
ADS
No t
Motion
ye t
a va
File I/O ilable!

TwinCAT 3 | Overview

23.05.2012

27

Engineering (XAE)
C/C++ programming languages | Integration

TwinCAT 3 | Overview

23.05.2012

28

eXtended Automation (XA) - overview


Architecture (XAA)

Engineering (XAE)

TwinCAT 3 Standard
TwinCAT 3 Integrated
System Manager
PLC
Motion Control
C/C++ programming
Matlab/Simulink
Integration
C#/ .NET programming

Runtime (XAR)

TwinCAT 3 | Overview

23.05.2012

29

Engineering (XAE)
Matlab/Simulink
Well-known from science and measurement technology
Large variability of toolboxes (e.g. fuzzy etc.)
Generation, simulation and optimisation of controller structures
Debug interface between Simulink and TwinCAT

Code generation
Design: Simulink
Automatic generation of C code by the Simulink real-time workshop
Compilation with the Visual Studio C compiler
Parameterisation in the TwinCAT System Manager
Download and execution in the TwinCAT 3 runtime (XAR)

TwinCAT 3 | Overview

23.05.2012

30

Engineering (XAE)
Matlab/Simulink | Integration

TwinCAT 3 | Overview

23.05.2012

31

eXtended Automation (XA) - overview


Architektur (XAA)

Engineering (XAE)

TwinCAT 3 Standard
TwinCAT 3 Integrated
System Manager
PLC
Motion Control
C/C++ programming
Matlab/Simulink
Integration
C#/ .NET programming

Runtime (XAR)

TwinCAT 3 | Overview

23.05.2012

32

Engineering (XAE)
C#/.NET programming

HMI/
Windows processes

PLC module
C++ module

Real-time Code

TwinCAT 3 | Overview

23.05.2012

33

eXtended Automation (XA) - overview


Architecture (XAA)

Engineering (XAE)

Runtime (XAR)

Modular runtime system


TwinCAT modules
Multi-core support

TwinCAT 3 | Overview

23.05.2012

34

eXtended Automation
Runtime (XAR)

TwinCAT 3 | Overview

23.05.2012

35

eXtended Automation
Runtime (XAR) | Modular runtime systems
Debugging

PLC
C++
Module

Task

TcCOM

Task

TcCOM

TcCOM

Call

PLC
Simulink
Module

PLC
CNC
Task

Task

PLC
NC

Call

PLC
PLC

C++
Module

TcCOM

Task

TcCOM

Task

Call

PLC
C
Module

TcCOM

PLC

TcCOM

Task

TcCOM

TwinCAT Object Manager

TcCOM

Firmly defined interface (e.g. TwinCAT


Component Object Model - TcCOM)

TC Configuration

TcCOM

Management of the modules with the


TwinCAT Object Manager

TwinCAT Transport Layer - ADS

TwinCAT Real-time
Kernel

Dynamic environment for the execution


and management of TwinCAT 3
modules
Standard PLC code
NC code
C++ code

PLC
Simulink
Module

PLC
Safety
TwinCAT 3 Runtime

TwinCAT Automation Device Driver - ADD

Fieldbus

TwinCAT 3 | Overview

23.05.2012

36

eXtended Automation
Runtime (XAR) | TwinCAT modules
Must
Description (methods, functions, names
etc.)
StateMachine (Init, PreOp, Op)
TcCom Interface

TwinCAT Module
Module Description
State Machine
ITComObject Interface

Can

Interfaces

Parameter

Interfaces
Pointers

Interfaces
Parameter
Data Areas

Contexts

Data Areas

Categories

ADS Port

TwinCAT 3 | Overview

Data Area
Pointers

23.05.2012

37

eXtended Automation
TwinCAT 3 Multi-core support

TwinCAT 3 | Overview

23.05.2012

38

Runtime (XAR)
TwinCAT 3 Multi-core support
Support for multi-core systems
Assignment of the individual projects to
different cores
PLC, NC, HMI etc. each assigned
to their own core
Scalable basic time for each core
Scalable CPU limit adjustable for each
core

Multi-core CPU
Core 0

Core 1

Core 2

Core 3

Core ...

Windows
Apps

PLC Control

User HMI

PLC Runtime 0

PLC Runtime 1

NC Runtime 1

Windows
Drivers

ADS

ADS

ADS

Task 0 Task 1

ADS

ADS

ADS Router Engine

L2 Shared Cache

ADS Router Message Queues

System Memory

TwinCAT 3 | Overview

23.05.2012

39

Runtime (XAR)
TwinCAT 3 Multi-core support | Assignment
Activation of the cores

Definition of the CPU limits


Definition of the basic time

Assignment of the task to the core/CPU

TwinCAT 3 | Overview

23.05.2012

40

Overview of contents

Motivation why
TwinCAT 3
eXtended Automation
(XA) - overview
Architecture (XAA)
Engineering (XAE)
Runtime (XAR)

Connectivity
TwinCAT 2 Migration
Functions
TwinCAT 3 | Overview

23.05.2012

41

eXtended Automation
Connectivity

TwinCAT 3 | Overview

23.05.2012

42

eXtended Automation
Connectivity | ADS to Communication
(PLC) PC 1

(PLC) PC 2

TwinCAT
TwinCAT

TwinCAT

TwinCAT

Automation
Protocols

Industry
Protocols

IT
Protocols

Web
Server Ils

TwinCAT

Automation
Device
Specification
(ADS)

OPC UA,
Modbus
TCP, Modbus
RTU
3964R/RK512

IEC 61850,
IEC 61400-25,
IEC 60870-510x,
BACnet, FIAS,
Creston

WLAN,
Bluetooth,
TCP, UDP,
RAS,
FTP, VPN,
SNMP, SNTP,
SMS, SMTP

XML, AJAX,
ASP,
DPWS/WSD

Automation
Device
Specification
(ADS)

Acyclic

TwinCAT ADS Router

TCP, UDP, Serial,


Fieldbus

TwinCAT ADS
Router

Cyclic
EtherCAT Automation
Protocol (EAP),
Network variables

TwinCAT 3 | Overview

23.05.2012

43

Overview of contents

Motivation why
TwinCAT 3
eXtended Automation
(XA) - overview
Architecture (XAA)
Engineering (XAE)
Runtime (XAR)

Connectivity
TwinCAT 2 Migration
Functions
TwinCAT 3 | Overview

23.05.2012

44

eXtended Automation
TwinCAT 2 Migration | Opening old projects
The opening of projects created with TwinCAT 2 results in:

1.) Conversion of old projects to the TwinCAT 3 format


Process can not be undone!
TwinCAT 3 projects can not be saved in the TwinCAT 2 project format!

Conversion of existing TwinCAT 2 projects to the TwinCAT 3 format means:


Extension of the project by new features
Increased reusability of the existing code in new project parts
Use of the same tools for all projects
Conversion of PLC Control and System Manager files

TwinCAT 3 | Overview

23.05.2012

45

Overview of contents

Motivation why
TwinCAT 3
eXtended Automation
(XA) - overview
Architecture (XAA)
Engineering (XAE)
Runtime (XAR)

Connectivity
TwinCAT 2 Migration
Functions
TwinCAT 3 | Overview

23.05.2012

46

eXtended Automation
TwinCAT Functions
The previously familiar TwinCAT supplements also exist in TwinCAT 3
The designation changes to TwinCAT Functions: TFxxxx

TwinCAT 2 supplement licences


cannot be used in TwinCAT 3!
New (if necessary trial) licences
must be generated for this.

TwinCAT 3 | Overview

23.05.2012

47

TwinCAT 3 | New Automation Technology

Overview

Training fr Umsteiger
Thank you very much for your
attention!

New Automation Technology

12.04.2013

eXtended Automation (XA) - overview


Architecture (XAA)

Engineering (XAE)

Runtime (XAR)

TwinCAT 3 | Overview

23.05.2012

eXtended Automation (XA)


Architecture (XAA)
eXtended
Architecture (XAA)

TcCOM

Safety

C++
modules

TcCOM

TcCOM

TcCOM

eXtended
Automation
Runtime (XAR)

PLC

TcCOM

Modular runtime system


NC

TwinCAT 3
eXtended
Automation (XA)
eXtended
Automation
Engineering (XAE)

TwinCAT 3 development environment


based on Visual Studio 2010
TwinCAT 3
Standard

TwinCAT 3
Integrated

Visual Studio
2010 Shell

Visual Studio
2010

23.05.2012

eXtended Automation (XA)


Architecture (XAA) - notebook example (XAE) CX
eXtended
Automation
Engineering (XAE)

TwinCAT 3 development environment


Visual Studio 2010
TwinCAT 3
Standard

TwinCAT 3
Integrated

Visual Studio
2010 Shell

Visual Studio
2010

eXtended
Automation
Runtime (XAR)

TwinCAT 3 | Overview

23.05.2012

eXtended Automation (XA)


Architecture (XAA) - notebook example (XAE) CX
Ethernet interface used as
programming interface

eXtended
Automation
Runtime (XAR)

TcCOM

Safety

C++
modules

TcCOM

TcCOM

TcCOM

PLC

TcCOM

Modular runtime system


NC

EtherCAT

TwinCAT 3 | Overview

23.05.2012

eXtended Automation (XA)


Architecture (XAA) - notebook example (XAE) CX
TwinCAT 3 development environment on
notebook

TwinCAT 3 runtime on CX /IPC

TwinCAT 3
Standard / Integrated
TwinCAT Transport Layer - ADS
TwinCAT 3 Runtime
Real-time Kernel

Simulink
PLC
modules

C++
PLC
modules

PLC
PLC

IO

TwinCAT Transport Layer - ADS

CNC
PLC

TwinCAT 3 | Overview

23.05.2012

eXtended Automation (XA)


Architecture (XAA) - notebook example (XAE) CX
TwinCAT 3 development
environment PC

TwinCAT 3 runtime on CX /IPC

TwinCAT 3
Standard / Integrated

TwinCAT Transport Layer - ADS

Real-time Kernel
CNC
PLC

Simulink
PLC
modules

C++
PLC
modules

PLC
PLC

IO

TwinCAT Transport Layer - ADS

TwinCAT 3 Runtime

Config Mode:
to enable communication (programming)
XAE status
PC
taskbar

scanning of hardware / IO test in Freerun


Run Mode : PLC NC IO etc. operate in real-time

TwinCAT 3 | Overview

23.05.2012

eXtended Automation (XA)


Architecture (XAA) - notebook example (XAE) CX

TwinCAT XAE displays TwinCAT


state on the target system

TwinCAT on the target computer


(CX / IPC)

PC taskbar

The target computer


must be in the RUN
state in order to logon
to the PLC

Real-time load in %

TwinCAT 3 | Overview

23.05.2012

Establishment of a connection
Practical part

Establishment of a
connection

TwinCAT 3 | Overview

23.05.2012

Establishment of a connection
Requirement: TC3 is successfully installed on the programming computer and the
target computer
Hardware with PC (XAE)
Target system CX with BK1120 Bus Station

12.04.2013

10

Hardware
Example hardware
PC with TwinCAT3 XAE,
CX with EtherCAT
adaptor
TwinCAT3 XAE / XAR
on the same computer
(local)
BK1120 Bus Coupler
2* KL1XX2 2-CHANNEL
DIG IN
2* KL2XX4 4-CHANNEL
DIG OUT
1* KL2531 Stepper
Terminal
12.04.2013

11

Starting the VS2010 / 2010 shell


Taskbar TwinCAT
VS2010 symbol

12.04.2013

12

Enter higher-level headline

Starting the VS2010 / 2010 shell


New Project
XAE Project

12.04.2013

13

Setting the target system

12.04.2013

14

Establishment of a connection
To search, first select Local Target System

12.04.2013

15

Establishment of a connection

searches
for TC
controllers
IPC/ CX

Connection
to both
devices
(enter PC
target
system)

12.04.2013

16

Establishment of a connection
Logon information: user name and password for computer.
Training CX 1020
CX training:

Administrator
1

12.04.2013

17

Establishment of a connection

Connection
valid

12.04.2013

18

Establishment of a connection

12.04.2013

19

Status of connection establishment


TwinCAT XAE displays TwinCAT
state on the target system

TwinCAT on the target computer


(CX / IPC)

PC taskbar

12.04.2013

20

State of the TwinCAT symbol


TwinCAT XAE displays TwinCAT
state on the target system

The TwinCAT system on the XAE


computer must be in the Config
Mode for logging on.

The target system must


be in Config Mode for
scanning and freerun test
of the hardware

The target computer


must be in the RUN state
in order to logon to the
PLC later

Run Mode is also possible if the XAE computer


simultaneously represents a control computer
(XAR)

12.04.2013

21

Scan and Freerun


Practical part

Hardware test

Scanning
Freerun Mode

TwinCAT 3 | Overview

22

23.05.2012

Enter higher-level headline

Scan Hardware
Check Config
Mode, activate
Config Mode if
necessary
Scan

12.04.2013

23

Enter higher-level headline

Scan Hardware
Scan Hardware

12.04.2013

24

Enter higher-level headline

Freerun
In Freerun Mode,
I/O can be tested
without PLC program

12.04.2013

25

PLC Program
Practical part

Create PLC program

Generate global variables


Linkage with the hardware

TwinCAT 3 | Overview

26

23.05.2012

Enter higher-level headline

Add PLC project


Create PLC project

12.04.2013

27

Enter higher-level headline

Global Variable List


PLC project from
template
Generate global variable
list

12.04.2013

28

Enter higher-level headline

Global Variable List


Name

12.04.2013

29

Enter higher-level headline

Global Variable List


Create global variables

12.04.2013

30

Enter higher-level headline

Linking
Link

12.04.2013

31

Enter higher-level headline

Linking
Link

12.04.2013

32

Enter higher-level headline

Linking
Further links

12.04.2013

33

Enter higher-level headline

Activate
Activating the
configuration
Wait for Run Mode

12.04.2013

34

Enter higher-level headline

Activate
If TwinCAT XAR is not
registered, a 7-day
licence can be created

12.04.2013

35

Enter higher-level headline

Login
Logon to PLC project

Login

Start
PLC

PLC
Online

PLC RUN

12.04.2013

36

Online

XAE offline + PLC not in Run Mode


XAE online + PLC not in Run Mode
XAE offline + PLC in Run Mode
XAE online + PLC in Run Mode

TwinCAT in Run Mode

Enter higher-level headline

Monitoring
Global variables online

Write
Value
s
12.04.2013

38

Enter higher-level headline

Extending the program


Logout
Create FB

12.04.2013

39

Enter higher-level headline

Extending the program


Create FB

12.04.2013

40

Enter higher-level headline

Extending the program


Edit FB
Toolbox: VIEW>TOOLBOX

12.04.2013

41

Enter higher-level headline

Extending the program


Edit FB
Adapt connection with
Set output connection

12.04.2013

42

Enter higher-level headline

Extending the program


Edit FB
Adapt connection with
Set output connection

12.04.2013

43

Enter higher-level headline

Extending the program


Call block in Main (ST)
with input assistant and
Auto Declare

12.04.2013

44

Enter higher-level headline

Extending the program


Call block in Main (ST)
with input assistant
and Auto Declare

12.04.2013

45

Enter higher-level headline

Extending the program


Call block in Main (ST)
with input assistant
and Auto Declare
Configure input and
output

12.04.2013

46

Autostart
Practical part

Settings for automatic start of


the XAR

Activate boot project


Enable boot project start
Set TwinCAT autostart for
RUN

TwinCAT 3 | Overview

47

23.05.2012

Enter higher-level headline

Autostart
Boot project
Enable autostart
Creating a boot project

12.04.2013

48

Enter higher-level headline

Autostart
TwinCAT autostart

12.04.2013

49

Enter higher-level headline

Autostart
User name and
password for the
control computer

12.04.2013

50

TwinCAT 3 | New Automation Technology

Handling

Training fr Umsteiger

TwinCAT 3 | New Automation Technology

Overview of contents
Version differences

Visual Studio 2010


Visual Studio 2010 Shell

Integration of the TwinCAT System


Manager
System
PLC
Slide-in 1: EtherCAT Bus Terminals
Slide-in 2: Variable Declaration
Practice slide-in 1: The first project
Automatic start of the controller
Establishing a remote connection
Own data types
Working with several tasks
Backup on the target system
Encrypt the project

TwinCAT 3 | Handling

23.05.2012

TwinCAT 3 | New Automation Technology

Version differences | Overview

TwinCAT 3 Standard

TwinCAT 3 Integrated

Based on the Microsoft


Visual Studio Shell

Integration in an existing Microsoft


Visual Studio 2010

Integrated TwinCAT
System Manager

Integrated IEC-61131-3 3rd edition


programming (OOP)

Integrated IEC-61131-3
3rd edition programming
(OOP)
Integrierte Safety PLC

Integrated System Manager

Integrierte Safety PLC


C/C++ programming
Matlab/Simulink
C# and .NET programming for nonreal-time applications
Optional: Implementation of thirdparty software tools
TwinCAT 3 | Handling

23.05.2012

TwinCAT 3 | New Automation Technology

Version differences | Concept

TwinCAT 3 | Handling

23.05.2012

TwinCAT 3 | New Automation Technology

Overview of contents
Version differences

Visual Studio 2010


Visual Studio 2010 Shell

Integration of the TwinCAT System


Manager
System
PLC
Slide-in 1: EtherCAT Bus Terminals
Slide-in 2: Variable Declaration
Practice slide-in 1: The first project
Automatic start of the controller
Establishing a remote connection
Own data types
Working with several tasks
Backup on the target system
Encrypt the project

TwinCAT 3 | Handling

23.05.2012

TwinCAT 3 | New Automation Technology

Integration of the TwinCAT System Manager


Complete integration of the TwinCAT
System Manager into the Microsoft
Visual Studio tree.
The complete collection of project data
(PLC, NC, hardware configuration) is
summarised in one solution
(Projectname.sln).
Each individual project in the solution
has its own process image.
Simulation of I/Os and axes.
Parameterisation of TwinCAT modules.

TwinCAT 3 | Handling

23.05.2012

TwinCAT 3 | New Automation Technology

Overview of contents
Version differences

Visual Studio 2010


Visual Studio 2010 Shell

Integration of the TwinCAT System


Manager
System
PLC
Slide-in 1: EtherCAT Bus Terminals
Slide-in 2: Variable Declaration
Practice slide-in 1: The first project
Automatic start of the controller
Establishing a remote connection
Own data types
Working with several tasks
Backup on the target system
Encrypt the project

TwinCAT 3 | Handling

23.05.2012

TwinCAT 3 | New Automation Technology

System configuration
The tree entry system contains
Licence
Real time
Tasks
Routing
TcCom Objects

TwinCAT 3 | Handling

23.05.2012

TwinCAT 3 | New Automation Technology

Licence | General overview


Licensing in TwinCAT 3 is divided into two steps:
Sales-related procedure
Technical integration in TwinCAT XAE

Alternative:
7-day test licence

Sales-related procedure
1. Ordering of the desired TwinCAT 3 package
Technical integration in TwinCAT XAE
2. All licences necessary for the project are listed automatically in TwinCAT XAE. This
list can also be extended manually. A licence file (Licence Request File) is generated
from it.
3. The licence file is sent by email to the Beckhoff Activation Server
4. The activation server creates a valid licence file (Licence Response File), which is
imported into TwinCAT XAE

TwinCAT 3 | Handling

23.05.2012

TwinCAT 3 | New Automation Technology

Licence | Diagram
Procedure for generating and integrating a chargeable licence file:

TwinCAT 3 | Handling

23.05.2012

10

TwinCAT 3 | New Automation Technology

Licence | Generation of the chargeable licence


In the Licence section below System in the configuration tree, the project-related
licences can be viewed on the Order Information tab or further licences can be
selected for ordering on the Manage Licences tab.
The corresponding file is generated by actuating the Generate Licence Request
File button
The Beckhoff Licence ID
is transmitted on
confirmation of the order
and must be entered here.

The generated file can then be sent by email:


TwinCAT 3 | Handling

23.05.2012

11

TwinCAT 3 | New Automation Technology

Licence | Importing the chargeable licence


The Licence Response File is received via the same email address that was used
to send the Licence Request File
This file can be read in the same section where the Request File was also
generated

After linking the licence file, it is automatically copied to %TwinCATDIR%


\Target\License
TwinCAT 3 | Handling

23.05.2012

12

TwinCAT 3 | New Automation Technology

Licence | 7-day test licence


In TwinCAT 3 there is a possibility to generate a 7-day test licence including
the required TwinCAT Functions - completely without limitations!
There are two different ways to use a test licence:
a)On the local system
i. The Order Information tab displays all licences necessary for the project for
which a 7-day test licence is generated

ii.

If a test licence has not yet been generated, but the project is to be activated,
then a message appears upon activation that licences are missing and will
now be generated. It is necessary to input a code for this:

TwinCAT 3 | Handling

23.05.2012

13

TwinCAT 3 | New Automation Technology

Licence | 7-day test licence | Remote system


b) On a remote system
i. An ADS connection must exist in order to copy the licence to the device

ii.

Two tabs are displayed in the Licence section: Order Information (Runtime)
and Order Information (Engineering). The necessary 7-day test licence can
be activated and confirmed on the Runtime tab.

TwinCAT 3 | Handling

23.05.2012

14

TwinCAT 3 | New Automation Technology

Real Time Settings


Assignment of the task(s) to a core
Definition of the base time for each
core
Setting of the CPU limit of the core

TwinCAT 3 | Handling

23.05.2012

15

TwinCAT 3 | New Automation Technology

Task Management
Central management of the task(s) for
this solution

Reference of the PlcTask from the PLC


to Task Management
TwinCAT 3 | Handling

23.05.2012

16

TwinCAT 3 | New Automation Technology

TcCom Objects
Linking of binaries
Matlab/Simulink
C++ modules in TwinCAT standard environments

TwinCAT 3 | Handling

23.05.2012

17

TwinCAT 3 | New Automation Technology

Overview of contents
Version differences

Visual Studio 2010


Visual Studio 2010 Shell

Integration of the TwinCAT System


Manager
System
PLC
Slide-in 1: EtherCAT Bus Terminals
Slide-in 2: Variable Declaration
Practice slide-in 1: The first project
Automatic start of the controller
Establishing a remote connection
Own data types
Working with several tasks
Backup on the target system
Encrypt the project

TwinCAT 3 | Handling

23.05.2012

18

TwinCAT 3 | New Automation Technology

PLC programming | Overview


Several PLC projects can be managed in a solution
Number of possible tasks: 65,000 (compare TwinCAT 2: 4x4)
Number of possible PLC projects: limited only by the memory capacity of the
automation device (compare TwinCAT 2: 4 RTS)
Programming:
Standard IEC 61131-3 languages (IL, ST, FBD, LD, SFC) +CFC
Use of the object-orientated extensions of IEC 61131-3, 3rd edition
Call and data exchange of code developed in C/C++ and Matlab/Simulink
Large number of import and export interfaces
No direct addressing (necessary)
Commissioning/maintenance
Source code upload/download
Online Change
Complete debugging (breakpoints, monitoring, sequence control etc.) of IEC
and C/C++ code

TwinCAT 3 | Handling

23.05.2012

19

TwinCAT 3 | New Automation Technology

PLC programming | Editor | Declaration of variables


Choice between normal declaration view and tabular view
All changes are consistent in both views

TwinCAT 3 | Handling

23.05.2012

20

TwinCAT 3 | New Automation Technology

PLC programming | Editor | Structured Text (ST)


Improved usability:
Automatic completion (auto-complete)
Marking of keywords associated with one another

Collapsing of programming structures

TwinCAT 3 | Handling

23.05.2012

21

TwinCAT 3 | New Automation Technology

PLC programming | Editor | LD/FBD/IL


Just one editor for all 3 programming languages!
Switching between the
languages without translating
Online switching possible
Settings e.g. for
symbol comments affect all views
Mixed networks

LD
Contact networks at all inputs
Coils at all outputs
Several blocks in a network
IL
Now table-orientated
TwinCAT 3 | Handling

23.05.2012

22

TwinCAT 3 | New Automation Technology

PLC programming | Libraries


Namespaces and default namespaces
Internal and external objects in one library
Installation of the libraries necessary!
Identification via name, company and version
Several versions of a library possible per installation
Use of several versions of a library possible within a project

TwinCAT 3 | Handling

23.05.2012

23

TwinCAT 3 | New Automation Technology

Overview of contents
Version differences

Visual Studio 2010


Visual Studio 2010 Shell

Integration of the TwinCAT System


Manager
System
PLC
Slide-in 1: EtherCAT Bus Terminals
Slide-in 2: Variable Declaration
Practice slide-in 1: The first project
Automatic start of the controller
Establishing a remote connection
Own data types
Working with several tasks
Backup on the target system
Encrypt the project

TwinCAT 3 | Handling

23.05.2012

24

TwinCAT 3 | New Automation Technology

Slide-in 1: EtherCAT Bus Terminals

TwinCAT 3 | Handling

23.05.2012

25

TwinCAT 3 | New Automation Technology

EtherCAT Coupler as link


The EtherCAT Coupler (e.g. EK1100) represents the link between the fieldbus
master and the EtherCAT I/O system.

A fieldbus master can manage up to 65535 EtherCAT slaves


These slaves can be I/O terminals, EtherCAT couplers or servo controllers etc.

TwinCAT 3 | Handling

23.05.2012

26

TwinCAT 3 | New Automation Technology

The EtherCAT terminals in detail

Terminal block design:


12 x 100 x 68 mm (W x H x D)

Screwless
connection
technology

Symmetrical
unlatching for
vertical removal

Power contacts for


automatic bridging
of the power
potentials

TwinCAT 3 | Handling

23.05.2012

27

TwinCAT 3 | New Automation Technology

Further features of the EtherCAT terminals


4-wire connection
technology

Terminal type based on the label


Digital inputs:
EL1xxx
Digital outputs:
EL2xxx
Analog inputs:
EL3xxx
Analog outputs:
EL4xxx
Communication:
EL6xxx
Drive:
EL7xxx
System:
EL9xxx
Last digit = number of channels

Leading PE contact

Tongue and groove


connection

TwinCAT 3 | Handling

23.05.2012

28

TwinCAT 3 | New Automation Technology

Overview of contents
Version differences

Visual Studio 2010


Visual Studio 2010 Shell

Integration of the TwinCAT System


Manager
System
PLC
Slide-in 1: EtherCAT Bus Terminals
Slide-in 2: Variable Declaration
Practice slide-in 1: The first project
Automatic start of the controller
Establishing a remote connection
Own data types
Working with several tasks
Backup on the target system
Encrypt the project

TwinCAT 3 | Handling

23.05.2012

29

TwinCAT 3 | New Automation Technology

Slide-in 2: Variable Declaration


In order to be able to link variables from the PLC to hardware inputs or outputs,
these must be specially declared
The variable
AnalogValuePot1
is to record a potentiometer
control value via an analog input terminal.
General addressing regulation:
I

0.1
BOOL

Variable name

AT

;
INT

This results in the following declaration possibilities for the example variable
AnalogValuePot1:

or
TwinCAT 3 | Handling

23.05.2012

30

TwinCAT 3 | New Automation Technology

Fixed addressing vs. automatic addressing


In comparison with fixed addressing,

a placeholder for an address to be assigned


by the System Manager is inserted in
automatic addressing by adding a *:

TwinCAT 3 | Handling

23.05.2012

31

TwinCAT 3 | New Automation Technology

Declaration regulation for naming


Naming restrictions

Lamp AT %QX0.0 : BOOL;


Switch AT %IX0.0 : BOOL;

Analog_Value AT %IB2:INT;

1. No special
characters

2. No spaces

Temperature AT %IB100 :INT;

Zhler AT %IB3 : UINT;

3. Permitted for
separation

b
c

PWM_Output AT %QB10 :INT;

TwinCAT 3 | Handling

4. No umlauts

23.05.2012

32

TwinCAT 3 | New Automation Technology

Overview of contents
Version differences

Visual Studio 2010


Visual Studio 2010 Shell

Integration of the TwinCAT System


Manager
System
PLC
Slide-in 1: EtherCAT Bus Terminals
Slide-in 2: Variable Declaration
Practice slide-in 1: The first project
Automatic start of the controller
Establishing a remote connection
Own data types
Working with several tasks
Backup on the target system
Encrypt the project

TwinCAT 3 | Handling

23.05.2012

33

TwinCAT 3 | New Automation Technology

Practice slide-in 1: The first project


Starting the TwinCAT 3 engineering
(XAE) - fast start via the TwinCAT Icon

TwinCAT 3 | Handling

23.05.2012

34

TwinCAT 3 | New Automation Technology

Creating a new project


Generating a new project
Selection of the template
TwinCAT Project

TwinCAT Project creates a


new solution with System
Manager tree

Enter name and specify


storage location for the
solution
TwinCAT 3 | Handling

23.05.2012

35

TwinCAT 3 | New Automation Technology

Project folder explorer


The project folder explorer manages
the complete solution and contains the
name that was selected when creating
the project.
If there is only one project, then
this has the solution name.
If there are several projects the
name can simply be changed
with a right click.
Further projects can be added by rightclicking on the project folder.
Existing projects always end
with *.tsp

TwinCAT 3 | Handling

23.05.2012

36

TwinCAT 3 | New Automation Technology

Installation: devices compatible with real-time Ethernet


For the use of real-time
Ethernet devices as fieldbus
masters, such as
9 EtherCAT
9 Realtime Ethernet
it is necessary to install an
appropriate protocol for
an INTEL chipset-based
Ethernet controller:
TwinCATShow
Realtime Ethernet
Compatible Devices

TwinCAT 3 | Handling

23.05.2012

37

TwinCAT 3 | New Automation Technology

Step 1: Generating a hardware configuration


1 You can automatically search for devices
by right-clicking on Devices in the I/O
menu option.
2 Depending on the fieldbus masters in
use, these will be displayed for selection
in the subsequent window.

3 When the selection is confirmed


with
, a search will be performed
for slaves connected to the selected
master if
is selected in the
dialog box.

TwinCAT 3 | Handling

23.05.2012

38

TwinCAT 3 | New Automation Technology

Testing the created configuration


The Free Run mode can be activated
in order to perform an I/O check.

TwinCAT 3 | Handling

23.05.2012

39

TwinCAT 3 | New Automation Technology

Step 2: Creating a PLC configuration


By right-clicking on PLC, either a
new TwinCAT 3 project
or an existing TwinCAT 3
(*.plcproj) or TwinCAT 2
(*.pro file) can be added

The standard PLC project or an


empty PLC project can be used
as the template for the new
project

TwinCAT 3 | Handling

23.05.2012

40

TwinCAT 3 | New Automation Technology

PLC project in detail


Below the PLC Configuration a PLC
project is created with the name
entered previously.
On creating the project the first POU:
MAIN is also created.
The PLC project is subdivided into
code and instance

At the same time as the PLC project, a


PLC task was created as a reference to
the created task in the system task
area.

TwinCAT 3 | Handling

23.05.2012

41

TwinCAT 3 | New Automation Technology

Step 3: IEC example Blinker


A function block FB_Blinker is now added to the already created POU MAIN.
By right-clicking on POUs a further block can now be created as a function block in
FUP/FBD.
2

TwinCAT 3 | Handling

23.05.2012

42

TwinCAT 3 | New Automation Technology

FB_Blinker | Add box


Depending on the selected language,
the Toolbox contains elements for
inserting into the block:

A total of 3 boxes are required, which


are inserted one after the other

The first box is pulled here into the first


network by drag & drop.
TwinCAT 3 | Handling

23.05.2012

43

TwinCAT 3 | New Automation Technology

FB_Blinker | Structure of the FB

The blinker is to be realised by means of an AND condition and two seriesconnected timer blocks of the type TON, to which an instance name will also be
assigned in the next step

TwinCAT 3 | Handling

23.05.2012

44

TwinCAT 3 | New Automation Technology

FB_Blinker | Instancing
Typing the implementation name for a timer opens the selection help:

If the instance name is now issued by selecting the ??? above the box, the
declaration help for creating the instance opens:
If you confirm the entries here, then
the instance is created in the selected
object FB_Blinker in the local variable
class VAR.
The second box is instanced in exactly
the same way.
TwinCAT 3 | Handling

23.05.2012

45

TwinCAT 3 | New Automation Technology

FB_Blinker | Instancing
The first box in the chain becomes the AND gate which, inserted as a function,
requires no instance formation:

The first input of the AND gate should be connected to the external variable bStart.
As soon as this is entered in place of ???, the declaration help opens again.
VAR_INPUT is selected here as
the memory location (Scope)
The type of variable (type) is
recognised automatically on the
basis of the block.

TwinCAT 3 | Handling

23.05.2012

46

TwinCAT 3 | New Automation Technology

FB_Blinker | Instancing
The second input of the AND gate is connected to the output Q of the second
timing element T2 and negated by right-clicking on the input in front of the box:

The runtime is specified via the PT inputs of timing elements T1 and T2, which are
declared as input variables of the FB_Blinker
On creating the tZeit variables, the declaration help opens again, via which the
variables are created in the VAR_INPUT area.

TwinCAT 3 | Handling

23.05.2012

47

TwinCAT 3 | New Automation Technology

FB_Blinker | Instancing
The generated pulse is output from the FB_Blinker via the variable bBlinkimpuls by
declaration as VAR_OUTPUT.
The value is tapped by means of adding an Insert Assignment by right-clicking in
front of the IN input of T2:

TwinCAT 3 | Handling

23.05.2012

48

TwinCAT 3 | New Automation Technology

FB_Blinker | The finished block


The finished FB now contains all necessary blocks and variables for operation and
can be instanced and called in the MAIN POU.

TwinCAT 3 | Handling

23.05.2012

49

TwinCAT 3 | New Automation Technology

MAIN | Creation in FBD


The first POU MAIN has been inserted in the Structured Text (ST).
This can be deleted by a right-click and replaced by a block of the type program
with the same name:

TwinCAT 3 | Handling

23.05.2012

50

TwinCAT 3 | New Automation Technology

MAIN | Assignment to the task


The new MAIN POU must now be assigned again to the task:

The FB_Blinker is now called again by creating a box in the first network
In this case, however, the button is used that appears as soon as the inner ???
are selected:

TwinCAT 3 | Handling

23.05.2012

51

TwinCAT 3 | New Automation Technology

MAIN | Inserting the FB_Blinker as an instance


Using the Input Assistant, you can now search inside the PLC project Plc0815 for
the block to be inserted:

After insertion, an instance name is selected as before and added to the variables
area VAR in the POU MAIN

TwinCAT 3 | Handling

23.05.2012

52

TwinCAT 3 | New Automation Technology

MAIN | Creation of global I/O variables


The input tZeit of the FB_Blinker instance is permanently assigned the value T#2s
bStart and bBlinkImpuls should be linked to hardware inputs or outputs.
To this end, a global variables list is first created under GVLs:

Subsequently, the variable Taster1 can be created via the variable declaration in
the global variables at address %IX0.1:

TwinCAT 3 | Handling

23.05.2012

53

TwinCAT 3 | New Automation Technology

MAIN | Creation of global I/O variables


The procedure is similar for the output bBlinkImpuls.
The only difference here is that the output must first be made connectable via
Insert Assignment
The variable Lampe1 is then placed at the address %QX0.1 as an output

TwinCAT 3 | Handling

23.05.2012

54

TwinCAT 3 | New Automation Technology

Project creation | Creation of the instance


After successful translation (creation) of the PLC project by right-clicking, a PLC
instance is created with the variables that are to be linked to hardware:

The variables from this instance can now be connected to the hardware
TwinCAT 3 | Handling

23.05.2012

55

TwinCAT 3 | New Automation Technology

Linking the variables


By right-clicking on the respective variable, the link target can be selected via
Change Link

TwinCAT 3 | Handling

23.05.2012

56

TwinCAT 3 | New Automation Technology

Activation of the configuration


The configuration can now be activated and the controller set to RUN

2
The feedback signal can be recognised by the
green TwinCAT icon in the TwinCAT XAE and
the taskbar.

TwinCAT 3 | Handling

23.05.2012

57

TwinCAT 3 | New Automation Technology

Login to the controller


After successful activation, the login to the controller can take place
To this end the project is selected and starts automatically

TwinCAT 3 | Handling

23.05.2012

58

TwinCAT 3 | New Automation Technology

Overview of contents
Version differences

Visual Studio 2010


Visual Studio 2010 Shell

Integration of the TwinCAT System


Manager
System
PLC
Slide-in 1: EtherCAT Bus Terminals
Slide-in 2: Variable Declaration
Practice slide-in 1: The first project
Automatic start of the controller
Establishing a remote connection
Own data types
Working with several tasks
Backup on the target system
Encrypt the project

TwinCAT 3 | Handling

23.05.2012

59

TwinCAT 3 | New Automation Technology

Automatic start of the controller


So that the controller starts
automatically and loads its project
when switching on, a few settings need
to be made.
The system must be parameterised in
such a way,
that the Windows login is
performed automatically,
that TwinCAT XAR starts
automatically and
that the generated boot project is
loaded.

Power ON

Windows start

Windows login

Starting of TwinCAT
XAR

Loading of the boot project

Starting of the PLC

TwinCAT 3 | Handling

23.05.2012

60

TwinCAT 3 | New Automation Technology

Windows login & start of TwinCAT XAR

2
1

TwinCAT 3 | Handling

23.05.2012

61

TwinCAT 3 | New Automation Technology

Loading of the boot project

3
Context Menu
3

TwinCAT 3 | Handling

23.05.2012

62

TwinCAT 3 | New Automation Technology

Overview of contents
Version differences

Visual Studio 2010


Visual Studio 2010 Shell

Integration of the TwinCAT System


Manager
System
PLC
Slide-in 1: EtherCAT Bus Terminals
Slide-in 2: Variable Declaration
Practice slide-in 1: The first project
Automatic start of the controller
Establishing a remote connection
Own data types
Working with several tasks
Backup on the target system
Encrypt the project

TwinCAT 3 | Handling

23.05.2012

63

TwinCAT 3 | New Automation Technology

Establishing a remote connection | Principles


As a rule, programming does not take place locally on the controller, but using a
remote programming device.
For the simple establishment of a remote connection to the automation system, the
following items must be observed:
Programming device and automation system must lie in the same network
class (observe subnet mask!).
No double AmsNetIds may occur in the connected network.
If necessary, the user name/password of the automation system must be
known.

TwinCAT 3 | Handling

23.05.2012

64

TwinCAT 3 | New Automation Technology

Establishing a remote connection | Example


Add a connection or select via
Choose target

Alternative: Drop-down menu


TwinCAT 3 | Handling

23.05.2012

65

TwinCAT 3 | New Automation Technology

Establishing a remote connection|Choose Target System (1)

Select from
the list or
search

TwinCAT 3 | Handling

23.05.2012

66

TwinCAT 3 | New Automation Technology

Establishing a remote connection | Add Route Dialog


If the DNS name or the IP is known,
this can be entered directly.
Otherwise there is a possibility to
search the network via Broadcast
Search.
After selection of a device from the list,
the route can be added:

TwinCAT 3 | Handling

23.05.2012

67

TwinCAT 3 | New Automation Technology

Establishing a remote connection|Choose Target System (2)

Select from
the list and
OK

TwinCAT 3 | Handling

23.05.2012

68

TwinCAT 3 | New Automation Technology

Overview of contents
Version differences

Visual Studio 2010


Visual Studio 2010 Shell

Integration of the TwinCAT System


Manager
System
PLC
Slide-in 1: EtherCAT Bus Terminals
Slide-in 2: Variable Declaration
Practice slide-in 1: The first project
Automatic start of the controller
Establishing a remote connection
Own data types
Working with several tasks
Backup on the target system
Encrypt the project

TwinCAT 3 | Handling

23.05.2012

69

TwinCAT 3 | New Automation Technology

Own data types


To create your own data types, rightclick on the PLC project:

The following are available:


Structure
Enum
Alias
Union
TwinCAT 3 | Handling

23.05.2012

70

TwinCAT 3 | New Automation Technology

Own data types | Structure

Declaration

Instance formation

Declaration
Call and
assignment
TwinCAT 3 | Handling

23.05.2012

71

TwinCAT 3 | New Automation Technology

Own data types | Enum

Declaration

Instance formation

Declaration
Call and
assignment
TwinCAT 3 | Handling

23.05.2012

72

TwinCAT 3 | New Automation Technology

Own data types | Alias

Declaration

Instance formation

Declaration

Call and
assignment

TwinCAT 3 | Handling

23.05.2012

73

TwinCAT 3 | New Automation Technology

Own data types | Union

Declaration

Instance formation

Declaration
Call and
assignment
TwinCAT 3 | Handling

23.05.2012

74

TwinCAT 3 | New Automation Technology

Own data types | Struct vs. Union


As in structures, elements of different types can be combined into a unit in a union.
Unlike structures, however, only one element of a union is available at any one time.

Explanation
1.In a structure,
structure the individual elements
of the structure are located one behind
the other in memory. The overall
memory requirement is thus
determined from the sum of the sizes
of the individual elements.
2.In a union the memory requirement is
determined from the largest element. In
the example shown above, therefore,
from the String variable.

TwinCAT 3 | Handling

23.05.2012

75

TwinCAT 3 | New Automation Technology

Overview of contents
Version differences

Visual Studio 2010


Visual Studio 2010 Shell

Integration of the TwinCAT System


Manager
System
PLC
Slide-in 1: EtherCAT Bus Terminals
Slide-in 2: Variable Declaration
Practice slide-in 1: The first project
Automatic start of the controller
Establishing a remote connection
Own data types
Working with several tasks
Backup on the target system
Encrypt the project

TwinCAT 3 | Handling

23.05.2012

76

TwinCAT 3 | New Automation Technology

Working with several tasks | Creation of the tasks


65,000 different tasks are available to the user in TwinCAT 3; these tasks can be individually
assigned to a core of the IPC.
If a further task is to be assigned to a special (program) block in an existing PLC project, then
this can be created by right-clicking on the project:

TwinCAT 3 | Handling

23.05.2012

77

TwinCAT 3 | New Automation Technology

Working with several tasks | Assigning the tasks to a block


After creation of the Referenced Task, this task is available
in the System Manager tree
By right-clicking on the new task inside the PLC project, it can
be assigned to a program block

1
4
TwinCAT 3 | Handling

23.05.2012

78

TwinCAT 3 | New Automation Technology

Working with several tasks | Core assignment


The project tasks can be assigned to the individual cores of a
multi-core CPU.

TwinCAT 3 | Handling

23.05.2012

79

TwinCAT 3 | New Automation Technology

Working with several tasks | Whats to consider?


When using several different task cycle time you have to have a look at the
resepective priority!
The task with the fastets cycle time gets the highest priority.

TwinCAT 3 | Handling

10.12.2012

80

TwinCAT 3 | New Automation Technology

Working with several tasks | Priority Management

TwinCAT 3 | Handling

10.12.2012

81

TwinCAT 3 | New Automation Technology

Working with several tasks | Multitasking


Preemptive multitasking in TwinCAT3 by using the example of an NC task with 1ms
(Priority 1) and a PLC task with 2ms (Priority 2)

Real time operation with software for PLC and NC on one PC


NC

PLC-Program

Win NT and HMIInterface

z.B.: 1 ms

2 ms

NC-Cycle (z.B. 1ms) NC-Cycle


PLC-Cycle (z. B. 2 ms)

3 ms

4 ms

NC-Cycle

2
5 ms

NC-Cycle

t
t

PCL-Cycle
TwinCAT 3 | Handling

10.12.2012

82

TwinCAT 3 | New Automation Technology

Working with several tasks | Choice of time base


The highest priority task and thus fastest are usually dictates the size of the time
slice or time base
Biggest value for time base:

1 ms

Smallest value for time base:

50s

Too low base period has a high copy expenses and thus may result in a higher
processor utilization as required for the application!
TwinCAT 3 | Handling

10.12.2012

83

TwinCAT 3 | New Automation Technology

Overview of contents
Version differences

Visual Studio 2010


Visual Studio 2010 Shell

Integration of the TwinCAT System


Manager
System
PLC
Slide-in 1: EtherCAT Bus Terminals
Slide-in 2: Variable Declaration
Practice slide-in 1: The first project
Automatic start of the controller
Establishing a remote connection
Own data types
Working with several tasks
Backup on the target system
Encrypt the project

TwinCAT 3 | Handling

23.05.2012

84

TwinCAT 3 | New Automation Technology

Backup on the target system | Download


A download of the TwinCAT configuration and the PLC or C program always takes
place automatically!
CurrentConfig.tszip is genereated on the target system.

The option can be disabled if required by "right-clicking the TwinCAT project".

TwinCAT 3 | Handling

10.12.2012

85

TwinCAT 3 | New Automation Technology

Backup on the target system | Upload


Reloading the project via the VS2010 environment :
FileOpen "Open project from Target system"

TwinCAT 3 | Handling

10.12.2012

86

TwinCAT 3 | New Automation Technology

Overview of contents
Version differences

Visual Studio 2010


Visual Studio 2010 Shell

Integration of the TwinCAT System


Manager
System
PLC
Slide-in 1: EtherCAT Bus Terminals
Slide-in 2: Variable Declaration
Practice slide-in 1: The first project
Automatic start of the controller
Establishing a remote connection
Own data types
Working with several tasks
Backup on the target system
Encrypt the project

TwinCAT 3 | Handling

23.05.2012

87

TwinCAT 3 | New Automation Technology

Encrypt project| Protection


TwinCAT 3 offers two different types of encryption
Change Protection: The project can be opened but not saved or modified
activated!
Read Protection: The project can not be opened without a password

The select "Protection" is also used for the project download!


TwinCAT 3 | Handling

10.12.2012

88

TwinCAT 3 | New Automation Technology

Handling

Training fr Umsteiger
Thank you very much
for your attention!

TR3020 | Training for new users | Overview

TwinCAT 3 New Automation Technology

Training fr Umsteiger

Identifier
Indentifier serves to assign individual names to variables, data types,
functions, etc.
The identifier starts with a letter or underscore
followed by numbers, letters and underscore
No distinction is made between upper and lower case
The following are not permitted
special characters (!, , , $, etc.)
spaces
consecutive underscores
umlauts

TwinCAT Training: Programmer

12.04.2013

Keywords
Keywords are identifiers specified by IEC61131-3. They are thus fixed
components of the syntax and therefore may not be used for other
purposes.
Examples
Standard operators AND, OR, NOT
Standard types BOOL, INT, REAL...
Types TYPE, STRUCT
Block types FUNCTION, FUNCTION_BLOCK, PROGRAM

TwinCAT Training: Programmer

12.04.2013

Keywords and comments


The comments are delimited by character strings with (* or *) at the beginning
and at the end. Comments may be placed wherever spaces are also permitted.
Exception: within string literals.
(*digitale Eingnge*)
bStart AT %IX0.0 :BOOL;(*Anlagenstart*)
(*analoge Eingnge*)
TemK1 AT %IW10 (*Byte 10-11*) :WORD;
Comments to the end of the line
bStart AT %IX0.0 :BOOL; // Anlagenstart

TwinCAT Training: Programmer

12.04.2013

Elementary data types


Type

Lower

Upper

BOOL

FALSE

TRUE

Size

Prefix
x
b

BYTE

8 BIT

by

Bitstring

WORD

16 BIT

Bitstring

DWORD

32 BIT

dw

Bitstring

TwinCAT Training: Programmer

12.04.2013

Elementary data types

Detail slides
Overflows
Example: EL3102
Example: KL2531
TwinCAT Training: Programmer

12.04.2013

Data types 1: Elementary data types


Type

Lower

Upper

Size

Prefix

TIME_OF_DAY

TOD#0:0:0

TOD#23:59:
59

32 Bit

tod

DATE

D#1970:01:01

D#2106 ???

32 Bit

date

DATE_AND_TIME

DT#1970:01:01:00:00:00

DT#2106
???

32 Bit

dt

TIME

T#0s

T#49d17h2m 32BIT
47s295ms

tim

Detail slides
DT example - reading the system time
DT example - working with standard operators

TwinCAT Training: Programmer

12.04.2013

Elementary data types


Type

Lower

Upper

Size

Prefix

REAL

4 Byte

LREAL

8 Byte

lr

TwinCAT Training: Programmer

12.04.2013

Data types: STRING


Type

Description

Example

Size

Prefix

STRING

String in ASCII
code. Standard
length 80
characters.
Maximum length
255. Strings are
zero-terminated

1234ABCDE

80 +1

ABCDE$R$L
ABCDE$0D$0A

String length specifications


Example
declaration

Assignment

Result SIZEOF

Result LEN

sVar : STRING;

sVar:=ABC;

81

sVar1 :STRING(1);

sVar := X;

sVar: STRING(255);

sVar:=ABC;

256

TwinCAT Training: Programmer

12.04.2013

Data types: STRING


Constants
$<2 Hex values>

ASCII Code

$0D

CR

$R

$r

CR

$L

$l

Line Feed

$N

$n

New Line

$T

$t

Tab

Detail slides
Example: FIND
Example: string functions LEN, REPLACE
String conversion with Union

TwinCAT Training: Programmer

12.04.2013

10

Data types: WSTRING


Type

Description

Example

Description

Pre
fix

WSTRING

String in Unicode
format

Level 0,Block
0x0400-0x4FFF
Cyrillic

ws

Training, seminar

Level 0
Block 0x00000x007F
Basic Latin

TwinCAT Training: Programmer

12.04.2013

11

Data types: Examples of literals


Variable Type

Examples

BOOL

TRUE

2#1

16#1

FALSE

2#0

16#0

WORD,
DWORD

2#1010111111111110

16#AFFE

45054

INT

2#1000000000000001

16#8001

-32768

TIME

t#1h

t#60m

t#3600000ms

t#0.5d

t#12h

t#43200000ms

day

hours

min

sec

ms

ms

REAL

t#30m18s90ms

t#0.505025h

0.3333

3.333e-1

t#1818090ms

TwinCAT Training: Programmer

12.04.2013

12

Data types 1: Variable declaration el. data types


A variable possesses a name behind which a value (number, string,
date, etc.) is concealed. The variable name is a type of description of
the path to the declared data. Variables are characterised above all by
the fact that their contents can be changed at runtime.

Identifier

Data type

Initial value

bStellerUntenLinks:BOOL:=TRUE;

The physical-logical storage


location of this variable is
unknown to the user
(unlocated)

The degrees of freedom and restrictions in the


assignment of the identifiers can be found on
the slide entitled Identifiers and Prefixes
TwinCAT Training: Programmer

12.04.2013

13

Data types 1: Located variables


It is possible when declaring a variable to link the name with an
address that must be explicitly specified. For the allocation of inputs
and outputs of the hardware the incomplete location is to be carried
out with I* and Q*
Identifier

AT

%I

Data type;

%Q*

TwinCAT Training: Programmer

12.04.2013

14

Data types 1: Located variables


Completely located variables.
Identifier

AT

%I

%Q

%M

Byte

Bit

Type

Byte

These variables possess a clear address


(located)
In TwinCAT 3 incompletely located variables can be used for inputs and
outputs
Applications for %M variables can be solved simply with Unions and
direct masking

Detail slides
Detail - Replace %MB by UNION
TwinCAT Training: Programmer

12.04.2013

15

Data types 1: Address division


Examples:
IX10.7

IX10.6

IX10.5

IX10.4

IX10.3

IX10.2

IX10.1

IX10.0

Din0 AT%IX10.0 : BOOL;

IB10

IB1

Ain AT%IB0 : INT;


equivalent

IB0
IW0

Ain AT%IW0 : INT;


IX22.7

IX22.6

IX22.5

IB23

IX22.4

IX22.3

IB22

IX22.2

IX22.1

IB21

IW22

IB20
IW20

ID20

IX22.0

BitVar AT%IX22.1 : BOOL;


Posi AT%IB20 : UDINT;
equivalent

Posi AT%ID20 : UDINT;

TwinCAT Training: Programmer

12.04.2013

16

Data types 1: Variable classes, scope


Local variables are restricted
to the block in which they
were declared.
Keywords
VAR ..
END_VAR
VAR_INPUT ..
END_VAR
VAR_IN_OUT ..

Global variables are


known in each block
within a project.
Keywords
VAR_GLOBAL ..
END_VAR
VAR_CONFIG ..
END_VAR

END_VAR
VAR_OUTPUT ..
END_VAR

TwinCAT Training: Programmer

12.04.2013

17

Data types 1: I/O directly in an FB instance


In an FB the inputs and outputs to the periphery are to be created
directly as local variables

Implementation
TwinCAT Training: Programmer

12.04.2013

18

Data types 1: Access via the located variables


The variable locVar locally declared in Program B can be directly
accessed from Program A via address %MB2.

Project machine
PROGRAM A

PROGRAM B

VAR

VAR
locVar AT%MB2:WORD;
END_VAR

END_VAR

LD %MB2

TwinCAT Training: Programmer

12.04.2013

19

Data types 1: Overlaps in the scope


Project machine
VAR_GLOBAL
Var1:WORD;
END_VAR
PROGRAM A
VAR
Var1 :WORD;
END_VAR

Example
name:
Gvl1

As shown on the left, there is


an overlap in the scope.
In this case the locally
declared variable Var1 is
loaded into the accumulator.
The global variable can also
be accessed with
Namespaces.

LD Var1
LD Gvl1.Var1

TwinCAT Training: Programmer

12.04.2013

20

Data types 1: PERSISTENT attribute


Special properties of variables can be defined using attributes.
Example:
The variable(s) are saved when the PLC is shut down and loaded back on
restarting.

TwinCAT Training: Programmer

12.04.2013

21

Data types 1: Initialisation and CONSTANT


Initial values, the variables are to be preset with a certain value when
starting/resetting the PLC.
VAR
AccelerationTime : TIME := T#3s200ms;
END_VAR
Read-only:
VAR_GLOBAL CONSTANT
pi:REAL:=3.141592654;

Global

END_VAR
VAR CONSTANT
pi:REAL:=3.141592654;

Also locally
possible

END_VAR
TwinCAT Training: Programmer

12.04.2013

22

Data Types 2: Derived data types


The user can create his own data types on the basis of the elementary
data types or data types that have already been created. The newlycreated data types are visible in the entire project.
The declaration starts with TYPE and ends with END_TYPE.

Parent type

Name

Data type

New value

Derivation

Name

Data type

Initial value

Area

Inherit
ance

Initial value

Area

TwinCAT Training: Programmer

12.04.2013

23

Data Types 2: References (alias types)


The purpose of the selfdefined data type Reference is
to generate an alternative
name for a variable, constant
or function block.
Create your references as
objects in the object organiser
on the Data Types tab.
They start with the keyword
TYPE and end with
END_TYPE.

Syntax:
TYPE
<Bezeichner>:<Zuweisungsausdruck>;
END_TYPE
Type

Declaration

TwinCAT Training: Programmer

12.04.2013

24

Data Types 2: References (alias types)


Example: A global string variable is transferred to various blocks. If
changes are made to the Global Variables, the declarations must also
be changed in every block

TwinCAT Training: Programmer

12.04.2013

25

Data Types 2: References (alias types)


If a type has been created for the string, further changes are made
only to the type

TwinCAT Training: Programmer

12.04.2013

26

Data Types 2: References (alias types)


If a type has been created for the string, further changes are made
only to the type

TwinCAT Training: Programmer

12.04.2013

27

Data Types 2: References (alias types)


If a type has been created for the string, further changes are made
only to the type

TwinCAT Training: Programmer

12.04.2013

28

Data Types 2: Enumerated type (Enum)


An enumerated type is a self-defined data type consisting of a number
of string constants. These constants are called enumeration values.
The enumeration values are always known in the entire project. It is
best to create your enumerated types as objects in the object
organiser on the Data Types tab. They start with the keyword TYPE
and end with END_TYPE.
Syntax:
TYPE <Bezeichner>:(<Enum_0> ,<Enum_1>, ...,<Enum_n>);
END_TYPE
Example:
TYPE Woche:(Mo, Di, Mi, Dn, Fr, Sa, So:=10);(*Mo = 0 Di = 1..
.. Sa = 6 So = 10*)
END_TYPE
TYPE Richtung:(Up, Dn);(*Up = 0 Dn = 1*)
END_TYPE

The same enumeration value can be used twice via Namespace.


Example: Woche.Dn Richtung.Dn
TwinCAT Training: Programmer

12.04.2013

29

Data Types 2: Enumerated type (Enum)


Example: signal light without Enum:
Declaration

Use

Online

TwinCAT Training: Programmer

12.04.2013

30

Data Types 2: Enumerated type (Enum)


Example: signal light with Enum:
Type

Use

Declaration

Online

TwinCAT Training: Programmer

12.04.2013

31

Data Types 2: Structure declaration


Example: KL5101 Encoder Terminal Structures are self-defined data types.
They are an important aid to better
administration of the process data. In
addition, the structures are suitable
for encapsulated data transfer to
function blocks. Structures can be
used like individual element variables.

TwinCAT Training: Programmer

12.04.2013

32

Data Types 2: Structures instancing

ST_KL5101In_1 AT%I* : KL5101_IN


ST_KL5101Out_1 AT%Q* : KL5101_OUT

TwinCAT Training: Programmer

12.04.2013

33

Data Types 2: Arrays


Arrays represent lists or data fields. All elements in the arrays are of the
same type. Naturally arrays can also consist of own data types (structures).
One, two and three-dimensional arrays are possible.
VAR
Feld_1 :ARRAY[0..9] OF BYTE;
Feld_2 :ARRAY[0..9, 0..1] OF UINT;
Feld_3 :ARRAY[0..9, 0..1,0..1] OF DINT;
END_VAR

1-dimensional
2-dimensional
3-dimensional

There is a possibility to place a data field in a directly addressed memory


location
VAR
Feld_1 AT%MB100:ARRAY[1..10] OF BYTE;
END_VAR
Access to the sub-elements of a data field
Feld_1[2] := 120; (* Expliziter Zugriff*)
Feld_2[i,j] := EXPT(i,j); (*Indizierter Zugriff*)

TwinCAT Training: Programmer

12.04.2013

34

Data Types 2: Limit transgressions


A dangerous state can arise if an area outside the data field is
accessed in the PLC program.
VAR
Feld_1 :ARRAY[1..10] OF BYTE;
Feld_2 :ARRAY[1..10, 2..5] OF UINT;
END_VAR

i:= 9
Feld_1[i+2] := 120;

Feld_1[9];

Feld_2[1,2];

120

TwinCAT Training: Programmer

12.04.2013

35

Data Types 2: CheckBounds (FUN)


The access can be monitored by
the PLC at PLC runtime
This function enables a limit
transgression occurring in the
program to be recognised and
rectified.

FUNCTION CheckBounds :DINT


VAR_INPUT
I,L,U : DINT;
END_VAR
IF I< L THEN
Error case

CheckBounds := L;

ELSIF I > U THEN


Error case
i
Min
Max

Limited
value

CheckBounds := U;

ELSE
OK case

CheckBounds := I;

END_IF

TwinCAT Training: Programmer

12.04.2013

36

Data Types 2: Adding CheckBounds 1 (FUN)


Adding Checkbounds:

TwinCAT Training: Programmer

12.04.2013

37

Data Types 2: Adding CheckBounds 2 (FUN)

TwinCAT Training: Programmer

12.04.2013

38

Data Types 2: Method of operation of CheckBounds (FUN)


Example: user error
source code

Checkbounds is compiled-in
in XAR

10

Do not write,
it is called
automatically
(not visible in
the code)

10

9
Can be checked with call build:
TwinCAT Training: Programmer

12.04.2013

39

Note about further checker functions


The following further checker functions are possible from
TwinCAT 2.8:

Check for division by 0


CheckDivByte
CheckDivWord
CheckDivDWord
CheckDivReal

Check value ranges


CheckRangeSigned
CheckRangeUnsigned
(see appendix)

TwinCAT Training: Programmer

12.04.2013

40

Data Types 2: Combination: structures and arrays


An array can consist of structures:
Structure:
TYPE DrillPos :
STRUCT
XPos:
FeedrateX:
AccelerationX:
DeccelerationX:
JerkX:
YPos:
FeedrateY:
AcceleartionY:
DeccelerationY:
JerkY:
FeedDrill:
Kuehlen:
END_STRUCT
END_TYPE

LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
BOOL; (*Pumpe ?*)

Declaration of the array:

Positions :ARRAY[0..100] OF DrillPos;


TwinCAT Training: Programmer

12.04.2013

41

Data Types 2: Combination: structures and arrays


Access to Drillpos 55:
Access:
MoveXAx (*FB Instanz*)
(
Execute:=

TRUE,

Position:=

Positions[55].XPos ,

Velocity:=

Positions[55].FeedrateX

Acceleration:=

Positions[55].AccelerationX,

Deceleration:=

Positions[55].DeccelerationX,

Jerk:=

Positions[55].JerkX,

Direction:=

.........,

Axis:=

.............,

);
TwinCAT Training: Programmer

12.04.2013

42

Block types
In IEC61131-3 there are three types of block covered by the generic
term POU (PROGRAM ORGANISATION UNIT):
Program
Function Block
Function

TwinCAT Training: Programmer

12.04.2013

43

Block types: program PRG


Program PRG
Called by a task (one program can call another)
Calls: FBs, functions, (programs)
Local variable: static, i.e. the local data are available again in the next cycle.
Inputs: usually 0, but VAR_INPUT possible
Outputs: usually 0, but VAR_OUTPUT possible
Transfer by reference VAR_IN_OUT likewise possible
Monitoring: Local data are immediately visible in the online mode of the PLC
control
Use: Main programs, Main, Manual, Automatic, etc.

TwinCAT Training: Programmer

12.04.2013

44

Block types: function block FB


Function block FB
Called by programs or other FBs
Calls: FBs, functions,
Local variable: static, i.e. the local data are available again in the next cycle.
Can be instanced in case of multiple calls (multipliable). Each FB call can have
its own local data.
Inputs: 0,1,2,3VAR_INPUT
Outputs 0,1,2,3.. VAR_OUTPUT
Transfer by reference 0,1,2,3.. VAR_IN_OUT
Monitoring: In the online mode of the PLC control the instance of the call
concerned must first be specified. The local data are then visible for each call.
Use: multiple-used modules, each of which requires its own data area. Step
chains...

TwinCAT Training: Programmer

12.04.2013

45

Block types: Function: FC


Function: FC
Called by programs, function blocks and other functions
Calls: Functions
Local variable: temporary, i.e. the local data are available only for the
processing time of the function. Afterwards this data area is used by
other functions.
Inputs:

1,2,3........ VAR_INPUT

Outputs:
precisely 1!, but structure variable possible. The name of
the output is at the same time the name of the function.
Transfer by reference

1,2,3........ VAR_IN_OUT ,

Monitoring: In the online mode of the PLC control only ??? are visible
for the local variables, since this data area is used by all functions in the
cycle and monitoring (debug) takes place only at the cycle limits.
Remedy: program development with breakpoints
Use: algorithms where the result is available after a run. Scaling,
comparison, etc.

TwinCAT Training: Programmer

12.04.2013

46

ST Structured Text: Operators


Operation
put in parentheses
Function call
Exponentiation
Negate
Build. complements
Multiply
Divide
Modulo
Add
Subtract
Compare
Equal to
Not Equal to
BOOL AND
BOOL XOR
BOOL OR

Symbol
Binding strength
(expression)
Strongest binding
Function name (parameter list)
EXPT
NOT
*
Same binding strength,
processing from left to right
/
(10/2*5 = 25 )
MOD
+
Same binding strength
<,>,<=,>=
=
<>
AND
XOR
Weakest binding
OR
TwinCAT Training: Programmer

12.04.2013

47

ST Structured Text: Instructions


Instruction

Example

Assignment:=

PosWert := 10;

Calling a Function Block

Ton1(IN:=Start, PT:=T2s); Output:= Ton1.Q;

RETURN

RETURN;

IF

more precise explanations and examples on the


following pages

CASE
FOR
WHILE
REPEAT
EXIT
Empty instruction

TwinCAT Training: Programmer

12.04.2013

48

ST: IF instruction
Is needed to branch in a program, depending on conditions. With the
IF instructions its not possible to jump back in the PLC cycle.
GOTO is also not available

Keywords:
IF

THEN

ELSIF
ELSE
END_IF

TwinCAT Training: Programmer

12.04.2013

49

ST: IF instruction

IF Condition THEN
Instruction block;
END_IF

No
Condition
Yes

Instruction block

TwinCAT Training: Programmer

12.04.2013

50

ST: IF instruction

IF a>b THEN
Instruction block A;
ELSE
Instruction block B;
END_IF

Condition

No

Yes

Instruction block A

Instruction block B

TwinCAT Training: Programmer

12.04.2013

51

ST: IF instruction
IF Condition1 THEN
Instruction block A;
ELSE
IF Condition2 THEN
Instruction block B;
Condition 1
ELSE
No
Yes
IF Condition3 THEN
Condition 2
Instruction block C;
ELSE
Yes
Instruction block D;
END_IF
END_IF
END_IF
Instruction
Instruction
block A

block B

No
Condition 3
No
Yes
Instruction
block C

Instruction
block D

TwinCAT Training: Programmer

12.04.2013

52

ST: IF instruction

IF Condition1 THEN
Instruction block A;
ELSIF Condition2 THEN
Instruction block B;
ELSIF Condition3 THEN
Instruction block C;
ELSE
Instruction block D;
END_IF

Condition 1
No
Yes
Condition 2
No
Yes
Condition 3
No
Yes
Instruction
block A

Instruction
block B

Instruction
block C

Instruction
block D

TwinCAT Training: Programmer

12.04.2013

53

ST: IF instruction
What can the BOOLEAN EXPRESSION be?
Conditions:
BOOLEAN variable
Comparison
Function calls

Querying of FB instances
NO FB call!

IF bVar THEN
.
IF a>b THEN
.
IF LEFT(STR:= strVar, SIZE:=7) =
'TwinCAT' THEN
.
IF Ton1.Q THEN
.
IF Ton1(IN:=bVar, PT:=T#1s ) THEN

TwinCAT Training: Programmer

12.04.2013

54

ST CASE Instruction
CASE Selection criterion OF
1:

Selection criterion = 2
or 4 or 6

Instruction 1

2, 4, 6: Instruction 2
7..10: Instruction 3

Selection
criterion = 1

Selection criterion = 7
or 8 or 9 or 10?

No

Yes

..

No

ELSE

Yes

Default
instructions

No
Yes

END_CASE;
Two identical values
may not be available
for selection in the list.

Instruction 1

Instruction 2

Instruction 3

Default
instructions

TwinCAT Training: Programmer

12.04.2013

55

ST: CASE instruction: possibility for a step chain /


state machine
Instructions for the step
(Actions)

CASE State OF
0:

Q0:=TRUE;
IF Transition THEN state := 1; END_IF

1:

Q1:=TRUE;
IF Transition THEN state := 2; END_IF

2:

Step-further condition
(Transition)

Q2:=TRUE;
IF Transition THEN state := 3; END_IF

3:

Q3:=TRUE;
IF Transition THEN state := 0; END_IF

END_CASE

TwinCAT Training: Programmer

12.04.2013

56

ST: CASE instruction Integer Selector Value


with constants
CASE State OF
0:

Instructions;(*State=0*)
IF THEN

Instructions
if state = 0

1:

Instructions;(*State=1*)

Instructions
if state = 1

2:

Instructions;(*State=2*)

Instructions
if state = 2

3:

Instructions;(*State=3*)

Instructions
if state = 3

END_CASE

TwinCAT Training: Programmer

12.04.2013

57

ST: CASE instruction Integer Selector Value


with Enum types

Enum-Typ:
TYPE Schritte :
(INIT:=0, START, AUTOMATIK, ENDE);
END_TYPE

CASE State OF
INIT:

Instructions;(*State=0*)

START:

Instructions;(*State=1*)

AUTOMATIK:

Instructions;(*State=2*)

ENDE:

Instructions;(*State=3*)

END_CASE

TwinCAT Training: Programmer

12.04.2013

58

ST: CASE instruction: suggestion for a step chain /


state machine
TYPE Schritte :
( INIT:=0, START, AUTOMATIK, ENDE);
END_TYPE

Instructions for the step


(Actions)

CASE State OF
INIT:

Q0:=TRUE;
IF Transition THEN state := START; END_IF

START:

Step-further condition
(Transition)

Q1:=TRUE;
IF Transition THEN state := AUTOMATIK; END_IF

AUTOMATIK: Q2:=TRUE; Step


IF Transition THEN state := ENDE; END_IF
ENDE:

Q3:=TRUE;
IF Transition THEN state := INIT; END_IF

END_CASE
TwinCAT Training: Programmer

12.04.2013

59

ST: CASE instruction Integer Selector Value


with constants
CASE State OF

VAR CONSTANT
Step1 : INT:=

0;

Step1:

Instructions;(*State=0*)

Step2 : INT:=

1;

Step2:

Instructions;(*State=1*)

Step3 : INT:=

2;

Step3..Step4:

Instructions;(*State=2 oder 3*)

Step4 : INT:=

3;

END_CASE

END_VAR
VAR
State:INT;
END_VAR

TwinCAT Training: Programmer

12.04.2013

60

ST: Repeat instructions


The process sequence often requires the multiple processing of
precisely the same program sequences, where their number is known
only at runtime.
Disadvantage of loops:
In the case of wrong programming, an infinite number of repetitions
takes place.
If a continuous loop is executed, this does not impair the start of the
time slices (real-time). Tasks with a higher priority will still be executed
on time. Tasks with a lower priority will no longer be executed.
Forced switchover
to Win NT

1
e.g.: 1ms

2
2ms

3
3ms

Begin of a new
time slice

4
4ms

1
5ms

TwinCAT Training: Programmer

12.04.2013

61

ST: Loops (overview)


All loops can be terminated with the help of the EXIT instruction,
regardless of the abort condition.

Expression

Processing

n cycle fix

FOR

SINT/INT/DINT

Instructions
Yes
follow condition

WHILE

BOOL

Instructions
No
follow condition

REPEAT

BOOL

Condition
follows
instructions

No

TwinCAT Training: Programmer

12.04.2013

62

ST: FOR loop


At the beginning of the loop the
Cycle n
control variable i is set to the
starting value (see example).
The control variable is
decremented or incremented in
each loop, depending on the step
size (value after the keyword BY).
If i exceeds the end value
(after TO), the loop is no longer
processed.
FOR i:=1 TO 12 BY 2 DO

Start i:=StartValue

Yes

i
>EndValue
No
Instruction block

i: = i + step size

Feld[i]:=i*2;(*Anweisung*)
END_FOR
Cycle n
TwinCAT Training: Programmer

12.04.2013

63

ST: WHILE loop


The instruction block of a WHILE loop
is executed continuously until the
Boolean expression returns TRUE.
The abort condition can contain
variables that can be changed in the
instruction block.
If the Boolean expression is FALSE at
the beginning, then the instruction
block of the WHILE loop is not
processed.
i:=0;
WHILE i<100 DO
Feld[i]:=i*2;(*Anweisung*)
i:=i+1;
END_WHILE

Cycle n

Yes

Boolean
expression

No

Instruction block
i: = i + step size

Cycle n
TwinCAT Training: Programmer

12.04.2013

64

ST: REPEAT loop


Cycle n

The instruction block of a REPEAT


loop is executed as long as the
Boolean expression is satisfied.
The instruction block is processed at
least once.

Instruction block
i:= i + step size

i:=0;
REPEAT
Feld[i]:=i*2;(*Anweisung*)
i:=i+1;
UNTIL i>100

No

Boolean
expression
Yes

END_REPEAT
Cycle n
TwinCAT Training: Programmer

12.04.2013

65

ST: FB calls in ST
VAR
TON1:TON;
END_VAR
TON1 (IN:= NOT TON1.Q , PT:=T#1s );
Q0:= TON1.Q;

TON1(IN:= NOT TON1.Q, PT:=T#1s , Q=>Q0 );

TwinCAT Training: Programmer

12.04.2013

66

ST: FB calls in ST (alternative)


VAR
TON1:TON;
END_VAR

TON1.IN:= NOT TON1.Q;


TON1. PT:=T#1s;
TON1();
Q0:= TON1.Q;

TwinCAT Training: Programmer

12.04.2013

67

ST: FC calls in ST
Result:=Scale (x:=Eingang, xug:=0.0, xog:=32767.0, yug:=0.0,yog:=100.0);
(* Gleichwertig:*)
Result:=Scale (Eingang, 0.0, 32767.0, 0.0, 100.0);
(* Gleichwertig:*)
Result:=Scale (

xog:=

x:=

Eingang,

xug:=

0.0,

32767.0,
yug:=

0.0,

yog:=

100.0

);
In case of functions, all inputs must be occupied
TwinCAT Training: Programmer

12.04.2013

68

ST: FC calls in ST
Result := Scale (x:=Eingang, xug:=0.0, xog:=32767.0, yug:=0.0,yog:=100.0);

Result

CALL

Input parameters

(* Gleichwertig:*)
Result:=Scale

(
x:=

Eingang,

xug:=

0.0,

xog:=

32767.0,

yug:=

0.0,

yog:=

100.0

);

TwinCAT Training: Programmer

12.04.2013

69

TwinCAT 3 | New Automation Technology

Advanced IEC features | Keywords


New keywords:
METHOD : Action on FB with own variables
PROPERTY: POE pair for Set/Get of attribute
THIS : in Method/Property for the current FB instance
SUPER : in Method for access to the basic class instance
EXTENDS : Inheritance between FBs
INTERFACE : defines abstract object type (FB without implementation)
IMPLEMENTS in the FB: Instances can be called via the named interface

Call syntax for methods:


Object.Methodname()

Special methods:
FB_Init, FB_Exit, FB_Reinit
TwinCAT 3 | Training | Object-orientated
programming in IEC

70

03.05.2012

Short information: OOP with example

TwinCAT Training: Programmer

12.04.2013

71

TwinCAT 3 | New Automation Technology

Advanced IEC features | Keywords


New keywords:
METHOD : Action on FB with own variables
PROPERTY: POE pair for Set/Get of attribute
THIS : in Method/Property for the current FB instance
SUPER : in Method for access to the basic class instance
EXTENDS : Inheritance between FBs
INTERFACE : defines abstract object type (FB without implementation)
IMPLEMENTS in the FB: Instances can be called via the named interface

Call syntax for methods:


Object.Methodname()

Special methods:
FB_Init, FB_Exit, FB_Reinit
TwinCAT Training: Programmer

12.04.2013

72

TwinCAT 3 | New Automation Technology

Advanced IEC features | Application


Object-orientated extensions of IEC 61131-3, 3rd edition:
the concept of the functional blocks has been extended by
Classes
Interfaces
Methods
Inheritance
Attributes
Keywords such as THIS, SUPER

Use of the extensions


Possible in all IEC languages
Independent of the hardware employed
Not absolutely necessary
TwinCAT Training: Programmer

12.04.2013

73

TwinCAT 3 | New Automation Technology

Advanced IEC features | SUPER and THIS


SUPER is available in every FB and represents a pointer to the basic FB instance.
THIS uses the local instance (e.g. a method).

Complete program: Sample06

TwinCAT Training: Programmer

12.04.2013

74

TwinCAT 3 | New Automation Technology

Advanced IEC features | SUPER and THIS


SUPER is available in every FB and represents a pointer to the basic FB instance.
THIS uses the local instance (e.g. a method).

TwinCAT Training: Programmer

12.04.2013

75

TwinCAT 3 | New Automation Technology

Advanced IEC features | SUPER and THIS


PUBLIC all methods can be accessed
PRIVATE can be used only in the FB. Not from outside as FB.Method()
PROTECTED cannot be overwritten in the derived FB
INTERNAL Methods Properties in a library cannot be overwritten

03.05.2012

TwinCAT Training: Programmer

12.04.2013

76

Example task
Example: a clock generator FB is to be created
that should be able to do the following:
generate a flashing cycle
generate a PWM signal (e.g. heating)
Parameter
fixed flashing time for flashing cycle
clock output for flashing signal
MaxCycles defines number of PLC cycles 100% duty cycle for PWM
generator
DCPercent; duty cycle in %
Enable: BOOL, enable for PWM signal
Vendor, name of the manufacturer as a string

TwinCAT Training: Programmer

12.04.2013

77

Standard procedure
All parameters are transferred with VAR_INPUT VAR_OUTPUT
The sub-functions are programmed in the FB and run through with the complete FB

to flashing
cycle
to PWM
generator

to flashing
cycle

to PWM
generator

TwinCAT Training: Programmer

12.04.2013

78

Standard procedure
This block is to be extended later
clock ratio of the flashing cycle is to be modified
the PWM generator is given a target profile generator (e.g. temperature profile)

Co
py
ex and
ten
d

TwinCAT Training: Programmer

12.04.2013

79

Alternative
With the new options
Methods
Features
Inheritance
Overwrite

TwinCAT Training: Programmer

12.04.2013

80

Example
A clock generator FB is to be created
Methods:
m_ClockGenerator generates the flashing cycle
M_Pwm generates a PWM signal (e.g. heating)
Features
p_CycleTime specifies flashing time for flashing cycle
p_MaxCycles defines number of PLC cycles 100% duty cycle
for PWM generator
p_Vendor
queries a string

TwinCAT Training: Programmer

12.04.2013

81

Example

FB_ClockGenerator
m_ClockGenerator()
m_Pwm()
p_Vendor
p_CycleTime

TwinCAT Training: Programmer

12.04.2013

82

The basic clock generator block is to be further developed. Name


FB_ClockGenerator_EX. All methods and properties are initially to be adopted from
the basic block.
Modifications:
the ClockGenerator method is to be given a different on/off ratio
the Vendor property is to be overwritten. (Different text)
A further method is to be created in m_PwmProfile. This method generates a
certain profile for the duty cycle (ramp) of the pwm generator (example:
temperature profile). This value is to go onto the pwm generator of the basic
class.

For execution, see training examples

TwinCAT Training: Programmer

12.04.2013

83

Example
FB_ClockGenerator
m_ClockGenerator()
m_PwmProfile()
p_Vendor
p_CycleTime

FB_ClockGeneratorEX
m_ClockGenerator() overwrite
m_PwmProfile() (new)
p_Vendor (overwrite)

TwinCAT Training: Programmer

12.04.2013

84

Extension
Block
see training examples

TwinCAT Training: Programmer

12.04.2013

85

Appendix: Standard IEC operators and FBs

The function blocks and functions are made available by integrating the
Standard.LIB. This is automatically integrated into the PLC project when
the project is created.
Standard blocks
Function Blocks
Timer

Functions
String Functions

Counter
Memory
Trigger

TwinCAT Training: Programmer

12.04.2013

86

Appendix: Logical operators

FBD /CFC

ST

Comments
BOOL
AND

WORD
AND

DWORD
AND

TwinCAT Training: Programmer

12.04.2013

87

Appendix: Numerical operators


FBD /CFC

ST

Comments
Arithmetic Operators
Overloading possible,
beware of overflow with
integers.

- * /

Determines integral
remainder of a division
(in this case 4)

TwinCAT Training: Programmer

12.04.2013

88

Appendix: Selection operators, SEL


Operator

Comments

FBD /CFC

Selection inputs can be


overloaded
SEL

ST
StrVarMode := SEL(Mode1, , Mode1Selected );

Example:
If Mode1 = TRUE, StrVarmode
contains Mode1Selected,
otherwise an empty string

TwinCAT Training: Programmer

12.04.2013

89

Appendix: Selection operators, MUX

FBD /CFC

Selection with
integer variable,
inputs can be
overloaded

ST:
Online:

TwinCAT Training: Programmer

12.04.2013

90

Appendix: Conversions
Operator

ST

Comments
Time values are resolved
in ms rt1:REAL
iT1:INT

bVar1:BOOL
Rounding up takes place:
0.4 output goes FALSE
>=0.5 output goes TRUE

TwinCAT Training: Programmer

12.04.2013

91

Appendix: Conversions
FBD /CFC

ST

Comments
Result 20000.0
Implicit conversion also
possible
Conversion to INT with
rounding up/down
Conversion to INT without
rounding up/down
Beware of overflows
(Result is negative)

TwinCAT Training: Programmer

12.04.2013

92

Appendix: Edge blocks R_TRIG F_TRIG


FBD /CFC

CLK
R_TRIG
Q
CLK
F_TRIG
Q

ST

CLK

BOOL

Trigger input

R_TRIG: Rising Edge

BOOL

Signal output (for 1 PLC cycle on)

F_TRIG: Falling Edge

TwinCAT Training: Programmer

12.04.2013

93

Appendix: Memory modules SR RS


FBD /CFC

SET1

SR

RESET1
Q1

SET1

RS

ST

RESET1
Q1

SET1

BOOL

Set

SR: priority is set

RESET1 BOOL

Reset

RS: priority is reset

Q1

Output

BOOL

TwinCAT Training: Programmer

12.04.2013

94

Appendix: Switch-on delay TON


FBD /CFC

IN
Q
ET

ST

IN

BOOL Start input

PT

TIME

BOOL Output

ET

TIME

Preset Time, delay time

Starts with edge, output is


available after delay and

Elapsed Time, current time value


TwinCAT Training: Programmer

12.04.2013

95

Appendix: Switch-off delay TOF


FBD /CFC

IN

PT

ST

IN

BOOL Start input

PT

TIME

BOOL Output

ET

TIME

Preset Time, extension

ET

Starts with falling edge on


IN, new edge extends signal

Elapsed Time, current time value


TwinCAT Training: Programmer

12.04.2013

96

Appendix: Pulse timer TP


FBD /CFC

IN
Q

ST

IN

BOOL Start input

PT

TIME

BOOL Output

ET

TIME

Preset Time, pulse time

ET

Starts with edge, restart is


not accepted

Elapsed Time, current time value


TwinCAT Training: Programmer

12.04.2013

97

Appendix: UP counter CTU


FBD /CFC
ST

CU

BOOL

Count up, count input

RESET BOOL

Counter reset

PV

UINT

Preset Value

BOOL

Counter value has reached PV

CV

WORD

Current counter value

Counts with edge on


CU, output is set when
the counter value has
reached the value of
PV.

TwinCAT Training: Programmer

12.04.2013

98

Appendix: DOWN counter CTD


FBD /CFC
ST

CD

BOOL

Count down, count input

LOAD sets counter,

LOAD

BOOL

Load value of PV to counter

PV

UINT

Preset Value

BOOL

Counter value has reached 0

Counts downwards with


edge on CU, output is set
when the counter value
has reached the value 0.

CV

UINT

Current counter value


TwinCAT Training: Programmer

12.04.2013

99

Appendix: UP/DOWN counter CTUD


FBD /CFC

LOAD
CD
CU
RESET
CV

ST

CV=PV

QD
QU

CU

BOOL

Count UP, count input +

CV

UINT

Current counter value

CD

BOOL

Count DOWN, count input -

Counts with edge on CD and CU,

RESET

BOOL

Reset

Negative count values are not possible

LOAD

BOOL

Load value of PV to counter

PV

UINT

Preset Value

QU

BOOL

Counter value has reached PV

QD

BOOL

Counter value has reached 0


TwinCAT Training: Programmer

12.04.2013

100

Appendix: String function CONCACT


FBD

ResultOnline

ST

STR1

STRING

First string

STR2

STRING

String that is appended


to the first string

TwinCAT Training: Programmer

12.04.2013

101

Appendix: String function FIND


FBD

ResultOnline

ST

STR1

STRING

String from which characters


are to be deleted

STR2

STRING

String to be found

TwinCAT Training: Programmer

12.04.2013

102

Detail : Overflows
Beware of overflows with numerical operations
0000h
INT 0

FFFFh
INT -1

8000h

7FFFh

INT -32768

INT 32767

PLC memory
INT value
TwinCAT Training: Programmer

12.04.2013

103

Data types: Example: EL3102


EL3102
2-channel analog input
terminals -10+10 V,
differential input, 16 bit

Input signal = Value


EL310x
10 V
5V
0V
-5 V
-10 V

Value
Decimal
32767
16383
0
-16383
-32768

Hexadecimal
0x7FFF
0x3FFF
0x0000
0xC001
0x8000

Status word from (EL3102-0000-0016) with older models only SW.0 - SW.7 1 byte
Bit

SW.15

SW.14

Name

TxPDO
Toggle

Bit
Name

SW.13

SW.12

SW.11

SW.10

SW.9

SW.8

TxPDO State Sync error

SW.7

SW.6

SW.5

SW.4

SW.3

SW.2

SW.1

SW.0

ERROR

Limit 2

Overrange

Underrange

Limit 1

With older
models

TwinCAT Training: Programmer

12.04.2013

104

Data types: Example: KL2531


KL2531

Velocity
Bit

15

14

Cont. VZ

13

12

11

10

Velocity value

Controlbyte (Ctrl)
Bit
Name

CB.7

CB.6

RegAccess Reset

CB.5

CB.4

CB.3

CB.2

CB.1

CB.0

AutoStop

AutoStart

Reduced
Current

Start

PLC-Stop

Enable

CW.13

CW.12
Reduced
Current
(drive)
CW.4
enLatch
FallEdge

CW.11

CW.10

CW.9

CW.8

Reduced
Current

SetPos

disMixed
Decay

GetEncoder
Position

CW.3
enLatch
RiseEdge

CW.2
enLatch
Input2

CW.1
enLatch
Input1

CW.0

Control word (ExtCtrl)


Bit
Name

Bit
Name

CW.15

CW.14

Set Position Clear


in ProcData Position

CW.7
CW.6
CW.5
GetPosition ToggleLatch GetLatch
Error
Data
Data

enLatchC

Position
Bit

15

14

13

12

11

10

Cont. Position value

Statusbyte (Status)
Bit
Name

SB.7

SB.6

RegAccess Error

SB.5

SB.4

SB.3

Warning

Idle

LoadAngle

SB.2

SB.1

SB.0
Ready

Status word (ExtStatus)


Bit
Name

SW.7

SW.6

SW.5

SW.4

SW.3

SW.2

SW.1

SW.0

Encoder
Disabled

LatchData
Toggled

LatchData
InByte2,3

LatchValid

Target
Reached

SetPos
Ready

Input E2

Input E1

Bit
Name

SW.15

SW.10
OpenLoad
Br A

SW.9
Under
Voltage

SW.8
Over
Temperature

SW.14
NoControl
Config Error
Power

SW.13
SW.12
SW.11
OverCurrent OverCurrent OpenLoad
Br B
Br A
Br B

Data types: Example: KL2531


KL2531

Summary
Description

Typ

Velocity 16-bit with sign

INT

Ctrl 8-bit bitstring

BYTE

ExtCtrl 16-bit bitstring

WORD

Position 16-bit, no sign

UINT

Status 8-bit bitstring

BYTE

ExtStatus 16-bit bitstring

WORD

TwinCAT Training: Programmer

12.04.2013

106

Data types: Example for reading the DT system time


The system time can be read with the
FB FB_LocalSystemTime
(TCUtilities.Lib)

TwinCAT Training: Programmer

12.04.2013

107

Data types: Example for DT


IEC standard operations can be applied to
D# and DT#

TwinCAT Training: Programmer

12.04.2013

108

Example: String function FIND

Pos 1

Pos
10

Pos
11

10

TwinCAT Training: Programmer

12.04.2013

109

Example: string functions LEN, REPLACE


Example: a string sVal is to be filled up to 5 characters. Output is right-aligned.
(Display CX or similar)

Pos 1

Pos 5
sVal

sResult

.1

-5

-5

12345

12345

TwinCAT Training: Programmer

12.04.2013

110

Example: String conversion with Union


A string is placed in the same address in the memory with an ARRAY OF BYTE
(Union)

A
B
C
D
E
$R
$N
TwinCAT Training: Programmer

12.04.2013

111

Detail - Replace %MB by UNION


Place target variable in same addresses in order to perform an ASCII - CHAR
transformation

Possible
Better, since user
does not have to
manage addresses

TwinCAT Training: Programmer

12.04.2013

112

System
Query the set PLC cycle time

Creation of a variable of the type PlcTaskSystemInfo;

Query the system variable _TaskInfo []

Task no.

Component .CycleTime returns the set cycle time. Scaling:


10,000 is 1 ms

TwinCAT Training: Programmer

12.04.2013

113

TR3020 | Training for new users | Overview

TwinCAT 3 New Automation Technology

Training fr Umsteiger

SFC
Sequential Function Chart, SFC
Step
Action
Transition

Jump
Jump to Target Step
TwinCAT Training: Programmer

12.04.2013

SFC

The Actions Blocks


and Transitions
can be programmed
in any of the four
IEC Programming Languages
IL,ST, FBD,LD
(TC3: also SFC in Action Blocks)
TwinCAT Training: Programmer

12.04.2013

SFC
Branch
Alternative

Brach

Only left or right


branch can be
active at once.

TwinCAT Training: Programmer

12.04.2013

SFC
Branch
Alternative

Brach
Both transition are active

Only the left step is active

TwinCAT Training: Programmer

12.04.2013

SFC
Branch
simultaneos

Brach
One transition to enter

simultaneos execution
One transition to leave

TwinCAT Training: Programmer

12.04.2013

SFC
Branch
simultaneos, special case

Brach

Cant leave before TR7 is


TRUE
TwinCAT Training: Programmer

12.04.2013

SFC
Actions
Brach
direct assign of a bool variable with
an action (here qualifier N)

TwinCAT Training: Programmer

12.04.2013

SFC
Actions
direct assign of a bool variable with an action (here Qualifier S0 R0)

TwinCAT Training: Programmer

12.04.2013

SFC
Jump

Target Step

TwinCAT Training: Programmer

12.04.2013

10

New Automation Technology

Connectivity

12.04.2013

ADS (General)
Definition

ADS = Automation Device Specification


- Modular ADS devices
e.g. PLC (each runtime system), NC, etc.
- Data exchange with message router

NEU

ADS General
Definition: ADS = Automation Device Specification
modular ADS devices
e.g. PLC (each runtime system), NC, etc.
message exchange by ADS via the message router

Beckhoff Training: TwinCAT ADS

12.04.2013

ADS: General device concept


ADS server
unambiguously
identifiable by:
AdsAmsServerPort

Router
unambiguously
identifiable by:
AdsAmsServerNetID

Beckhoff Training: TwinCAT ADS

12.04.2013

Identification of ADS devices


Each (TwinCAT) PC in the network is clearly identifiable via a TCP/IP address,
e.g. 172.1.2.16
The NetID is the identifier of the message router on a TwinCAT system (PC, CX, BX, BC),
e.g. 172.1.2.16.1.1

The port number is the identifier of a TwinCAT device.


(PLC runtime 1, 2, 3, 4, NC, IO, cam controller)

Beckhoff Training: TwinCAT ADS

12.04.2013

Identification of ADS devices


The port number is the identifier of a TwinCAT device.
(PLC runtime 1, 2, 3, 4, NC, IO, cam controller)
Port

PLC runtime 1 (TC3)

851

PLC runtime 2 (TC3)

852

PLC runtime 3 (TC3)

853

PLC runtime 1 (TC2)

801

PLC runtime 2 (TC2)

811

PLC runtime 3 (TC2)

821

PLC runtime 4 (TC2)

831

NC

500
(501)

IP Address
172.16.17.108

Message Router 172.16.17.108.1.1

IO server

TwinCAT device

PORT 851 PORT 852 PORT 500


NC
PLC 2
PLC 1
I

IO Mapper
Beckhoff Training: TwinCAT ADS

12.04.2013

TwinCAT message router


Example:
an ADS client sends an ADS message to an ADS server.

the TwinCAT message router (transport layer 4) carries out:

the receipt of the clients request

forwarding the message to another router if appropriate

provision of the messages to the ADS server

Beckhoff Training: TwinCAT ADS

12.04.2013

TwinCAT message router


Existing message router:
on each TwinCAT PC
on each CX1000, CX1020 Embedded PC
on each BX Bus Terminal Controller
on each BC XXXX Bus Terminal Controller

Possible communication paths:


Network (TCP/IP)
A PLC runtime system sends data to another PLC on another
TwinCAT PC, Embedded PC, etc. in the network.
Fieldbus (Lightbus / PROFIBUS)
A PLC runtime system sends data to another PLC
on a Bus Terminal Controller in the fieldbus.

Beckhoff Training: TwinCAT ADS

12.04.2013

Client-server relationship
1.) Confirmed services
2.) Unconfirmed services
ADS Client

ADS Server

Request
(Anforderung)

Indication
(Aufforderung)

Confirmation
(Besttigung)

Response
(Antwort)

Beckhoff Training: TwinCAT ADS

12.04.2013

Client-server between two PLC devices


Example: PLC (runtime 1) requests data from PLC (runtime 2)
ADS Client

PLC I

ADS server PLC II

Uses ADS FB

merely keeps the


data available

Request

Indication

(FB call)

Confirmation

Response

(Busy on the FB)

Beckhoff Training: TwinCAT ADS

12.04.2013

10

Access methods, identification of the target data


By address

For PLC variable located in

%M

Memory range

%I

Input range

%Q

Output range

By name

PLC variable

Global

Example: .Tempsetpoint

Access with .Variablename


.TON1.ET GVL1.Input1 (global instance of an FB)

Local: VAR , VAR_INPUT, VAR_OUTPUT with instance path

Example: MAIN.TON1.ET

Beckhoff Training: TwinCAT ADS

12.04.2013

11

Access methods, sequence


Synchronous:

Client sends a query to the server

Client waits until the result is available

Synchronous with the program line

Asynchronous:

Client sends a query to the server

Client continues to operate directly


Result of the server by callback

Notification:

Client registers itself at the server

Server serves the client autonomously by callback


(until the client logs off from the server again)

Beckhoff Training: TwinCAT ADS

12.04.2013

12

Description of access with index group and index offset


Services are described by the parameters INDXGRP and IDXOFFS
In the case of the PLC function blocks ADSWRITE, ADSREAD, etc. these are
VAR_INPUT parameters
The same input parameters are used for the ADSDLL method calls

Beckhoff Training: TwinCAT ADS

12.04.2013

13

Description of access with index group and index offset


Detail for access to PLC data (selection)
PLC SOURCE /
target variable

IDXGRP

IDXOFFS

%MB

0x4020

MB address

Example

IDXGRP 0x4020
IDXOFFS 100

%MX

%IB

0x4021

0xF020

MB address * 8 +
bit address

IDXGRP 0x4021

IB address

IDXGRP 0xF020

IDXOFFS 81

IDXOFFS 0
%IX

%QB

0xF021

0xF030

IB address * 8 +
bit address

IDXGRP 0xF021

QB address

IDXGRP 0xF030

IDXOFFS 41

ISXOFF 100
%QX

0XF031

QB address * 8 +
bit address

IDXGRP 0xF011
IDXOFFS 167

Beckhoff Training: TwinCAT ADS

12.04.2013

14

Description of access with index group and index offset


Access by name takes place via a variable handle
See PLC example and VS example for details

Action

IDXGRP

IDXOFFS

Example

Create
Handle

0xF003

READ/ WRITE COMMAND

Read / Write
by
handle

0xF005

Handle

Read or Write : Data

Delete
Handle

0xF006

Write Data: Handle

WRITE: VarName

Read: Handle

Beckhoff Training: TwinCAT ADS

12.04.2013

15

PLC examples

Examples with 2 PLC runtimes

Beckhoff Training: TwinCAT ADS

12.04.2013

16

Access by address
Example: PLC 1 sends to PLC2 2; access by address

PLC 1

PLC 2 PORT 811

Beckhoff Training: TwinCAT ADS

12.04.2013

17

Access by address
Variable access
PLC 1
PORT PLC2
NETID local

INDEXGROUP 0x4020 ->%MB


INDEXOFFSET 100 address %MB100
Beckhoff Training: TwinCAT ADS

12.04.2013

18

Access by address
Notes

Beckhoff Training: TwinCAT ADS

12.04.2013

19

Access by name / handle PLC-PLC


Example: PLC 1 sends to PLC2 access by name handle
Request handle on variable name
Write by handle
Delete handle

PLC 1

PLC 2 PORT 811

Beckhoff Training: TwinCAT ADS

12.04.2013

20

Access by name / handle PLC-PLC


Request handle IDXGRP 16#F003
PLC 1

NetiD local
PORT PLC2
Create Handle

Beckhoff Training: TwinCAT ADS

12.04.2013

21

Access by name / handle PLC-PLC


Variable access by handle 16#F005
PLC 1
PORT PLC2
NETID local

INDEXGROUP 0xF005 ->Access by handle


INDEXOFFSET Handle
Beckhoff Training: TwinCAT ADS

12.04.2013

22

Access by name / handle PLC-PLC


Delete handle 16#F006
PLC 1
PORT PLC2
NETID local

INDEXGROUP 0xF006 ->Delete handle


INDEXOFFSET Handle
Beckhoff Training: TwinCAT ADS

12.04.2013

23

Access by name / handle PLC-PLC


Notes

Beckhoff Training: TwinCAT ADS

12.04.2013

24

Example: access by IDXGRP IDXOFFS


Example: read and write PLC variable located at %MB and %MX
Access with IDXGRP and IDXOFFSET
(TCINFOSYS)
%MB in PLC:

INDEXGROUP

0x4020

INDEXOFFSET the %MB address of the PlcC variable


%MX in the PLC:

INDEXGROUP

0x4021

INDEXOFFSET byte address (%MB) * 8 + bit address

INDEXGROUP 0x4021
INDEXOFFSET 10*8 +1 = 81
INDEXGROUP 0x4020
INDEXOFFSET 12

Beckhoff Training: TwinCAT ADS

12.04.2013

25

Example: access by IDXGRP IDXOFFS

PLC

C# Application

VAR_GLOBAL

BIT0 AT%MX10.0 :BOOL;

BIT1 AT%MX10.1 :BOOL;

BIT2 AT%MX10.2 :BOOL;

BIT3 AT%MX10.3 :BOOL;

iVar0 AT%MB12 :INT;

diVar0 AT%MB14 :DINT;

END_VAR

Beckhoff Training: TwinCAT ADS

12.04.2013

26

Example: access by IDXGRP IDXOFFS


Integration of Add AdsDll
1

Beckhoff Training: TwinCAT ADS

12.04.2013

27

Example: access by IDXGRP IDXOFFS

TcAdsClient tcClient = new TcAdsClient();


Instance TcClient
TcClient.Connect(851);
Link TcClient to PLC1
(PORT 851)
%MX ACCES
lblM10_0.Text = TcClient.ReadAny
(0x4021,
10 * 8 + 0,
typeof(bool)).ToString();

IDXGRP for %MX ACCESS


IDXOFFS MB ADDRESS *8
+ BIT ADDRESS
Type of variable

Result

Beckhoff Training: TwinCAT ADS

12.04.2013

28

Example: access by IDXGRP IDXOFFS

%MB ACCES
lblMW12.Text = TcClient.ReadAny
(0x4020,
12,
typeof(short)).ToString();

IDXGRP for %MB ACCESS


IDXOFFS MB ADDRESS of
the PLC variable (AT%MB12)
Type of variable

Result

Beckhoff Training: TwinCAT ADS

12.04.2013

29

Example: access by IDXGRP IDXOFFS

TcClient.Dispose();
Enables the resources

Details: Create PLC program, create Visual C# 2008 according to the


course notes

Beckhoff Training: TwinCAT ADS

12.04.2013

30

Example: access by IDXGRP IDXOFFS


Notes

Beckhoff Training: TwinCAT ADS

12.04.2013

31

Example: access by name

Basic procedure:
Insert TcClient
Insert Namespace
Instance object variable for TcClient
Create handle variables
Request handle on PLC variable(s)
Write & read by handle
Delete handle(s)
Release resources (dispose)

Beckhoff Training: TwinCAT ADS

12.04.2013

32

Example: access by name


Write the variables to the PLC and read back

PLC

C# Application

VAR_GLOBAL

BIT0 :BOOL;

BIT1 :BOOL;

BIT2 :BOOL;

BIT3 :BOOL;

iVar0 :INT;

diVar0 :DINT;
END_VAR

Beckhoff Training: TwinCAT ADS

12.04.2013

33

Example: access by name


TcAdsClient tcClient = new TcAdsClient();
Instance TcClient
private int hBit0;
Handle on the PLC variable

hBit0 = TcClient.CreateVariableHandle(".BIT0");
Request handle
Name of the PLC variable. Do
not forget the dot with global
variables
(. BIT0)

Beckhoff Training: TwinCAT ADS

12.04.2013

34

Example: access by name


chkBit0.Checked = (bool)TcClient.ReadAny(hBit0, typeof(bool));
Return type is object

Type of variable
Handle on the variable

Result sets check box

TcClient.WriteAny(hiVar0, (short)tbariVar0.Value);
Value to the PLC
PLC INT is in C# Short
Handle
Beckhoff Training: TwinCAT ADS

12.04.2013

35

Example: access by name


TcClient.DeleteVariableHandle(hBit0);
Delete handle

TcClient.Dispose();

Release resources

Details: Open the templates (PLC/C#) distributed in the course and follow
the instructions
Beckhoff Training: TwinCAT ADS

12.04.2013

36

Example: access by name


Notes

Beckhoff Training: TwinCAT ADS

12.04.2013

37

Example: access by notification


Methods:
TcClient.AddDeviceNotificationEx(.);
AdsNotificationEx += new AdsNotificationExEventHandler()
TcClient.DeleteDeviceNotification();

General procedure:
Register notification on each variable (handle)
Create event handler
Evaluate received data in the Notification Event
Delete notifications
Release resources

Beckhoff Training: TwinCAT ADS

12.04.2013

38

Example: access by notification


Example

PLC

VAR_GLOBAL
AxisName:STRING(19);
Ready:
Error:
actVelocity:
actPosition: LREAL;
setVelocity:
setPosition: LREAL;
Lagdistance: LREAL;
END_VAR

C# Application

BOOL;
BOOL;
LREAL;
LREAL;

Beckhoff Training: TwinCAT ADS

12.04.2013

39

Example: access by notification

TcAdsClient tcClient = new TcAdsClient();

Instance TcClient
TcClient.AdsNotificationEx += new
AdsNotificationExEventHandler(TcClient_AdsNotificationEx);
Event
Name of the event function

Beckhoff Training: TwinCAT ADS

12.04.2013

40

Example: access by notification


void TcClient_AdsNotificationEx(object sender, AdsNotificationExEventArgs e)
{
if (e.NotificationHandle == hnReady )
{
e contains:
}
Datavalue
}
Notification handle
userobject
Is run through when the PLC
timestamp
has sent data
TcClient.DeleteDeviceNotification(hnReady );
delete notifications
ends reading
Details: Open the templates (PLC/C#) distributed in the course and follow
the instructions
Beckhoff Training: TwinCAT ADS

12.04.2013

41

Example: access by notification


TcClient.Connect(851)
Open port on PLC
hnReady = TcClient.AddDeviceNotificationEx
(
notification handle
".Ready",
AdsTransMode.OnChange,
100, 0,
lblReady,
typeof(bool)
);

PLC variable name

Update method
Filter time
User object or zero
Data type of the read
variable

For each variable


Beckhoff Training: TwinCAT ADS

12.04.2013

42

Example: access by notification


Notes

Beckhoff Training: TwinCAT ADS

12.04.2013

43

Writing / reading a 1-dimensional array


Methods:
TcClient.CreateVariableHandle(.);
TcClient.ReadAny()
TcClient.WriteAny();
TcClient.DeleteVariableHandle();
Procedure:
Connect to device PLC
Create variable handle
Read / write variable by handle
Delete variable handle

12.04.2013

44

Writing / reading a 1-dimensional array


Example:

PLC
VAR_GLOBAL
VisuPositions: ARRAY [0..19]
OF LREAL;

C# Application

double[] PlcArray;

END_VAR

12.04.2013

45

Writing / reading a 1-dimensional array


PlcArray = (double[])TcClient.ReadAny
(
handle
hPlcArray,
typeof(double[]),
Variable Type
new int[] { 20 }
Array length, number of
);
elements
C# target variable
TcClient.DeleteVariableHandle(hPlcArray);
Delete handle
Details: Open the templates (PLC/C#) distributed in the course and follow
the instructions
12.04.2013

46

Writing / reading a 1-dimensional array


Notes

12.04.2013

47

Reading a 1-dimensional array with notifications


Methods:
notificationHandle =TcClient.AddDeviceNotificationEx()
TcClient.DeleteDeviceNotification(notificationHandle);
TcClient.AdsNotificationEx += new AdsNotificationExEventHandler();
Procedure:
Connect to device
Add notification handler
Add device notification, device sens automaticly
Data im callback auswerten
Delete device notification

12.04.2013

48

Reading a 1-dimensional array with notifications


Reading a PLC array with notifications
PLC
VAR_GLOBAL
VisuPositions: ARRAY [0..19]
OF LREAL;

C# Application

double[] PlcArray;

END_VAR

12.04.2013

49

Reading a 1-dimensional array with notifications

TcAdsClient tcClient = new TcAdsClient();


Instance of the
TcAdsClient
TcClient.AdsNotificationEx += new
AdsNotificationExEventHandler(TcClient_AdsNotificationEx);
Event
Name of the event

12.04.2013

50

Reading a 1-dimensional array with notifications


TcClient.Connect(851)
Connect to plc
hnPlcArray=TcClient.AddDeviceNotificationEx(
PLC variable
Create notification handle ".VisuPositions",
AdsTransMode.OnChange,
Actualisation by
100,0,
Time for checking for
change of array
dataGridView1,
changes
User object
typeof(double[] ),
Data type
new int[] {20});
Arguments, number
of array elements

12.04.2013

51

Reading a 1-dimensional array with notifications


void TcClient_AdsNotificationEx(object sender, AdsNotificationExEventArgs e)
{
if (e.NotificationHandle == hnPlcArray)
{
e contains:
}
}
Datavalue
Notification handle
Is run through when data is
userobject
received
timestamp

TcClient.DeleteDeviceNotification(hnPlcArray);
Delete notifications
Details: Open the templates (PLC/C#) distributed in the course and follow
the instructions
12.04.2013

52

Reading a 1-dimensional array with notifications


Notes

12.04.2013

53

Read structure synchronously from the NC with IDXGRP


IDXOFFS
Method:
tcClientObject.Read(Indexgroup, Indexoffset, AdsStream);
AdsStream : Buffer for read data. Namespace: TwinCAT.Ads.Adstream
Class for evaluating the data stream:
BinaryReader. Namespace: System.IO
Or AdsBinaryReader Namespace TwinCAT.Ads simplified handling for strings
and PLC data and time types
Procedure:
Create Adsstream
Create BinaryReader or AdsBinaryReader
Read Methode aufrufen (Read, ReadAny)
Evaluate data stream and copy into target structure

12.04.2013

54

Read structure synchronously from the NC with IDXGRP


IDXOFFS
Example
NC
NC ADS Documentation :
IDXGRP 0x4000 + AxisID
IDXOFFSET 0
Details : TCMC.LIB

C# Application

ListView

12.04.2013

55

Read structure synchronously from the NC with IDXGRP


IDXOFFS
TcAdsClient tcClientNc = new TcAdsClient();
Instance
AdsStream AdsStrNcParaset= new AdsStream(512) ;
Ads stream for receive data
Length in bytes
tcClientNc.Read(Indexgroup + AxisId, Indexoffset, AdsStrNcParaset);
Read command
IDXGRP /IDXOFFS -> TcInfosys
Target stream

12.04.2013

56

Read structure synchronously from the NC with IDXGRP


IDXOFFS
Getting the index group and index offset from the Beckhoff information system
TcInfosystem

12.04.2013

57

Read structure synchronously from the NC with IDXGRP


IDXOFFS
Beckhoff Information System

Function to
read/write

Indexgroup +
Axid

Indexoffset

Acces Read
only

@ Result for AXIS1 : IDXGRP 0x4001 IDXOFFSET 0


12.04.2013

58

Read structure synchronously from the NC with IDXGRP


IDXOFFS
BinaryReader BinRead = new BinaryReader(AdsStrNcParaset,Encoding.ASCII );
Class for decoding the
receive stream
Constructor contains receive stream
Required if strings are contained

BinRead.ReadInt32()
Example for 32-bit INT

12.04.2013

59

Read structure synchronously from the NC with IDXGRP


IDXOFFS
Or: AdsBinaryReader:
AdsBinaryReader AdsBinRead = new AdsBinaryReader(AdsStrNcParaset);
Ads Class to evaluate stream
Constructor with AdsStrem

AdsBinRead.ReadInt32()
Example for 32-bit INT

Details: Open the templates (PLC/C#) distributed in the course and follow
the instructions
12.04.2013

60

Read structure synchronously from the NC with IDXGRP


IDXOFFS
Notes

12.04.2013

61

Reading structures with notifications


Methods:
TcClient.DeleteDeviceNotification(notificationHandle);
notificationHandle =TcClient.AddDeviceNotification()
TcClient.AdsNotificationEx += new AdsNotificationExEventHandler();
Procedure:
Connect to device
Add notification handler with datastream
Add device notification,
Evaluation of the data in callback
Delete device notification
Note:
StructLayout and MarshalAs can alternatively be used with the standard
framework. The method AddDeviceNotificationEx can be used there.

12.04.2013

62

Reading structures with notifications


Example
PLC
TYPE strAxisstate :
STRUCT

C# Application
private struct Axisstruct
{

AxisName:STRING(19);

public string AxisName;

Ready: BOOL;

public bool Ready;

Error: BOOL;
actVelocity: LREAL;

public bool Error;

actPosition: LREAL;

public double actVelocity;

setVelocity: LREAL;

public double actPosition;

setPosition: LREAL;

public double setVelocity;

Lagdistance:LREAL;

public double setPosition;

END_STRUCT

public double Lagdistance;

END_TYPE
}
VAR_GLOBAL
Axistate1 :strAxisstate ;

private Axisstruct Axistruct1;

END_VAR

12.04.2013

63

Reading structures with notifications


TcAdsClient TcClient = new TcAdsClient();
Instance for ads client
TcClient.AdsNotification += new AdsNotificationEventHandler
(TcClient_AdsNotification);
Add event

AdsStream StreamAxisstruct1 = new AdsStream(62);


Stream to receive data

12.04.2013

64

Reading structures with notifications


Check event
void TcClient_AdsNotification(object sender, AdsNotificationEventArgs e)
{ // check stream

AdsBinaryReader to
evaluate Stream

e.DataStream.Position = 0;
AdsBinaryReader AdsBinReader = new AdsBinaryReader(e.DataStream);
Axistruct1.AxisName = AdsBinReader.ReadPlcString(20);
Axistruct1.Ready = AdsBinReader.ReadBoolean();
Read Data from stream.
Position increments
automaticly
12.04.2013

65

Reading structures with notifications

TcClient.DeleteDeviceNotification(hnAxisstruct1);
Delete Notification only one handle per struct

TcClient.Dispose();
Release resources

Details: Open the templates (PLC/C#) distributed in the course and follow
the instructions
12.04.2013

66

Reading structures with notifications


Notes

12.04.2013

67

Beckhoff EtherCAT Training

EtherCAT Training
Contents
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9

30.01.2012

Hardware
Principles
Topology
Benefits and efficiency
Exercise: Driver Installation ->System Manager
EtherCAT Data Exchange
Protocol
Performance
The Feildbus EtherCAT
Configuration In System Manager
Exercise:
Parameterization and commissioning of the
System Manager
Sync Units
Exercise: Hot Connect
Diagnose
Exercise: Cable Redundancy
XFC eXtreme Fast Control Technology
Exercise: Distributed Clocks Timing
Exercise: Distributed Clocks
with input channels
Exercise: Oversampling

EtherCAT Training

Hardware
EtherCAT Fieldbus Master
IPC / Control Panel
Intel-Chipset based network card
with a TwinCAT real-time
Ethernet driver:
FC9001/9002/9004/9011
Supported network adapters in the
Information System
(Online:http://infosys.beckhoff.com/
content/1033/tcsystemmanager/refe
rence/ethercat/html/ethercat_supne
tworkcontroller.htm?id=10257)
Embedded PC / Control Panel
CX90xx
CX10xx
CX50xx
30.01.2012

EtherCAT Training

Hardware
Overview of standard components EL (IP20)
Bus Coupler
/ EK1101

Bus End Cap :EL9011

EK1100

EL or ES Terminals with E-bus


30.01.2012

EtherCAT Training

Hardware
Overview of standard components KL (IP20)
Bus Coupler

End Terminal : KL9010

BK1120

KL or KS Terminals with K-bus


(BK1250: EtherCATK-Bus)
30.01.2012

EtherCAT Training

Hardware
Overview of standard components EP (IP67)
EP1111 EtherCAT Box
EP1122 EtherCAT 2-port junction

The EtherCAT connection is established via screened M8 screw plug-in


which will directly link activity and status.
30.01.2012

EtherCAT Training

Hardware
More EtherCAT components
EK1501

EK1521

EK1122

EK1110

30.01.2012

EK 1132

EL6692

EtherCAT Training

Principle
EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

Principle
Highlights
Ethernet up to the terminal - complete continuity
the Ethernet interface process, scaled from 1 bit to 64 Kbytes
the first true Ethernet solution for the field level
exact timing and synchronization
There were far different problems to make the classic
Ethernet real-time capability:
Collision detection (CSMA / CD) override
Special switches to create as frames temporally accurate deliver
Problem
Also be sent to small amount of data must be a complete
Ethernet frame
Lower-level bus system will lead to additional delay (eg K-bus)
30.01.2012

EtherCAT Training

EtherCAT
The Ethernet down to the terminal!
Direct address of the EtherCAT Slave Controller (ESC) to process
data in the EtherCAT frame
Through the ESC command header distinguishes between
process data and other commands
Ringbussystem mit softwareseitigem Abschluss
From an Ethernet point of view: EtherCAT bus is an Ethernet device
Process data for example are the PLC is no longer welcome in, but
interpreted by the EtherCAT Slave Controller (ESC) taken
directly from the message.
The EtherCAT frame is only a few ns delayed while passing through
the EtherCAT slave
The last device in the bus segment sends the frame back to
the EtherCAT master
30.01.2012

EtherCAT Training

10

EtherCAT
ESC
The handling of the EtherCAT communication in an
EtherCAT slave is tasked by an EtherCAT Slave Controller (ESC)
Each EtherCAT slave has such an ESC to cyclic and
acyclic process data exchanged by the master to the slave via
the EtherCAT field bus
This ESC can handle simple functions such as direct digital inputs
and outputs, but it can also be connected via serial /
parallel interface to another processor in the EtherCAT slave for
the more complex tasks such as Motion Control.

30.01.2012

EtherCAT Training

11

EtherCAT
Overview of EtherCAT Slaves

30.01.2012

EtherCAT Training

12

EtherCAT
typical embedding of the ESC
Of the RJ45 connector, the electrical signals through the transformer
to the PHY (physical interface) led.
The ESC then extracts from the encoded signal,
the Ethernet payload and forwards them to the ESC to
the processing.
Minimum delay (as in a continuous process),
the EtherCAT telegram then passed through PHYtransformer bushing to the next EtherCAT slave.
The ESC is configured in slave-start automatically with
configuration data from an EEPROM. If another CPU exists in the
slave, it can communicate with it via interfaces.

30.01.2012

EtherCAT Training

13

Topology
EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

14

Topology

Line, tree or star topology


up to 65,535 slaves
Network size: almost unlimited (> 500 km)
Operating with or without switches
cost-effective cabling: Industrial Ethernet Patch Cable (CAT5)
physical transmission : Twisted-Pair:
Ethernet 100BASE-TX to 100 m between two devices
alternatively, fiber optic versions 50-2000 m
Hot-Connect/Disconnect from system
Upgrade to Gigabit Ethernet possible

Physical layer is converted in the coupler to the E-bus signal


form LVDS (Low Voltage Differential Signalling)
If necessary. re-conversion of the signal shape at the end of the bus
segment to pass on to the next Interface module and coupler.
30.01.2012

EtherCAT Training

15

Topology : Line
any number of nodes "in series"
IPC

..
..

DVI

Up to 65,535
participants
Cable: standard CAT 5 cable,
consistently without the
"crossover"
30.01.2012

EtherCAT Training

16

Topology : Chain

IPC

..
..

DVI

Up to 65,535
participants
Cable: standard CAT 5 cable,
consistently without the
"crossover"
30.01.2012

EtherCAT Training

17

Topology : Line & Daisy Chain

IPC

..
..

DVI

Up to 65,535
participants
Cable: standard CAT 5 cable,
consistently without the
"crossover"
30.01.2012

EtherCAT Training

18

Topology : Mixed!
flexible tree structures - can be extended
IPC

..
..

DVI

Up to 65,535
participants
Cable: standard CAT 5 cable,
consistently without the
"crossover"
30.01.2012

EtherCAT Training

19

Benefits and Efficiency


EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

20

Benefits and Efficiency

no network tuning: lower engineering costs


hard real-time software with master: no plug
no active infrastructure components (switches, etc.) is required
Ethernet cable and connector costs lower than the classic field bus
systems
EtherCAT to the I / O terminal: no more complicated coupler
low connection costs due to highly integrated EtherCAT Slave
Controller
EtherCAT is the only fieldbus
Integration "in Fieldbus Fieldbus" for more field buses like CAN,
PROFIBUS, ETHERNET, etc.
No other fieldbus Master e.g. as a PCI card in the PC necessary!

30.01.2012

EtherCAT Training

21

Benefits and efficiency EtherCAT instead of PCI

Seamless integration of
existing Fieldbus Devices
Process image update
time over EtherCAT (1500
bytes of I / O data): 150s
Before:
Process image update
time via PCI (500 bytes of I /
O data): 400s
30.01.2012

EtherCAT Training

22

Benefits and efficiency topology with Ethernet


over EtherCAT
Ethernet over EtherCAT (EoE) allows direct connection of Ethernet
devices in the EtherCAT fieldbus
Complete integration of all Ethernet technologies!

virtual Ethernet Switch


Functionality

EoE
Switchport

IPC

..
..

DVI

e.g. Connection
of a Label
Printer / Scanner

30.01.2012

Programming directly in the I / O


area

EtherCAT Training

23

Benefits and efficiency topology with vertical


integration
...via 2. Ethernet Port

IPC

..
..

DVI

any Ethernet protocols can be used

Ethernet performance is EtherCAT


not restricted

30.01.2012

No need for switch port terminal

requiring second Ethernet port (on IPC / control)


EtherCAT Training

24

Excersise

Driver Installation in System Manager


EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

25

Real-time Ethernet driver


For real-time communication over the network card is a Y-driver
needed
Transparent integration into the operating system (compliant to the
operating system, while TwinCAT fieldbus card driver)
On the transmission side is by internal buffer and
prioritization ensures that the real-time frames always find a free
transmission line
The Ethernet frames to the operating system will be shipped
within gaps
On the receiving end, all Ethernet frames from the TwinCAT I / O system checks and filter out the real time relevant information
All other frames are routed back to the operating system

30.01.2012

EtherCAT Training

26

Excersise
Real-time Ethernet driver
The installation of real-time Ethernet driver can be made via the
TwinCAT System Manager.
To use the cable redundancy, the driver must be installed on two
network cards

30.01.2012

EtherCAT Training

27

Real-time Ethernet driver integration into the


operating system

30.01.2012

EtherCAT Training

28

EtherCAT Data Exchange


EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

29

EtherCAT Data Exchange


When to take place between EtherCAT system of
direct, synchronous data exchange, various options are available for
this purpose.
Choosing the right approach should be taken in individual
cases, depending on the application.
To select the method the following distinguishing features used :
Synchronous data exchange with predefined in the configuration specified process data
Asynchronous data exchange
Support for ADS over EtherCAT (AoE)
Support the synchronization of distributed clocks (DC) of
both systems

30.01.2012

EtherCAT Training

30

EtherCAT Data Exchange Index


EL6692

Publisher/
Subscriber

EL6601

FC1100

Max. synchro
nous data
size

480 Byte,

any

1024 Byte,

1024 Byte,

Max. extent of
asynchronous
data

beliebig

AoE support

Yes

Yes

Yes

Yes

support DC

Yes

reference

- recommended to
synchronize EtherC
AT systemsTwinCAT
2.11 required

- Use of
Ethernet ports in
both
systems as realtime device recom
mended for
synchronous data
transfer

- Relocation

- free PCI slot in


the
IPC required Twi
nCAT 2.11-R2 is
required

- CX5000 is a lowerlevel autonomous co


ntrol of its
own IO integrated as
EtherCAT slave
option in the host
system requires B11
0
- TwinCAT
2.11 R2 required

30.01.2012

bidirectional

EtherCAT Training

of RT devices in
a terminalEtherCAT recom
mended for
synchronous dat
a transfer

CX50x0B110

31

EtherCAT topology data exchange

30.01.2012

EtherCAT Training

32

Protocol
EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

33

Protocol
optimized protocol directly in the Ethernet frame
fully implemented in hardware
for routing and socket interface: UDP datagram
Processing while passing
Distributed clock for precise synchronization
Time stamp data type for resolution in the nanosecond range
Oversampling data types for high resolution measurements

30.01.2012

EtherCAT Training

34

Protocol in detail description


The EtherCAT protocol is optimized for process data Ethernet
protocol that either one (or more) or Ethernet frames over
UDP / IP is consistently sent
An Ethernet frame is 1514 bytes in
size EtherCAT datagrams (process data, etc.) with an effective
size of 1486 bytes to send
Need more data to be exchanged, a new Ethernet frame opened
With the EtherCAT process data in the Ethernet frame can be
addressed by a process image up to 4 GB.
The physical configuration of the EtherCAT slaves in the bus has
no effect on the speedof the frame or the data sequence within the
frame!
device profile for CANopen (CoE) or SERCOS (SoE)

30.01.2012

EtherCAT Training

35

Protocol in detail design of the frames


EtherCAT uses standard frames according to IEEE 802.3
no shortened Frames
Alternatively, via UDP / IP (if IP routing required)
MTU Maximum
Transmission Unit,
the computer
network, the
maximum amount
of
datatransmitted un
fragmented.

MTU: max. 1514 Byte

48 Bit

48 Bit

16 Bit

16 Bit

Destination

Source

EtherType

Header

Embedded in Standard Ethernet


Frame, EtherType 0x88A4
160 Bit

Ethernet H.

IP Header

32 Bit

CRC

1..n EtherCAT
Telegram
64 Bit

UDP H.

Header

CRC

Or: via UDP/IP


UDP Port 0x88A4
11 Bit

Length
0

30.01.2012

EtherCAT Training

1 Bit

4 Bit

Res.
11

Type
12

15

36

Protocol in detail
full integration of TCP / IP
all available Internet technologies: HTTP, FTP,
without limitation for real-time characteristics of the bus
system!
EtherCAT Device

Standard
TCP/IP
Stack

Real Time
Application

Ethernet
Application
TCP

UDP
Acyclic
Data

IP
Mailbox

Process Data

EtherCAT MAC / DLL


Ethernet PHY

30.01.2012

EtherCAT Training

Ethernet PHY

37

Performance
EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

38

Performance
256 Digital-I/Os in 12 s
1.000 Digital-I/Os in 30 s
200 Analog-I/Os (16 Bit) in 50 s, corresponds 20-kHz-SamplingRate
100 servo axes in 100 s
12.000 Digital-I/Os in 350 s
The EtherCAT bus system is so fast that can be made between two
(PLC) control cyclesor internal processing of EtherCAT
EtherCAT is not limited to 100 MBaud
The bus system is no longer the bottleneck of control!

30.01.2012

EtherCAT Training

39

Performance
principle Ethernet on the Fly

Wagen
27

Trainn (Ethernet Frame) does not stop


and who sees the "train" through a narrow window, sees
the whole train
Carriages" (sub-frames) are of variable length
There may be some "people" (bits) or all the
"groups" (x Kbytes) "removed" and / or incorporated

30.01.2012

EtherCAT Training

40

Performance in the processing cycle


Data is taken from
the Ethernet cable on
the run. Inputs or
Outputs
no intermediate store of
Telegrams
minimum throughputDelay
optimal performance

30.01.2012

EtherCAT Training

vom
vom Master
Master
zum Master

41

The EtherCAT fieldbus


EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

42

The EtherCAT fieldbus mapping of


multiple process images so far
Conventional fieldbus systems produce physical process image
Mapping is "onto this logical process image (s)

logical process images

Controller e.g. IPC


Feldbus Scanner/
DPRAM Master

node 1

node 1
Data n
PLC Data

node 2

node 2

NC Data

node 3
node 4

node 3

Mapping
node 4
30.01.2012

EtherCAT Training

43

The EtherCAT fieldbus mapping of a process


images so far
The same applies to controls with a single process image
Reordering of the process data ("mapping") is also required
Controller
logical process image

Feldbus Scanner/
DPRAM Master

node 1

node 1
node 2

node 2

Process
Data

node 3
node 4

node 3

Mapping
node 4
30.01.2012

EtherCAT Training

44

The EtherCAT
fieldbus mapping shifts in the slave
IPC

..
..

DVI

232

Telegram structure

logical process image: up to 4 GB

Ethernet HDR

30.01.2012

HDR 1

PLC Data

HDR 2

NC Data

HDR n

Data n

CRC

Data n
PLC Data
NC Data

SubTelegramm 1

SubTelegramm 2

SubTelegramm n

Control is released, is very easy to master


0

Data is ever transmitted on application


requirements: extremely fast, flexible and efficient
EtherCAT Training

45

The EtherCAT fieldbus Direct Memory


Access saves time
Fieldbus: take up to 30% of the
CPU time for copying data

PC Control mit Feldbuskarten

PC RAM
Control task

Scanner card, DP RAM


PCI
bus

EtherCAT: NIC is PCI bus


master DMA data is
provided by the PC RAM
Less CPU burden
More Performance

30.01.2012

EtherCAT Training

CPU

PC Control mit EtherCAT


CPU

NIC card, DMA transfer

memcopy

PC RAM
Control task

PCI
bus

DMA

46

The fieldbus reaction time


I PLC Task O I PLC Task O I PLC Task O I PLC Task O I PLC Task

Tmpd

Bus Cycle

TI/O

TI/O

Bus Cycle

TI/O

TI/O

Bus Cycle

TI/O

TI/O

Bus Cycle

TI/O

TI/O

TI/O

Bus Cycle

TI/O

TI/O

Bus Cycle

TI/O

TI/O

Bus Cycle

TI/O

TI/O

best case Reaction Time


Input
(Worst case)

worst case
Reaction Time

Input
(best case)

Output
Tmpd: Master Processing Delay
TI/O: Local I/O Update Time
(local Extension Bus + Firmware)

30.01.2012

EtherCAT Training

47

The EtherCAT fieldbus EtherCAT system design

I PLC Task O I PLC Task O I PLC Task O I PLC Task O I PLC Task
No master controller board more
Tmpd

Bus Cycle

TI/O

TI/O

Bus Cycle

TI/O

TI/O

Bus Cycle

TI/O

TI/O

Bus Cycle

TI/O

TI/O

TI/O

Bus Cycle

TI/O

TI/O

Bus Cycle

TI/O

TI/O

Bus Cycle

TI/O

TI/O

No more lower-level expansion

30.01.2012

EtherCAT Training

48

The EtherCAT fieldbus processing between two


control cycles

I PLC Task O I PLC Task O I PLC Task O I PLC Task O I PLC Task

DMA (NIC)

TDMA (Time for Data Transfer to /


from
the Ethernet controllers via Direct
MemoryAccess):negligible

EtherCAT Cycle

30.01.2012

EtherCAT Training

49

The reaction time with EtherCAT fieldbus

I PLC Task O I PLC Task O I PLC Task O I PLC Task O I PLC Task

worst case
Reaction Time
Input
(Worst case)

best case

Input
(best case)

Output

Reaction time is reduced significantly with the same control performance


no subordinate local I / O cycles or more expansion buses
Because of the very simple protocol no special master
systems (eg plug-in) is required

30.01.2012

EtherCAT Training

50

Configuration of the System Manager


EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

51

Configuration of the EtherCAT System in


TwinCAT System Manager
The EtherCAT master in the IPC environment

30.01.2012

EtherCAT Training

52

Configuration of the System


Manager software as EtherCAT Master Device
The EtherCAT master device as a software TwinCAT
Process data of the PLC / NC / Task assemble the Ethernet frames to
the EtherCAT datagrams and send them via the Ethernet port assigned
Extract from I / O environment received process data and then go
back to the task
Construction of cyclic and acyclic telegrams
Distributed-Clocks-Synchronisation
evaluates the diagnostic information of the EtherCAT slave
performs event-related diagnosis or respond to changing topologies
an EtherCAT system with up to 65,535 slaves on an
Ethernet interface ("RJ45 port") link.
Cable redundancy of the EtherCAT master with a second port
EtherCAT communication with other masters in
the same TwinCAT system
The sole producer of EtherCAT telegrams in an EtherCAT system
30.01.2012

EtherCAT Training

53

Configuration of the System


Manager cyclic / acyclic communication
Synchronous execution of task and EtherCAT communication

Temporal distribution of cyclic (solid) and acyclic (variable)


EtherCAT telegrams

30.01.2012

EtherCAT Training

54

Configuration in System
Manager of EtherCAT frames
Example of an EtherCAT communication with
20 slaves and a 100us task

30.01.2012

EtherCAT Training

55

Configuring the EtherCAT master system


manager: Adapter tab
MAC Address: MAC address of the
Ethernet controller
IP Address: Set IP address from
the Windows registry. The
network class of "normal
Ethernet network interface
card should be different.
Freerun cycle : Cycle [ms] in
the config mode Freerun
Promiscuous Mode: should
be activated when the data
traffic as to be
recorded with Wireshark.

30.01.2012

EtherCAT Training

56

Configuring the EtherCAT master system


manager: EtherCAT tab (above)
NetId: AmsNetId of the
EtherCAT master
Advanced Settings:
additional network setup, such
as DC, shift time, etc.
Sync Unit Assignment : Sync
Units each EtherCAT slave
Topology: Opens the view Topolgy

30.01.2012

EtherCAT Training

57

Configuring the EtherCAT master system


manager: EtherCAT tab (below)
LRW = Read
inputs, write outputs
BRD =
Broad Cast Read, re
ad status of all slaves

Frame: Cyclic EtherCAT telegram


Cmd: Command type (LRD = Logical Read, Write LWR = Logical, Logical LRW = Read &
Write)
Addr: With logical addressing of the slaves here is the logical
address. Otherwise, specify theupper 16-bit physical memory address, the lower the
fixed 16-bit slave address (Auto IncAdr, Adr EtherCAT)
Len: data length
WC: Expected working counter. Each slave this counter incremented. Slaves who write
in theLRW Increment by 2, the slaves to read from the LRW Increment by 1
SyncUnit: associated SyncUnit
Cycle: associated cycle time
See also the
Utilisation: Overall utilization [%] of the frame
chapter Diagnostics!
Size: Size [bytes] of the entire frame
Duration: Time [s]
30.01.2012

EtherCAT Training

58

EtherCAT Master: Master Advanced Settings


Start-up behaviour when
switching / start-up

Runtime behaviour
of the Diagnosis

Info data to fade into the


process image

30.01.2012

EtherCAT Training

59

EtherCAT Master: Advanced Settings Global


Settings slave on the master
Startup checks during
initialization of the slaves

State machine after failure of


a slave or the master

Infodata to fade into the


process image
The slave settings
can be
made alternatively for
each slave.

30.01.2012

EtherCAT Training

60

EtherCAT Slave: Advanced settings behaviour


In addition to the
master settings are :
The Final System State
The process data
is partly changed
A Fixed addressing are
enforced
The watchdog behaviour
can be parameterized

30.01.2012

EtherCAT Training

61

EtherCAT slave: timeout advanced settings


If necessary, the switching
behaviour between the individual
EtherCAT slaves are changed.
In general, the EtherCAT slaves
should also be operated with the
default settings.

30.01.2012

EtherCAT Training

62

Excersise

Parameterization and commissioning of the System


Manager
EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

63

EtherCAT slave configuration of


a specific example of the EL7041
In addition to the standard configuration of the
EtherCAT slave can often also becustomized settings
Process image change
PDO modify content
Parameters on startup lists initialized

30.01.2012

EtherCAT Training

64

Change in the PDO Contents


If the assignment of
the PDO changed, this
should also be loaded at
start up in the slave.
Also, the configuration of
one (or more) PDO (s) are
loaded into the slave.
By selecting a PDO list, the
corresponding PDO content
s by right-clicking possibly
extended with
new parameters.

30.01.2012

EtherCAT Training

65

Add start up parameters


If the content of the CoE
objects are modified, this
must be added to
the startup list for the
exchange of slaves make n
o further parameterizations.
On "New ...", the CoE
objects are selected and
added.

30.01.2012

EtherCAT Training

66

Temporary change CoE-Online

values are changed only


temporarily, so in case of an
exchange of slaves are not
preserved.

30.01.2012

EtherCAT Training

67

Update of
the EtherCAT Configuration Description
Since terminals is constantly evolving, the EtherCAT configuration
descriptions of the terminals (XML Device Description) is updated regularly
To take advantage of new terminals, modules, or FW-functions must be
provided according to current configuration descriptions
If these do not exist, the recognition of a new terminal will attempt to
load the description of the terminal :

This may range from not enough to ensure the proper operation of
the terminal - useful>update the XML device description

30.01.2012

EtherCAT Training

68

Update of
the EtherCAT Configuration Description
The current XML device description are available on the Beckhoff website
for download and is updated regularly :
http://www.beckhoff.com/english/download/elconfg.htm?id=71003277100532
The files of the extracted zip file can be manually copied to
".. \ TwinCAT \ Io \ EtherCAT"and the files will be replaced there
If necessary. existing cache files that were created when
you upload the device description from
the terminal should be deleted (eg: ".. \ TwinCAT \ Io \ EtherCAT \OnlineDes
criptionCache00000002.xml")
The update of the device description can be conveniently carried out via
the TwinCAT System Manager (from TwinCAT Build 2.11.1545) (ESIupdater)
The old files are automatically backed up (zipped file) and delete any
existing cache files
Same dialogue / function without the TwinCAT System
Manager EsiUpdateDlg.exeunder ".. \ TwinCAT \ Io
30.01.2012

EtherCAT Training

69

Update of
the EtherCAT Configuration Description

30.01.2012

EtherCAT Training

70

Sync Units
EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

71

Sync Units Essential characteristics


Synchronous exchange of process data related to the validity
In addition to a diagnosis of the field bus, now the diagnosis of
individual groups, so-called "Sync Units" possible
Transparent data exchange for each Sync Unit
Synchronous exchange of process data in multi-task operation, so
that a sync unit of several different fast task can be served at the
end must be logically correct!
Using Sync Units for delineation of individual logical or physical
modules.
Each unit provides sync cycle synchronization process data that
can be used to diagnose the entire system.

30.01.2012

EtherCAT Training

72

Sync Units
What For?
Sync units are used in particular for applications in which
individual parts are either machine or error
conditions can be switched off without the other machine parts are
to be influenced by.
For dynamic activation and deactivation of modules and
their connection to any position in the field bus (Hot Connect)
these modules are in separate units Sync.
Communication terminals such as fieldbus master-slave modules,
or modules, eg PROFIBUS, CAN should be in separate Sync Units

30.01.2012

EtherCAT Training

73

Sync Units
parameterization in System Manager
SPSTask
Task
SPS

NCTask
Task
NC

SPSTask
Task
SPS
User
User
defined
defined
SyncUnit
Unit
Sync
30.01.2012

EtherCAT Training

74

Sync Units
EtherCAT Commands

Each unit contains the sync process


data necessary for
your commands, depending on the
slaves.
30.01.2012

EtherCAT Training

75

Excersise

Hot Connect
EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

76

Excersise
Hot Connect Funktionsprinzip
Many applications require a change in I / O configuration during
operation :
Machining centres with changing, sensor-equipped tool systems
Presses, in which individual printing units can be switched off
etc.
EtherCAT protocol structure allows this
The hot component Connect features / modules in the
EtherCAT network can in operation on or be
decoupled and may be attached to another, anywhere and on again

30.01.2012

EtherCAT Training

77

Excersise
Hot Connect with EK1101
The EK1101 EtherCAT Coupler has three hexadecimal ID
switches can be assigned to those of a group of
EtherCAT components of an ID.
This group can then be located at any point in the EtherCAT
network.

30.01.2012

EtherCAT Training

78

Excersise
Hot Connect - im System Manager

Right-click on EK1101 and


selection:
"Add to Hot Connect Groups ...".
30.01.2012

EtherCAT Training

Selection of belonging to the


group participants
and registration of
contracts with input
coupler ID Word.

79

Excersise
Hot Connect - SyncUnit assignment
Change the display in a directory tree
For each group Hot
Connect automatically sync its
own unit is inserted:

30.01.2012

EtherCAT Training

80

Diagnosis
EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

81

Diagnosis

Breaking point detection


continuous "quality-of-line"
measurement enables precise localization of transmission errors
Topology View
The EtherCAT system can be diagnosed through
various variables :

30.01.2012

EtherCAT Training

82

Diagnosis :
EtherCAT State Machine

About the EtherCAT State Machine (ESM) of


the state of the EtherCAT slave is
controlled. We distinguish the following states:
Init
Pre-Operational
Safe-Operational und
Operational
Boot
30.01.2012

EtherCAT Training

Init: EtherCAT master initializes


the Sync Manager channels 0 and 1
for the mailbox communication
Pre-Op: During the transition
from Init to preop checks the EtherCAT slave, if the
mailbox has
been initialized correctly.
Safe-Op: During the transition from preop checks for safe-Op of the
EtherCAT slave, if the sync
manager for
process data communication chann
els and, if the settings
for the distributed clocks are
correct. (Outputs safe)
Op:Before the EtherCAT master on the
EtherCAT slave after he
has already Op valid output
data transfer.
Boot: In the state boat can update
the firmware to be made slave.
83

Practical diagnosis example - "FrmXWcState


In the
sample configuration,
there are
two coupler with
one input
and one output
terminal.Each
coupler is in a
separate sync
unit (Hugo1, Hugo2).

LRD = LogicalRead: input data e.g. The EL1004


LWR = LogicalWrite: Output data e.g. The EL2004
BRD = BroadcastRead: Reading out the status of
all slaves
30.01.2012
EtherCAT Training

The only frame of


this configuration inclu
des: 2 Cmds (LWR) +
2 Cmds (LRD) Cmd +
1(FRG)
= 5 Commands
84

Diagnose
Inputs -> Master -> FrmXState
FrmXState: Variable of type Word (UINT)
shows the status of
the frame X. For each EtherCATcommand a bit
is reserved:

FrmXState shows bit


by bit
at the respective Ether
CAT commands that
have not beensent.
30.01.2012

Bit:
0 (0x0001) 1. EtherCAT command not sent (NOP
requested)
1 (0x0002) 2. EtherCAT command not sent (NOP
requested)
2 (0x0004) 3. EtherCAT command not sent (NOP
requested)...
14 (0x4000) 15. EtherCAT command not sent
(NOP requested)
15 (0x8000)complete frame not sent

EtherCAT Training

85

Diagnose
Inputs -> Master -> FrmXWcState

FrmXWcState shows b
it by bit
at the respective Ether
CAT commands that
have received an
invalid WcState.
30.01.2012

FrmXWcState: variable of type Word (UINT)


shows the wrong working counter status
foreach cyclic frame X.
For each EtherCAT command a bit is reserved:
Bit:
0 (0x0001)wrong working counter of 1. EtherCAT
command received
1 (0x0002)wrong working counter of 2. EtherCAT
command received
2 (0x0004)wrong working counter of 3. EtherCAT
command received...
14 (0x4000)wrong working counter of 15.
EtherCAT command received
15 (0x8000)complete frame missing

EtherCAT Training

86

Diagnose
FrmXWcState - Evaluation
From terminal 1
(EK1100) is now terminal 3
(EL2004) located.
The variable Frm0WcState reports
the diagnostic value 0x001116
bzw. 0001 00012.
The
binary is now evaluating the failu
re of the first and
5 Commands, each
characterized by bit 0 and bit 4.
Bit 0 = no output data is written
Bit 4 = Read not
successful broadcast
30.01.2012

EtherCAT Training

87

Diagnose
FrmXWcState Evaluation
An EtherCAT frame can consist of one or more commands.
These commands can be assigned different SyncUnits.
Each of these commands has an expected value of working counter.
The Master knows the number of slaves per SyncUnit that are
addressed to the respective command and calculates the
expected Working Counter.
The slaves Increment this value
If the master receives an incorrect working counter, then this
points to communication problems, to one or more slaves.

30.01.2012

EtherCAT Training

88

Diagnose
FrmXWcState Evaluation
Outputs can be switched on invalid WcState continue from the PLC to
ensure a safe state of the system.
Terminals, which are separated by the EtherCAT switch, the output after
the SyncManager watchdog (watchdog SM) from.
Input values "freeze" to view the last current value when
the WcState is invalid.
That is, although an input terminal of the affected SyncUnit is still
in surgery can be viewed old values when the WcState is invalid.
The WcState of EtherCAT slaves should be "always" be evaluated!

30.01.2012

EtherCAT Training

89

Explanation : FrmXWcState

SlaveCount: Number of slaves found


DevState: Device status information as

WORD (UINT)

30.01.2012

EtherCAT Training

90

Diagnosis of the bus system DevState (Master)


State: 0xABCD
Bit
0 (0x0001)Link error detected.
1 (0x0002)I/O locked after link error (I/O reset required)
2 (0x0004)Link error (redundancy adapter)
3 (0x0008)Missing one frame (redundancy mode)
4 (0x0010)Out of send resources (I/O reset required)
5 (0x0020)Watchdog triggered
6 (0x0040)Ethernet driver (miniport) not found
7 (0x0080) I/O reset active
8 (0x0100)At least one device in 'INIT' state
9 (0x0200)At least one device in 'PRE-OP' state
10 (0x0400)At least one device in 'SAFE-OP' state
11 (0x0800)At least one device indicates an error state
12 (0x1000)DC not in sync
30.01.2012

EtherCAT Training

91

EtherCAT Slave: WcState


Similar to the EtherCAT master and each
slave has individual diagnostic inputs
WcState: Variable of type BOOL, shows
the status of slaves working counter.
0 indicates valid Data
1 is an invalid Data.
An invalid value indicates that the
EtherCAT command is to update the inputs
and outputs an invalid value.
For further analysis, the Info-Data variables to
be used

30.01.2012

EtherCAT Training

92

Diagnosis of the bus system state (slave)


State: 0xABCD

30.01.2012

0x___1 Slave in 'INIT' state


0x___2 Slave in 'PREOP' state
0x___3 Slave in 'BOOT' state
0x___4 Slave in 'SAFEOP' state
0x___8 Slave in 'OP' state
0x0010 Slave signals error
0x0020 Invalid vendorId, productCode... Read
0x0100 Slave not present
0x0200 Slave signals link error
0x0400 Slave signals missing link
0x0800 Slave signals unexpected link
0x1000 Communication port A
0x2000Communication port B
0x4000Communication port C
0x8000Communication port D

EtherCAT Training

93

Diagnostic Information Data additional elements

Shows the frequency of the process image


update
DevId(optional): Device ID of
the EtherCAT device.
AmsNetId(optional): The AmsNetId the
EtherCAT master. The corresponding ADS
port is fixed: 0xFFFF(65535)
AdsAddr( optional ): The
variable 'AdsAddr' and
the impressive keep the
AmsNetId AMsport the slaves to
communicate with the mailbox
Chn0( optional for drives only): Channel of a
drive.
30.01.2012

EtherCAT Training

94

Online Diagnostics tab (Master)


No: physical position in the
EtherCAT ring
Addr: EtherCAT slave address
Name: Name of Slave
State: State of the
EtherCAT slave. If the
slave was not found ERR
is indicated + last validstate.
CRC: CRC count of slaves (ports
A, B, C, D if used)
Tx/Rx Errors:
be (counted from below TwinCAT)
on the network map
Lost Frames: are high,
with Tx / Rx error. Lost a frame
is accepted before Tx / Rx is
incremented.
30.01.2012

EtherCAT Training

95

Online diagnostic indicator in Topology View


For static errors can also be the fault line in the Topology View display:

30.01.2012

EtherCAT Training

96

Diagnosis of the bus


system EtherCAT Master: Emergency scan

Link State: All


participants will be
reached?
Number
of frames tocome
Scan frames st
arting with 0,
10,100,1000

30.01.2012

EtherCAT Training

97

Excersise

Cable Redundancy
EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

98

Excersise
Cable Redundancy
Cable redundancy to compensate for a disconnection between
two bus segments
To cover the entire bus system is a ring topology used
The ring topology starts by default via a second network port of the
control in both directions
In the event of redundancy - the ring is interrupted at one point are not achievable by the components supplied by the
second EtherCAT master with process data

30.01.2012

EtherCAT Training

99

Excersise
Cable redundancy - Setup

The cable redundancy is configured on the primary EtherCAT master.


For this, the entry point for the redundancy master must be chosen.
In the case of redundancy, the participants are then automatically added to
the list.

30.01.2012

EtherCAT Training

100

Excersise
Cable Redundancy - Diagnostic
Diagnosis of the system
over the system variables and slave count SlaveCount2
Evaluation of the system variable DevState
The variable count shows slave in normal operation the value 0, the
variable SlaveCount2all achievable EtherCAT slaves
In the case of
redundancy SlaveCount/SlaveCount2 shows the still accessible
slaves
In addition, over DevState and a corresponding bit values can be
diagnosed:
- 0x0001: Link Error am primren Port
- 0x0004: Link Error am Redundanzport
- 0x0008: Missing one frame
30.01.2012

EtherCAT Training

101

Praxiseinschub
Kabelredundanz Diagnose Topology View
Unterbrechung am
Redundanzport

Unterbrechungen,
Kommunikationsausfall zu
einem Klemmenblock
Klemme im 2.
Klemmenblock im
laufenden Betrieb
entfernt, dadurch
Spannungsunterbrechun
g zu nachfolgenden
Klemmen und
Kommunikationsausfall
dorthin
30.01.2012

EtherCAT Training

102

Excersise
Cable redundancy - Notes

Supplement License: TwinCAT EtherCAT Redundancy required!


TwinCAT is 2.10.1313 or TwinCAT 2.11 used
The control PC has 2 full-fledged, real-time Ethernet ports.
A parallel connection made by a EK1122 for the purpose
of cable redundancy is not permitted
The supplement EtherCAT cable redundancy guarantees from :
- the failure of Ethernet cable runs (eg between couplers EK1100/EK1101)
when the power supply of the stations is not interrupted.
- the failure of the communication part of a single terminal, when the power
supply is not interrupted to the following terminals.
Cable redundancy is only one fault-tolerant

30.01.2012

EtherCAT Training

103

XFC eXtreme Fast Control Technology


EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

104

XFC eXtreme Fast Control Technology


Various Technologies
Under the XFC technology can be summarized in three different control
technologies :

Distributed Clocks
Time-Stamp
Oversampling

When it comes to these three variants each for ultra fast I / O


terminals with extended real-time property.
In the XFC technology, it is possible to achieve response time <100us,
which were due to technical reasons has been hard to reach.
30.01.2012

EtherCAT Training

105

Distributed Clocks
Consider a regular, discrete control loop :
Actual value (input components)
Forwarding to control (communication components)
Calculate reaction (control component)
Result of setpoint output (output component)
Process (controlled system)
Crucial to the control process is both a very short
response time, as well as a deterministic, ie be exactly calculable :
actual value
Setpoint output
The temporal accuracy is therefore expected in the I / O
component and not in communication or computation unit!
30.01.2012

EtherCAT Training

106

Distributed Clocks Principles


Distributed Clocks (DC ) Refers to a
logical terminology EtherCAT network of distributed clocks
With the distributed clocks, it is possible to EtherCAT, all bus
stations locally a reproachin a very narrow
range same time (Accuracy <100 ns)
If an
EtherCAT slave supports the Distributed Clocks capability, it include
its own clock, after power is working locally first, based on its
own clock in the EtherCAT slave (quartz, oscillator, ...).
The exact synchronization is of particular importance in cases where
spatially distributed processes require simultaneous actions.
This may be the case for example in applications that run in which
several servo axes simultaneously coordinated movements.

30.01.2012

EtherCAT Training

107

Distributed Clocks
Time synchronization system
Time accuracy: 1ns
Aligned clocks have a high degree of tolerance to faultrelated delays
Since communication uses a logical ring structure, the "master
clock" run-time offset to the individual "slave clocks" to
determine accurately and easily and vice versa
which are based on the distributed clocks tracked
Distributed clocks can also provide information to the local time of
data collection :
e.g. timestamp at terminals

30.01.2012

EtherCAT Training

108

Distributed Clocks
Reference Clock / Slave Clocks
In the EtherCAT strand exists a selected EtherCAT slave, which is
the reference clock /"master
clock" (M), to synchronize the slave clocks / "daughter Clock" (S) of
the other participants and the control.
This reference clock is the System Master.

30.01.2012

EtherCAT Training

109

Distributed Clocks
Determination of the master-slave offset
The Reference Clock (M) is the first slave
in line with EtherCAT distributed clock
functionality to the EtherCAT master IPC, but can also be
selected freely
Since each slave on the round trip a short delay - both in the
local (S) itself and by the intermediate transmission line - causes the
running times (At) between the reference
clock and the respective slave clock in the synchronization of
the slave Clocks to be considered.

30.01.2012

EtherCAT Training

110

Distributed Clocks
Measuring the offset times
Measuring the offset time starts in the start phase of the slave by
a broadcast read datagram (FRG)
Each slave is made to save the time of receipt of the telegram (with
respect to its local clock) on both the outward and also on the way
back .
This saved time points are then read by the master and charged
accordingly.
These cycles are measured for all EtherCAT slaves instead
of multiple times and repeated the process time.
This enables the EtherCAT master to create a very accurate
predictor of the topology, based on the frame delays between
the EtherCAT slave.

30.01.2012

EtherCAT Training

111

Time-Stamp
Process data are usually in your
"real" format (bit digital values, word for analogue values).
The temporal evaluation of the process data can now
be made now from the communication cycle (PLC cycle time) can
be derived.
Resolution and accuracy limits!
Timestamp data types include, in addition
payload
also an associated
time stamp
Input value: When something has happened?
Baseline: When should a reaction?
30.01.2012

EtherCAT Training

112

Oversampling
Process data are normally transmitted once per
communication cycle accurate.
Temporal resolution depends on the cycle time!
A higher resolution only by reducing the cycle time.
Practical, physical limit to the control component
Oversampling data-types now allow multiple sampling of a process
data within a communication cycle.
The oversampling factor is the number of sampling between two
communication cycles
The triggering of the scanning takes the I / O component by its local
clock (DC)

30.01.2012

EtherCAT Training

113

Excersise

Distributed Clocks Timing


EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

114

Excersise
Distributed Clocks - Timing behavior
Mittwoch, 20. August 2008

Sync1 Timing-Diagramm
0

1000

2000

Datenaustausch
Master <-> Slave

Verzgerung, z.B.
bedingt durch einen
Jitter des PCs, der den
Sync1 Impuls (SyncImpuls der triggernden
Task) verschiebt

3000

Zykluszeit [s]
App

App

Shift Zeit
EC Master
112.4s

Reserve

FRAME

User Shift
500s

Reserve Shift Zeit

EC Master
112.4s

FRAME

Sync1

FRAME

App

Sync1

Sync1

Sync1
Shift Zeit
EC Master
112.4s

Verzgerung

Reserve

Reservezeit:
10% Zykluszeit
Reservezeit:
10s
Telegrammlaufzeit
10%
Zykluszeit
10 s Telegrammlaufzeit
50s Sicherheitsoffset
50 s Sicherheitsoffset

Globale Shift Zeit EC Master:

Globale Shift Zeit EC Master:


10%
Zykluszeit
10%
Zykluszeit
2s pro Knoten (z.B. EK1100)
60ns
Teilnehmer
(z.B.
EL1008)
2spropro
Knoten
(z.B.
EK1100)

60ns pro Teilnehmer (z.B. EL1008)

30.01.2012

EtherCAT Training

Datenaustausch
Master <->Slave:
Slave-Prozessdaten
sind noch nicht
bereit!

Erwarteter Zeitpunkt
des Datenaustausch:
Master <->Slave
Innerhalb der
Reserve-Zeit

Tritt dieser
Effekt
innerhalb von
5ms zwei Mal in
direkter Folge
auf, so spricht
man von einem
SyncLost
115

Distributed Clocks
Example Time Stamp / oversampling terminals
The distributed clock unit in the ESC has usually about 2
interrupts, which can be triggered timed: SYNC0 and SYNC1
If the local Distributed Clocks time with a userdefined default match time, triggers the ESC an interrupt and the
associated operations: SYNC0
Allowed time for example Beckhoff terminals Timestamp: The time
is about an event, for example, saved the arrival of a
(digital) signal and transmits the control
The ESC
can also automatically download new default values, which in this
case a cyclic sequence of actions for the ESC sequence (SYNC1) eg use Beckhoff terminals oversampling

30.01.2012

EtherCAT Training

116

Distributed Clocks
Capture - Latch 0/1
If an ESC configured, it can save the occurrence of an external
event, the current local time, so they put a capture
unit without delay in a buffer. These external events can be :

Arrival of the EtherCAT frames,


End of the EtherCAT frames,
Edge on a dedicated pin of the ESC,
Communication with a connected microcontroller
etc.

With Servo Drive AX5000 can have high-speed input


(11s) as be stored on a digitalpulse, the current position and the
process image is made available.

30.01.2012

EtherCAT Training

117

Excersise

Distributed Clocks with input channels


EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

118

Excersise
Distributed Clocks with Input Channels
In the figure, the master PC runs with his PLC to an
EtherCAT master an EtherCAT configuration with 3channel digital input terminal EL1202-0100 with Distributed Clocks
support.

30.01.2012

EtherCAT Training

119

Excersise
Reading the values from the terminals
The PLC controlled and thus the EtherCAT fieldbus operated with
1 ms cycle time
every 1 ms, the input terminals polled EL1202-0100 after their input
values.
The EL1202-0100 is now the local Distributed clock for
sampling of both input channels is used: with each
SYNC interrupt the ESC reads directly adjacent to the input value (0
or1).
The terminal puts its values into the incident shortly after EtherCAT
frame
By using the distributed clock signal, the sampling of the
inputs is highly stable in the continuous equal distance with a
deviation of <100 ns.
All EL1202 EtherCAT-0100 in the entire network by
default read their inputs at the same time, a global, independent
of their location.
30.01.2012

EtherCAT Training

120

Excersise
Distributed Clocks with Output Channels
Logic for output channels similar to that at input channels
The primary difference is
that the local slave clock sync has now to be most conveniently
by the passage of an EtherCAT frame, instead of at the input
channels before the frame.
Calculation of the global shift time for input and output slaves thus
takes place separately.
The standard established global shift time for the group
of output units is greater than the input modules.
Both lie in the meaningful range of 0 to
100% of EtherCAT cycle time.

30.01.2012

EtherCAT Training

121

Excersise

Parameterization of oversampling Terminal


EtherCAT Ultra high-speed for Automation

30.01.2012

EtherCAT Training

122

Excersise
Oversampling Digital Output EL2262
The EL2262 digital output
terminal connects the
binary output signals of the control
process level with electrical isolation.
The outputs are adjustable with
an integer multiple (oversampling factor:
n) of the controlled bus
cycle (n micro cycles per bus cycle).
The terminal would receive for
each micro-cycle, a set of
process data sequentially output.
The time base of the terminal can be
synchronized precisely with other
EtherCAT distributed
clock by participants.

30.01.2012

EtherCAT Training

123

Excersise
parameterization EL2262
The EL2262 is in the TwinCAT System Manager on an
oversampling = 200 set.
In the ESC generated in the terminal SYNC0 the interrupt with the nfold higher frequency.
At each SYNC0 signal is a new bit from the current record for each
channel read and output to the power stage.
By generating the SYNC0 pulse from the local synchronized clock in
the distributed clock composite is ensured that the output of the
output values in high temporal constant equal intervals with the
period of SYNC1 pulse (triggered PLC task) is.

30.01.2012

EtherCAT Training

124

Excersise
Oversampling factor set
Using the
tab "DC" ADJUSTING le
aves the oversampling
rate.
About "Advanced Setting
s" you can go into
the menu for
the Distributed Clocks

30.01.2012

EtherCAT Training

125

Excersise
Adavenced Settings DC
In the advanced settings of
the EL2262 to the distributed
clock, the
time of SYNC1Interrupts can
be changed.
By entering a "User defined shift
time" may be a
few microseconds of
the timecompared
with the global sync setting mov
ed forward or back.

30.01.2012

EtherCAT Training

126

Excersise
Variablendeklaration im PLC Control
For data transfer to the EL2262 is example for each channel an
array of size 25 bytes are required (200 bits / 8 = 25 bytes)

30.01.2012

EtherCAT Training

127

Excersise
Link in the System Manager

30.01.2012

EtherCAT Training

128

S-ar putea să vă placă și