TwinCAT IEC61131-3
-
Upload
nigo-villan -
Category
Documents
-
view
172 -
download
17
description
Transcript of TwinCAT IEC61131-3
26.07.20071
TwinCAT IEC61131-3
26.07.20072
Overview
Contents
Part 1IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2
Variables II Structs, Enums
Variables II Arrays
Checkbounds
Structured text
Part 3
Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.20073
The IEC 61131-3
IEC 61131-3
-1 General definitions and
typical function (cyclic processing,
process image input and output)
-2 Environmental conditions and conditioning classes
of the control and the programming devices.
(temperature, air humidity)
-3
Rules for using and implementation of
PLC programming languages
-4 Guide line for the system analysis of the user, the
system selection, the realisation of the
application, as well as maintenance and
servicing
-5Definition of the
communication via funcion blocks and communication via
access paths
(additionally to –3)
-6 Communication via
fieldbus.
-7 Fuzzy systems in the
PLC
26.07.20074
Standard guide
The PLCopen contains 3 devaluation compatible compli ance classes:
Base level
Portability level
Full compliance level
Contains IL, ST, SFC, CFC (in preparation) a few data types, standard operators,
functions, function blocks as well as local variables
Data exchange format (8 bit ASCII). Data types with 32 bit strings, Arrays and all functions and operators based on this
data type.
Here the supreme compatibility degree must exist.
26.07.20075
Functional structure of a PLC
Power supply
Communicationfunction
MMI functions
Check functions
Power supply system Operator Programmer
Executing function
Operating system
Operating program
Data
Interface function to sensors and actuators
Signal executing function
Other systems
process
26.07.20076
Communication functions
Communicationfunction
MMI functions
Check functions
Operator
Programmer
Other systems
ADS/AMS router
Ethernet, RS232, Modem
Server
ADS OCX, ADS DLL, TwinCAT OPC
Forcen, Breakpoints, single step, System
Manager, Scope View
26.07.20077
Signal executing function
Operating function
Operating system
Operating program
Data
Signal executing function
Win NT, 2000, XP
PLC Server 1, PLC Server 2, PLC Server 3, PLC Server 4,
NC Server, Cam Server
ADS-, I/O processimage
Compiled PLC project, selfdefined server
26.07.20078
Interface function between sensors and actuators
Interface function between sensors and actuators
Copy rule DP RAM <-> PA PLC
Actuators and sensors
A E
F-Field-Device
DP/PA
F-ActuatorF-Sensor
26.07.20079
Overview
Contents
Part 1IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2
Variables II Structs, Enums
Variables II Arrays
Checkbounds
Structured text
Part 3
Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.200710
Software model
Configuration
Main Motion
Resource Resource
Task1 Task2 Task1 Task2
Program Program Program Program
FB FB FB FB FB
Global and direct addressed variable
access paths
26.07.200711
Software model Example
Configuration
Main Motion
Resource PC Resource BC9000
Task1 Task2 Task1
Program Program Program
FB FB FB FB
Global and direct addressed variable
Mapping in the TwinCAT System Manager
access paths
Example PC PLC with 1 run time und zwei Task 1 BC900 ( Ethernet Controller)
26.07.200712
Overview
Contents
Part 1IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2
Variables II Structs, Enums
Variables II Arrays
Checkbounds
Structured text
Part 3
Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.200713
Identifier
Identifier serves to the individual name assignment for variables, data types, functions...
• The identifier begins with a letter or a underscore
• Followed by numbers, letters and underscore
• No difference between capital letters and small let ters
• Blank character
• Sequential underscores
• mutated vowel
Not allowed
• Special characters (!,“,§,$..)
26.07.200714
Prefix
b – Boolean r – Real s - String ST_ - Declaration of structures st - Initialisation of structuresFB_ - Declaration of function blocksfb – Initialisation of function blocks M_ - Declaration of methods
bEndschalterLinksrSollPositionsRxDaten
ST_MotorDaten (declaration)stM1Parameter (instance)
FB_Ueberlast (declaration)fbM1Ueberlast (instance)
Hungarian notation: Write part words together. The f irst letter of a part word must be a capital letter.
Prefixes are not specificated, but they make the ha ndling of the identifier easier. Here some suggestions:
26.07.200715
Key words and comments
Key words are preset indentifer by the IEC61131-3.They are fixed components of the syntax and must not be used for other purposes.
TRUE, FALSE, AND, FUNCTION,...
Using the option Auto format, the keywords are written in capital letters.
The comments are limited with the characters (* at the beginning and *)at the end.Comments can be placed there, where blank characters are allowed.Exception: inside character string literals.
(*digital inputs*)bStart AT%IX0.0:BOOL;(*Machine start*)
(*analog inputs*)TemK1 AT%IW10(*Byte 10-11*): WORD;
26.07.200716
Overview
Contents
Part 1IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2
Variables II Structs, Enums
Variables II Arrays
Checkbounds
Structured text
Part 3
Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.200717
Data types
Data types describe memory locations resp. appoint the ir features.
Type value
(Part)STRING
µ
SINT -75
USINT 181
Memory 1 0 1 1 0 1 0 1
Value type (WORD) Data width (2 Byte)Initial value (0)Value range (0..65535)
26.07.200718
Elementary data types
Type ANY-Type Key word Data width(Bit)
Initial Value range
Boolean ANY_Bit BOOL 1 FALSE TRUE/FALSE
Bit string(8) BYTE 8 0 0..16#FF
Bit string(16) WORD 16 0 0..16#FFFF
Bit string(32) DWORD 32 0 0..16#FFFF_FFFF
Short integer ANY_Num SINT 8 0 -27...27-1
Integer INT 16 0 -215...215-1
Double integer DINT 32 0 -231...231-1
Unsigned short integer USINT 8 0 0...28-1
Unsigned integer UINT 16 0 0...216-1
Unsigned double integer UDINT 32 0 0...232-1
26.07.200719
Elementary data types
Type ANY-Type Key word Data width(Bit)
Initial Value range
Slide point ANY_Real REAL 32 0.0 -1.18*10-38.. 3.4*1038
Long slide point LREAL 64 0.0 -2.22*10-308.. 1.798*10308
Date ANY_Date DATE (D) 32 D#1970-01-01
Time of day TIME_OF_DAY (TOD)
32 TOD#00:00 TOD#00:00..TOD#23:59
Date time of day
DATE_AND_TIME(DT)
32 DT#1970-01-01-00:00
time ANY_Time TIME 32 T#0ms
Sequential characters
ANY_String STRING (80+1)*8 ‚‘
26.07.200720
String
A STRING type variable can contain any string of characters. The size entry in the declaration determines how much memory space should be reserved for the variable. It refers to the number of characters in the string and can be placed in parentheses or square brackets. If no size specification is given, the default size of 80 characters will be used.
Strings are zero terminated, that means the last
character of a string is always zero. Each character
inside a string needs one byte.
VAR
strVar : STRING(3);
lenVar: INT;
sizeVar: INT;
END_VAR
VAR
strVar : STRING(3);
lenVar: INT;
sizeVar: INT;
END_VAR
26.07.200721
Special characters
If you want to add a special character into a string, you have to begin with a $-
character.
character description
$$ dollar signs
$‘ Single quotation mark
$L or $l Line feed
$N or $n New line
$P or $p Page feed
$R or $r Line break
$T or $t Tab
ACR100 (*Str. Abschluss*)
Special Characters
26.07.200722
ASCII <-> CHR
If a character in a program ought to be converted to an ASCII character, two procedures are allowed:
1. Indirectly, by interpreting the data memory different.
2. Directly via the provided function block. ASC and CHR are both included in the libraryChrAsc.lib.
(Component of the Comlib)
26.07.200723
Variables declaration el. data types
A variable owns a name, behind which a value (numbe r, string, date) hides. The name of the variable is a way description to th e declared data.Variables distinguish themselves thereby, that thei r content can be changed to the run time.
bStellerUntenLinks: BOOL:=TRUE;
Identifier Data type Initial value
The physical logical storage location of the variable is not
known by the operator(unlocated)
The degrees of freedom and the restrictions at the assignment of the identifiers can be seen
on the slides identifier and prefixes.
26.07.200724
Variables declaration el. data types
At the declaration of the variables it´s possible t o link the name with an explicit specified address. For the mapping of the inputs and outputs to the symbolic variables, the locating of variables is es sential.
bStellerUntenLinks AT%IX0.0:BOOL:=TRUE;
Identifier AT Address : Data type ;
%I
%Q
%M
ATIdentifier X
B
W
D
Byte Data type
Byte
Bit
These variables own a unique address (located)
From TwinCAT 2.8 the addressing can be done automati cally. Then the program works with not completely located variables.
bStellerUntenLinks AT%I*:BOOL:=TRUE;
26.07.200725
Overview
Contents
Part 1IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2
Variables II Structs, Enums
Variables II Arrays
Checkbounds
Structured text
Part 3
Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.200726
Validity range
Local variables are limited on the block, in which they were declared.
Global variables are known in each block inside a project.
Key words
VAR ..
END_VARVAR_INPUT ..
END_VARVAR_IN_OUT ..
END_VARVAR_OUTPUT ..
END_VAR
Key words
VAR_GLOBAL ..
END_VARVAR_CONFIG ..
END_VAR
26.07.200727
Access via the located variables
PROGRAM A
VAR
END_VAR
PROGRAM B
VARlocVar AT%MB2:WORD;END_VAR
LD %MB2
�
�
�
�
�
�
Project Machine
From program A is a direct access by address %MB2 to the local declared variable ‚locVar‘ in program B possible.
26.07.200728
Overlapping in the validity range
PROGRAM A
VARVar1 :WORD;
END_VAR
LD Var1
�
�
Project Machine
VAR_GLOBALVar1:WORD;
END_VAR
As shown in the example on the left, there is an overlapping in the validity range.In this case, the local declared variable Var1 is loaded into the accumulator.
The compiler generates no warning for this overlapping.
26.07.200729
Attributes
Attributes can be used to define special features o f variables.
Examples:
The variable(s) should be stored at the shutdown of the PLC, to be reloaded at the new start.
VAR RETAIN
Zaehler: UINT;
END_VAR
VAR PERSISTENT
Zaehler: UINT;
END_VAR
Initial values, the variables should be allocated wi th a special value at the PLC start or reset.
VAR
AccelerationTime : TIME := T#3s200ms;
END_VAR
26.07.200730
Attributes (constants)
If you want to use a mathematic, construction, or machine constant, you have to complete the regular key words VAR_GLOBAL .. END_VAR with the key word CONSTANT. This completement can also be used with local keywords. The state of these identifier is read.
VAR_GLOBAL CONSTANTpi: REAL:=3.141592654;
END_VAR
PROGRAM AVAR CONSTANT
�
END_VAR
�
�
�
Projekt Maschine
VAR_GLOBAL CONSTANT
�
END_VAR
26.07.200731
Overview
Contents
Part 1IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2
Variables II Structs, Enums
Variables II Arrays
Checkbounds
Structured text
Part 3
Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.200732
POU program organisation units
In the IEC61131-3 exists under the main generic ter m three POUs:
� Programs
� Function blocks
� Functions
The organisation POU is replaced by the task configurator.
The data POUs are replaced by multi-dimensional fie lds (ARRAY‘s).
26.07.200733
POU program organisation units
Each POU consists of a declaration part and a body.
The declaration part is the same in each IEC progra mming language. The local variables of the block are declared there.
The body is written in one of the IEC programming l anguages which include IL, ST, SFC, FBD, LD or CFC.
26.07.200734
PROGRAM PRG
Program PRG
• Call by a task (TwinCAT: One programm calls another)
• calls : FB‘s, Functions, (Programs)
• Local variable : static, i.e. the local data are av ailable at the next cycle.
• Inputs: mostly 0, but VAR_INPUT possible
• Outputs: mostlys 0, but VAR_OUTPUT possible
• Transfer by reference: VAR_IN_OUT also possible
• Debug: The local data are directly visible in the o nline mode of the PLC Control
• Using: Main programms, main, hand, automatic....
26.07.200735
Function block FB
Function block FB
• Called by programs or other FB´s
• calls : FB‘s, functions,
• Locale variable : static, i.e. the local data are a gain available at the next cycle. At multiple call multiple instances (mul itply). Each FB call can have own local data.
• Inputs: 0,1,2,3 VAR_INPUT
• Outputs: 0,1,2,3 VAR_OUTPUT
• Transfer by reference 0,1,2,3 VAR_IN_OUT
• Debug: In the online mode of PLC Control, the insta nce of the according call has to declared. After this, the loc al data are visible for each call.
• Using: multiple used function blocks, which need an own data range each. Multiple sequences....
26.07.200736
Create an instance
FUNCTION_BLOCK AVAR _INPUT
Var_IN :WORD;END_VARVAR _OUTPUT
Var_Out :BYTE;END_VARVAR
Var1 :WORD;Instanz_1: B;
END_VAR
LD Var1CAL Instanz_1
FB
PROGRAM MAINVAR
Instanz_1 :A;Instanz_2 :A;Instanz_3 :B;
END_VAR
CAL Instanz_1CAL Instanz_3
PRG Instanz_1Var_In : WORD; Var_Out : BYTE; Var_1:WORD;Instanz_1
X :REAL; Y :REAL;
Instanz_2Var_In : WORD; Var_Out : BYTE; Var_1:WORD;Instanz_1
X :REAL; Y :REAL;
Instanz_3X :REAL; Y :REAL;
FUNCTION_BLOCK B VAR_INPUT
X :REAL;END_VARVAR _OUTPUT
Y :REAL;END_VAR
�
FB
26.07.200737
Function FC
Function FC
• called by: programs, function blocks and other func tions
• calls: functions
• Local variable : temporary, i.e. the local data are only available for the operating time of the function. Afterwards this data range is used by other functions.
• Inputs: 1,2,3........ VAR_INPUT
• Outputs: exactly 1!, but structure varaibale possible . The output name is at the same time the name of the function.
• Except for TwinCAT: VAR_IN_OUT possible,
• Debug: The local variables are visible with „???“ in t he online mode of PLC Control, because these variables are multiple u sed by all functions in the cycle, and the monitoring (debug) takes place at the cycle bounds. Hepl: program development with breakpo intsBreakpoints
• Using: algorithms, at which the result is available after a pass.Scaling, compare......
26.07.200738
FC Specials
From TwinCAT 2.8: The return value can be defined directly if a new function is created.From TwinCAT 2.8: The return value can be defined directly if a new function is created.
Function nameFunction nameReturn value
The name of the „output“ is scale.
Scale can be used as local variable inside the
function(Write/Read)
Return value
The name of the „output“ is scale.
Scale can be used as local variable inside the
function(Write/Read)
InputsInputs
Local variables are only valid for the operating
time of the function
Local variables are only valid for the operating
time of the function
26.07.200739
Overview
Contents
Part 1IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2
Variables II Structs, Enums
Variables II Arrays
Checkbounds
Structured text
Part 3
Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.200740
TwinCAT System Service
The TwinCAT System Service operates as Windows NT service in the local system account. In this way, t he
TwinCAT System Service is started by Windows NT bef ore a user has logged on. As an activity symbol, the Tw inCAT System Service incorporates its icon into the task bar of the desktop. In addition, the colour of the icon in dicates
the state of the TwinCAT system.
The TwinCAT System Service is primarily responsible for starting and stopping the
TwinCAT run time system. It loads all configured servers and initialises them during the TwinCAT
system start.
.
TwinCAT stopped
TwinCAT starting.
TwinCAT running.
TwinCAT Config Mode
26.07.200741
TwinCAT System Service
The TwinCAT I/O subsystem can be reset via the TwinCAT System Service. For this, the
corresponding function must be selected in the context menu. The reset applies to all
connected field bus systems.
The event display is a programm to moniotor the events in the system. The event logging service starts automatically, if you execute Windows NT.
26.07.200742
Multitasking
TwinCAT possesses more than 62 different tasks. The default settings can use preset profiles or change the priority individu ally.
26.07.200743
Assigning the computing power
Real time operation of PLC software in the classical PLC.
Read inputs
Write outputs
Operate program
PLC cycle PLC cycle t
tPLC cycle PLC cycle
Win NT & HMI Interface
Real time operation of PLC software (1 task) on a PC w ith windows NT.
26.07.200744
Overview
Contents
Part 1IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2
Variables II Structs, Enums
Variables II Arrays
Checkbounds
Structured text
Part 3
Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.200745
Real time
Many industrial applications demand a guarantee, th at, clearly predictable and reproduceable, the system load reacts sufficient fa st to the process event in a defined time.
The real time is very important for the digital con trol. The sampling of an analog signal (actual position) with a PC should have abso lute constant distances between two measurements.
Each part process requires different reaction times . Because of this, several part processes with different features and different rea ction times can be created in one automation task.
If several tasks want to access the CPU simultaneou sly, the IEC 61131-3 defines two procedures:
1. Preemptive (interruptible execution) multi taski ng (TwinCAT)
2. Non preemptive (not interruptible execution) mul ti tasking
26.07.200746
Real time operation
� The real time operation will be achieved with deterministic time slices. The width of the time sl ices can be chosen in steps: (1000µs ... 50µs).The default setting is 1ms.
� With the begin of a new time slice, the software devices (PLC, NC) will be executed with priority control.
� The time slices will be kept with an accuracy of±±±± 15µs (Jitter). Device with the lowest priority goes to the waiting loop and waits until the CPU is free.
- 15µs +15µs
26.07.200747
Real time
The TwinCAT real-time system can be configured via the context menu of the TwinCAT System
Service.
Length of the time slice
Processor time can be assigned to the TwinCAT real-time system via the linear regulator in the figure above. On a time basis of 1 ms, this means that TwinCAT has a maximum of 800µs available each milli-second.
When the TwinCAT real-time system switches to its idle task, the processor is returned to Windows NT. The bar in the linear regulator dis-plays the current utilisation level of the real-time system. The display is averaged over 256 cycles (ms).
In this case, the current and maximum latency times in the real-time sys-tem are shown. The time by which the central system tick arrives t oo late is measured.
26.07.200748
Real time operation
� Cyclic PLC task e.g. 10ms
10ms 20ms 30ms40ms0ms
� Refinement: Behavior under TwinCAT base cycle 1 ms
0ms 1ms
80%
TwinCAT W
2ms
80%
TC W
3ms
80%
W
PLC PLC
Time slice forWindows
Time slice for TwinCAT
PLC programcyclic task
If TwinCAT does not need the (full) reserved time s lice, the scheduler provides this computing power to windows.
26.07.200749
Real time operation
� PLC tasks and drive control will be executed determ inistically with multiple tasking.
Real time operation of a PLC program and NC control with a PC
SPS cycle (e.g. 2ms) PLC cyclet
tNC cycle (e.g. 1ms) NC cycle NC cycle NC cycle
1ms 2ms 3ms 4ms 5mse.g.:
NC PLC program
Win NT & HMI Interface
1 2 3 41 2 31‘ 2‘
26.07.200750
Real time operation
� The smaller the time slice, the shorter the reaction time of the highest priority task.
� This has the consequence that the software devices must be fairly often interrupted.
� If a device is interrupted, the program stack has t o be safed. This has the consequence that the recopy expense rises.
� TwinCAT and the operating system are equal.
� For the operating system, calculating capacity is g iven regularly.
� The switch to the operating system takes place at t he earliest, as soon as all TwinCAT devices complete the processing, and at the latest at the CPU limit.
26.07.200751
Task + POU´s -> Create a new project
Before a new project starts, the following question s have to be checked:
1. What is the target platform, i.e. the device the user wants his program to run.
TwinCAT offers three different platforms.
Soft SPS (IPC)
Hard SPS (BCXXX0)
26.07.200752
Create a new project
2. In which distances and under which circumstances shall the PLC program be processed?
The IEC 61131-3 defines the task as a element of th e execution control, which is able to call several programs to execute.
At the configuration of the task one of the variant s „cyclic“ and „event“ can be chosen. TwinCAT only supports the „cyclic“ vari ant.
It´s possible to create an event driven task from a cyclic task. For this, the
program call must depend on an event.
26.07.200753
Create a new project
The task name is an identifier. Respectively the rules for the identifier obtain.
Priority of the task. The value range (0-3) is an offset on the default value 25 for the first run time. Each run time possess maximum
to four different tasks.
The interval time is always a multiple of the time slice.
26.07.200754
PLC Control Symbol bar
File
new
open
safe
Project
Start
Stop
Single step
Breakpoint
Log in
Log off
Element
Cut
Copy
Insert
Find
Find next
The field for the variables depends on the selected IEC
language.
PLC Control
26.07.200755
Main program
� The task is a trigger mechansim. A program is required to execute logical operations.
�The task calls one program. If an instance of a function block is needed, it can only be called from a program.
The features of an POU can be defined with this dia log.
�The name is an identifier. Respectively the rules for the ide ntifier obtain.
� The type of the POU depends on the problem.
� The language of the POU should be used according to the problem.
26.07.200756
Program
A program is a POU which returns several values dur ing operation. Programs are recognized globally throughout the project. All values are retained from the last time the program was run until the next.
Programs can be called by programs and function blocks.
A program call in a function is not allowed.
If a POU calls a program, and if thereby values of the program are changed, then these changes are retained the next time the p rogram is called, even if the program has been called from within another POU.
26.07.200757
Overview
Contents
Part 1
IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2Variables II Structs, Enums
Variables II Arrays
Checkbounds
Structured text
Part 3
Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.200758
Derivated data types (Variable II)
The user can create own data types on the base of e lementary data types or already created data types. The new created data ty pes are visible in the whole project.They begin with the keyword TYPE and end with END_TY PE.
Parent typeName Data type Initial value Range
DerivationName Data type Initial value
heir
New value
Range
26.07.200759
References (Alias Types) (Variable II)
You can use the user-defined reference data type to create an alternative name for a variable, constant or function block. Create your references as objects in the Object Organizer under the register card Data types.
They begin with the keyword TYPE and end with END_TYPE.
Syntax:
TYPE
<Identifier>:<Assignment term>;
END_TYPE
Example: Ads_Net_ID
TYPE
Net_ID:STRING(23);
END_TYPE
26.07.200760
Enumeration (Variable II)
Enumeration is a user-defined data type that is mad e up of a number of string constants. These constants are referred to as enume ration values. Enumeration values are recognized in all areas of t he project even if they were locally declared within aPOU. It is best to create your enumerations as objects in the Object Organizer under the register card Dat a types. They begin with the keyword TYPE and end with END_TYPE.
Syntax:TYPE <Bezeichner>:(<Enum_0> ,<Enum_1>, ...,<Enum_n>);END_TYPE
Beispiel: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
You may not use the same enumeration
value more than once.
26.07.200761
Enumeration (Variable II)
The <Identifier> can take on one of the enumeration values and will be initialized with the first one. These values are co mpatible with whole numbers which means that you can perform operations with th em just as you would with INT. You can assign a number x to the <Identif ier>. If the enumeration values are not initialized, counting will begin wit h 0. When initializing, make certain the initial values are increasing. The vali dity of the number will be reviewed at the time it is run.
VARWochenTag:Woche;
END_VAR
WochenTag:=3;
26.07.200762
Structure declaration (Variable II)
Pers_Data
Name: Firstname:
Age: Address:
form
TYPE Pers_Data :STRUCT
Name: STRING(25);Firstname: STRING(25);Age: USINT; Address: STRING(55);
END_STRUCTEND_TYPE
Identifier for the new data type
Identifier : parents data type
■
■
■
Structures are self defined data types.They are important aids for managing the process data.
Furthermore the structures are suited for capsulated data transfer to function blocks.
Structures can be used like single element variables.
26.07.200763
Structures Instances (Variable II)
P1
P3
K2
VARP1, P3 : Pers_Data;
END_VARVAR_OUTPUT
K2 : Pers_Data; END_VAR
VAR_INPUTEmployees : Pers_Data;
END_VAR
P1Name:=‚Müller‘ Firstname:=‚Peter‘Age:=32Address:=‚Postweg 34‘
P3Name:=‚Koschnik‘ Firstname:=‚Heinz‘Age:=37Address:=‚Domplatz 10‘
Name_total:= CONCAT(P3.Firstname, P3.Name)(*Heinz Koschnik*)■
■
26.07.200764
Overview
Contents
Part 1
IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2Variables II Structs, Enums
Variables II Arrays
Checkbounds
Structured text
Part 3
Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.200765
Arrays (Variable II)
Arrays describe lists resp. data arrays. All elemen ts in the arrays are from the same type. Arrays can also exist of own data types (stru ctures).
One- , two-, and three-dimensional arrays are possib le.
VARFeld_1 : ARRAY[1..10] OF BYTE; one-dimensional
Feld_2 : ARRAY[1..10, 2..5] OF UINT; two-dimensional Feld_3 :ARRAY[1..10] OF DINT; three-dimensional
END_VAR
� It´s possible to put a data array to a direct addre ssed memory position
VARFeld_1 AT%MB100:ARRAY[1..10] OF BYTE;
END_VAR
�Access to the sub-elements of a data arrayFeld_1[2] := 120; (* explicit access*)Feld_2[i,j] := EXPT(i,j); (*indicated access*)
26.07.200766
Array one-dimensional example with initialisation (Variable II)
One-dimensional
DBZeiten : ARRAY [0..6] OF TIME:= T#1s, T#2s, T#1s, 4(T#0s);
Identifier Field Data type Initial value
The field length can be done explicit or with the
aid of constants.
A dynamic change of the field size is not
possible.
Faktor Wert
0 1 2 3 4 5 6
T#1s T#2s T#1s T#0s T#0s T#0s T#0s
Access:VAR
WertAusArray : TIME;
END_VAR
WertAusArray := DBZeiten[1];
26.07.200767
Array two-dimensional example with initialisation (Variable II)
To assign for example support points, an array is w ell qualified.
Supportpoint: ARRAY [0..1, 0..6] OF REAL:= 0, 1.7, 2, 4(3.33), 6, 6(1.2);
Identifier Field Data type Initial value
Factor Value
0 1 2 3 4 5 6
0 0 1.7 2 3.33 3.33 3.33 3.33
1 6 1.2 1.2 1.2 1.2 1.2 1.2
Access:VAR
WertAusArray : REAL;
END_VAR
WertAusArray := Supportpoint[1 ,0];
26.07.200768
Array initialisation more clearly with comments (Variable II)
Example: Drive jobs for an axis
Drivejob: ARRAY [0..3, 0..1] OF LREAL :=
(* target position, velocity *)
(*Job 0*) 20.0, 30.0,
(*Job 1*) 33.75, 30.0,
(*Job 2*) 45.0, 30.0,
(*Job 3*) 70.75, 30.0;
26.07.200769
Array three-dimensional example with initialisation (Variable II)
Supportpoint : ARRAY [0..2, 0..1, 0..2] OF UINT:= 0,1,2,3,4,5,
10,11,12,13,14,15,
20,21,22,23,24,25
Identifier Array Datatype Initial value
Access:VAR
ValfromArray : UINT;
END_VAR
ValfromArray :=
Supportpoint[ 2,0,1 ];
0 1 2
3 4 5
0 1 2
0
1
0
10 11 12
13 14 15
0 1 2
0
1
1
20 21 22
23 24 25
0 1 2
0
1
2
26.07.200770
Exceed bounds (Variable II)
A dangerous state can arise in the PLC program, if an access to a range outside the data field takes place.
VARFeld_1 : ARRAY[1..10] OF BYTE;Feld_2 : ARRAY[1..10, 2..5] OF UINT;Feld_3 : ARRAY[1..10] OF DINT;
END_VAR
i:= 9 9Feld_1[i+2] := 120;
�
�
Feld_1[9]; 0
Feld_2[1,2]; 120
26.07.200771
Overview
Contents
Part 1
IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2Variables II Structs, Enums
Variables II Arrays
Check bounds
Structured text
Part 3
Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.200772
Check Bounds (FUN)
If you define a function in your project with the name CheckBounds, you can automatically check for out-of-range errors in arrays.
iMinMax
Limited value
FUNCTION CheckBounds :INT
VAR_INPUT
I,L,U : INT;
END_VAR
IF I< L THEN
CheckBounds := L;
ELSIF I > U THEN
CheckBounds := U;
ELSE
CheckBounds := I;
END_IF
Error case
Error case
„OK“ case
26.07.200773
Inserting Check Bounds 1(FUN)
CheckBounds can be copied with „Copy Project“ from a nother PLC project to the current project ( e.g. training project). Check bounds can also be created or written directley.
26.07.200774
Inserting Check Bounds 2(FUN)
So that CheckBounds is recognised by translating, th e following may NOT be changed:
-Name and type of the inputs I,L and U
-Name (CheckBounds) and return value (INT).
-In the function can be edited freely. At application of own local variables (e. g. error counter, instances of FBs) is to be considered that these are o nly temporary (at functions). Such a variable has to be declared (in this case) under the global variables.
26.07.200775
Check Bounds (FUN) mode of operation
FUNCTION CheckBounds :INT
VAR_INPUT
I,L,U : INT;
END_VAR
IF I< L THEN
CheckBounds := L;
ELSIF I > U THEN
CheckBounds := U;
ELSE
CheckBounds := I;
END_IF
Program (* User*)VAR arrVar:ARRAY[0..3] OF INT index :INTEND_VAR
index:=2;
arrVar[Checkbounds[2,0,3]:=100;
index:=index+2
arrVar[Checkbounds[4,0,3]:=100;
Access at 2->ok
Automatical call
FUNCTION CheckBounds :INT
VAR_INPUT
I,L,U : INT;
END_VAR
IF I< L THEN
CheckBounds := L;
ELSIF I > U THEN
CheckBounds := U;ELSE
CheckBounds := I;
END_IF
Checkbounds returns 3, the
access is
limited to the maximum
index
26.07.200776
Note: Further Checker functions
From TwinCAT 2.8 the following further Checker functio ns are possible:
Check division by 0
CheckDivByte
CheckDivWord
CheckDivDWord
CheckDivReal
Check value range
CheckRangeSigned
CheckRangeUnsigned
(see Appendix)
26.07.200777
Combination Structures and Arrays (1)
An array can consist of structures:
Structure:TYPE DrillPos :STRUCT
XPos: LREAL;FeedrateX: LREAL;AccelerationX: LREAL;DeccelerationX: LREAL;JerkX: LREAL;YPos: LREAL;FeedrateY: LREAL;AcceleartionY: LREAL;DeccelerationY: LREAL;JerkY: LREAL;FeedDrill: LREAL;Kuehlen: BOOL; (*Pump ?*)
END_STRUCTEND_TYPE
Declaration of the arrays :
Positions :ARRAY[0..100] OF DrillPos;
26.07.200778
Combination Structures and Arrays (1)
�Access to „Drillpos 55“:
�Access:MoveXAx (* FB Instance*)
(Execute:= TRUE,Position:= Positions[55].XPos ,Velocity:= Positions[55].FeedrateXAcceleration:= Positions[55].AccelerationX,Deceleration:= Positions[55].DeccelerationX,Jerk:= Positions[55].JerkX,Direction:= .........,Axis:= .............,);
26.07.200779
Overview
Contents
Part 1
IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2Variables II Structs, Enums
Variables II Arrays
Check bounds
Structured text
Part 3
Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.200780
ST Structured Text operators in the order of their binding strength:
Operation
Put in parenthesesFunction callExponentiationNegateBuild. complementsMultiplyDivideModuloAddSubstractCompareEqual toNot Equal toBool ANDBool XORBool OR
Symbol
(expression)Function name (parameter list)EXPT-NOT*/MOD+-<,>,<=,>==<>ANDXOROR
Binding strength
Strongest binding
Weakest binding
26.07.200781
ST Structured text: Overview about Instructions
Instruction
Assignment :=
Callin a function block
RETURN
IF
CASE
FOR
WHILE
REPEAT
EXIT
Empty instruction
Example
PosWert := 10;
Ton1(IN:=Start, PT:=T2s); Output:= Ton1.Q
RETURN;
See the following pages
;
26.07.200782
IF Instruction
Is needed to branch in a program depending on conditions.
With the IF instructions it´s not possible to jump back in the PLC cycle.
„GOTO“ is not available
Keywords:
IF THEN
ELSIF
ELSE
END_IF
e.g.:
26.07.200783
IF Instruction (1)
Instruction block
Condition
Yes
No
IF Condition THENInstruction block;
END_IF
26.07.200784
IF Instruction (2)
IF a>b THENInstruction block A;
ELSEInstruction block B;
END_IF Instruction block A
Condition
Yes
No
Instruction block B
26.07.200785
IF Instruction (3)
IF Condition1 THENInstruction block A;
ELSEIF Condition2 THEN
Instruction block B;ELSE
IF Condition3 THENInstruction block C;
ELSEInstruction block D;
END_IFEND_IF
END_IF
Instruction block A
Condition 1
YesNo
Instruction block B
Condition 2
YesNo
Condition 3
YesNo
Instruction block C Instruction block D
26.07.200786
IF Instruction (4)
IF Condition1 THENInstruction block A;
ELSIF Condition2 THENInstruction block B;
ELSIF Condition3 THENInstruction block C;
ELSEInstruction block D;
END_IF
Instruction block A
Condition 1
YesNo
Instruction block B
Condition 2
YesNo
Condition 3
YesNo
Instruction block C Instruction block D
26.07.200787
IF Instruction (5)
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
Conditions :
•BOOLEAN Variable
•Comparison
•Function calls
•Call FB Instances
•NO FB call!
What can the „BOOLEAN EXPRESSION“ be ?
26.07.200788
CASE Instruction
CASE Selection criterion OF
1: Instruction 1
2,4,6: Instruction 2
7..10 : Instruction 3
..
ELSE Default Instructions
END_CASE;
Two same values mustn´t be
available at the listing.
Instruction 1
Selection criterion = 1
Yes
No
Instruction 2
Selection criterion = 2Or 4 or 6
Yes
No
Yes
No
Instruction 3 Default Instructions
Selection criterion = 7Or 8 or 9 or 10?
26.07.200789
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
If the integer selector variable state is declared as enum, the value of the variable is visible in
the online mode.
VAR
State:Schritte;
(* State:INT also possible*)
END_VAR
26.07.200790
CASE Instruction Integer Selector Value with constants
CASE State OF
Step1: instructions; (*State=0*)
Step2: instructions; (*State=1*)
Step3..Step4: instructions; (*State=2 oder 3*)
END_CASE
VAR CONSTANT
Step1 : INT:= 0;
Step2 : INT:= 1;
Step3 : INT:= 2;
Step4 : INT:= 3;
END_VAR
VAR
State:INT;
END_VAR
26.07.200791
CASE Instruction proposal for a Statemachine
TYPE Steps :
( INIT:=0, START, AUTOMATIC, END);
END_TYPE
CASE State OF
INIT: Q0:=TRUE;
IF Transition THEN state := START ; END_IF
START: Q1:=TRUE ;
IF Transition THEN state := AUTOMATIC; END_IF
AUTOMATIC: Q2:=TRUE ;
IF Transition THEN state := END ; END_IF
END: Q3:=TRUE;
IF Transition THEN state := INIT ; END_IF
END_CASE
Instruction for the step
(Actions)
Instruction for the step
(Actions)
„step enabling condition“
(Transition)
„step enabling condition“
(Transition)
StepStep
26.07.200792
Repeat Instructions
The process flow requires the multiple handling of exactly the same program sequences, whose quantitiy is known at the run time.
Disadvantage of loops:During faulty programming, many repetitions take place infinitely.
If a continuous loop is executed this does not impair the start of the time slice (real-time). Tasks that will have a higher priority are still executed on time. Tasks that will have a lower priority are not longer executed.
1ms 2ms 3ms 4ms 5mse.g.:
1 2 3 41 1‘‘ 1‘1‘ 1‘‘‘
Forced switch toWin NT
Begin of a new time slice
26.07.200793
Loops (Overview)
Expression Work flow n cycle fix
FOR SINT/ INT /DINT
Pre repel Yes
WHILE BOOL Pre repel No
REPEAT BOOL Post repel No
All loops can be ended with the EXIT instruction, re gardless of the break-off condition.
26.07.200794
FOR loop
FOR i:=1 TO 12 BY 2 DO
Field[i]:=i*2; (*instruction*)
END_FOR
cycle nAt the beginning of the loop, the variable i is defined as start value (see example).The variable in incremented or decremented in each cycle depending on the step width (value after the keyword BY)
If i exceeds the end value (afterTO), the loop is not longer processed.
Start i:=Start value
Instruction block
cycle n
i>End value
Yes
No
I:= i+ Step width
26.07.200795
WHILE loop
i:=0;WHILE i<100 DO
Field[i]:=i*2; (*instruction*)i:=i+1;
END_WHILE
Boolean Expression
Instruction blockI:= i+ Step width
cycle n
cycle n
The instruction block of a WHILE loop is executed as long as the boolean expression supplies TRUE .The exit condition contains variableswhich can be changed in the instruction block.If the boolean expression is FALSE at the beginning, the instruction block of the WHILE loop is not processed .
Yes No
26.07.200796
REPEAT loop
i:=0;
REPEATField[i]:=i*2; (*Instruction*)i:=i+1;
UNTIL i>100
END_REPEAT
The instruction block of a REPEATloop is processed as long as (UNTIL) the boolean expression is no longer fullfilled.
The instruction block is executed at least once.
Booleanexpression
Instruction blockI:= i+ Step width
cycle n
Cycle n
Yes No
26.07.200797
FB calls in ST
TON1 (IN:= NOT TON1.Q , PT:=T#1s );
Q0:= TON1.Q
VAR
TON1:TON;
END_VAR
TON1(IN:= NOT TON1.Q, PT:=T#1s , Q=>Q0 );
from TwinCAT 2.8 :
26.07.200798
FB calls in ST explanation:
Create instance of FB
TON1 (IN:= NOT TON1.Q , PT:=T#1s );
VAR
TON1:TON;
END_VAR
Q0:= TON1.Q
Call with instance name
input parameters
Scan output
Q0:=TON1(IN:= NOT TON1.Q, PT:=T#1s);
Not possible: FB can have several outputs:
26.07.200799
FB calls in ST (alternative)
TON1.IN:= NOT TON1.Q ,
TON1. PT:=T#1s;
TON1();
Q0:= TON1.Q
VAR
TON1:TON;
END_VAR
26.07.2007100
FB calls in ST (alternative) explanation
TON1.IN:= NOT TON1.Q ;
TON1. PT:=T#1s;
TON1();
Q0:= TON1.Q;
VAR
TON1:TON;
END_VAR
Declaration
TRANSFER ONLY INPUT PARAMETER .
This is NO FB CALL!!!!!
scan output
FB CALL
26.07.2007101
FC calls in ST
Result:=Scale (x:=input, xug:=0.0, xog:=32767.0, yug :=0.0,yog:=100.0);
(* equal:*)Result:=Scale (input, 0.0, 32767.0, 0.0, 100.0);
(* equal :*)Result:=Scale (
x:= input,
xug:= 0.0,
xog:= 32767.0,
yug:= 0.0,
yog:= 100.0
);
26.07.2007102
FC calls in ST explanation:
Result := Scale (x:=input, xug:=0.0, xog:=32767.0, y ug:=0.0,yog:=100.0);
(* equal:*)
Result:=Scale (
x:= input,
xug:= 0.0,
xog:= 32767.0,
yug:= 0.0,
yog:= 100.0
);
Result CALL Input parameters
26.07.2007103
Overview
Contents
Part 1
IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2
Variables II Structs, Enums
Variables II Arrays
Checkbounds
Structured text
Part 3Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.2007104
SFC Sequential Function Chart
• Only one step is active at a time• The condition to change from one step to another is the transition.• In the action must be programmed what should be executed during the active step.
Step
Transition
ActionN
Qualifier
Following step
Transition
ActionN
Qualifier
Action,
Can be written in Structured Text, Instruction list, Ladder Diagram, Function Block Diagram and in
Sequential Function Chart .
26.07.2007105
Steps
• The activity of a step can be requested with Stepname.X.
• The duration of the activity of a step can be requested with Stepname.T .
• Both are components of a structure, which are created automatically from PLC Control. At the programming only the stepname has to be defined.
• Stepname.X and Stepname.T are local variable and can only beread.
Init
Transition
ActionN
„Normal“ Step“
Step1
Transition
ActionN
Initial stepactive at the
start
26.07.2007106
Actions
Step1
Transition
bOutputN
Action,can be a variable of type BOOL.
The variable is TRUE by activating the the step and FALSE
by leaving the step.
Transition
Step1
Transition
ActionN
Action, can be programmed in
-> Structured Text,
-> Instruction List,
-> Ladder Diagram,
-> Function block diagram, CFC/FBD
-> Sequential Function Chart
Transition
26.07.2007107
Actions, several allowed per step
Step1
Transition
STActionP
bOutputN
LDActionN
FBDActionR
26.07.2007108
Steps /alternative branches
• Only one branch can be active.
• Because only the left or the right branch is important, two transitions are necessary before the combination.
Stepa
Init
Transition
ActionN
Transition
ActionN
Transition
Transition
ActionNStepb
26.07.2007109
Steps / alternative branches
• The branches needn´t be symmetrical.
Stepa
Init
Transition
ActionN
Transition
ActionN
Transition
Transition
ActionN
Stepb
Transition
ActionN
Stepc
26.07.2007110
Steps /alternative branches
• Branches can be skipped.
Stepa
Init
Transition
ActionN
Transition
ActionN Transition
26.07.2007111
Steps /simultaneous branches
•Two branches are processed “simultaneous”.
Step_a
Init
Transition
ActionN
Transition
ActionN ActionNStep_b
Transition at the beginning of the
simultaneous branch
Transition at the „end“
Double line, symbolises the simultaneous
branch
26.07.2007112
Steps /simultaneous branches
• Simultaneous branches needn´t be symmetrical.
Step_a
Transition
Transition
ActionN
ActionN
Step_c
ActionN
Step_b
Transition
26.07.2007113
Transitions
A Transition must be of type „BOOL“. Possibilities:
• BOOLEAN Variable
• ST Instruction
• „programmed“ Transition
Init
bVariable
ActionN
BOOLEANVARIABLE
Step1
A > B
ActionN
ST instruction.
The result be must be of type BOOL.
Note: If the instruction is too long, the display will be shorten automatically.
26.07.2007114
Hides behind
Possible: FBD, LD, IL, ST.
Limitations: one network, one Instruction
sequence, no FB calls.
Transitions
Programmed Transitions
InitActionN
Step1ActionN
GTANDA
B
INPUT0
001Comment
A > B
Points to programmed
transition
„NOTHING CONNECT“
The result must be of type BOOL and is the transition
With this mark it´s only a
comment.
26.07.2007115
Final Scan
If a step is left, the processing takes exactly one more cycle. This behaviour can be used for “cleaning”in the action. E xample: Reset outputs.
ANDrelease
Step1.X
001
At the last pass the step.X = FALSE. Thus the variable
„Output “ is FALSE .
Step1
Go on
ActionN
Following step
Transition
ActionN Output
Step.X
Action processingt
t
1
0
1
0
1 Cycle
26.07.2007116
Final Scan
At a certain action the final scan leads to an unwa nted behaviour.
Step1
TRUE
ActionN
Behaviour:
Counter := Counter +1;
(*Counter increases at 2*)
Step.X
Action processingt
t
1
0
1
0
1 cycle1 cycle
Remedy: The step flag is only for one cycle 1:
IF Schritt.X THEN
Counter := Counter +1;
END_IF
(*Counter increases at 1*)
26.07.2007117
Qualifier
Controls the action processing after activating a s tep.
N: Non StoredStep
TRUE
ActionN Step.X
Action processingt
t
1
0
1
0
1 cycle
N: Non Stored
Combination in FBD
Step.X
001
Action processing
26.07.2007118
Qualifier
Controls the action processing after activating a s tep
S: SETStep
TRUE
ActionS
Combination in FBD
Step.X
Action processingt
t
1
0
1
0
1 cycle
Step.X
001
Action processing
SRS
R
26.07.2007119
Qualifier
Controls the action processing after activating a s tep
R: RESETStep
TRUE
AktionR
Combination in FBD
Step.X
001
Action processing
SRS
R
Step.X
Action processingt
t
1
0
1
0
26.07.2007120
Qualifier
Controls the action processing after activating a s tep
D: DELAY
Combination in FBD
Step.X
Action processingt
t
1
0
1
0
Delay
Step
TRUE
ActionD T#1s
Step.X
001
Action processingTON
IN
PT ET
Q
T#1s
26.07.2007121
Qualifier
Controls the action processing after activating a s tep
L: LIMITEDStep
TRUE
Action
Combination in FBD
Step.X
Action processingt
t
1
0
1
0
LIMITED
L T#1s
Step.X
Action processingt
t
1
0
1
0
Limit
Step.X
001Action processing
TONIN
PT ET
Q
T#1s
AND
26.07.2007122
Qualifier
Controls the action processing after activating a s tep
P: PULSEStep
TRUE
Action
Combination in FBD
P Step.X
Action processingt
t
1
0
1
01 cycle 1 cycle
Step.X
001
Action processing
R_TRIG
Clk Q
ATTENTION: A SECOND FLOW PROCESSES!
26.07.2007123
Qualifier, Combinations
SD: Stored and delayed
DS: Delayed and stored
SL: Stored and time limeted
26.07.2007124
Overview
Contents
Part 1
IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2
Variables II Structs, Enums
Variables II Arrays
Checkbounds
Structured text
Part 3Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.2007125
Sequential Function Chart step diagnosis
VAR
SFCEnableLimit: BOOL;
(*When it has the value TRUE, the timeouts of the s teps will be registered in SFCError. Other timeouts will be ignored.*)
SFCInit: BOOL;
(*When this boolean variable has the value TRUE the sequential function chart is set back to the Init step. The other SFC flags are reset too (i nitialization).
The Init step remains active, but is not executed, for as long as the variable has the value TRUE. It is only when SFCInit is again set to FALSE that the block can be processed normally. *)
26.07.2007126
Sequential Function Chart step diagnosis
SFCReset: BOOL;
(*This variable, of type BOOL, behaves similarly to SFCInit. Unlike the latter, however, further processing takes place after the initializa tion of the Init step. Thus for example the SFCReset flag could be re-set to FALSE in the I nit step.*)
26.07.2007127
Sequential Function Chart step diagnosis
SFCQuitError: BOOL;
(*Execution of the SFC diagram is stopped for as long as this boolean variable has the value TRUE whereby a possible timeout in the variable SFCError is reset.
All previous times in the active steps are reset wh en the variable again assumes the value FALSE.*)
SFCPause: BOOL;
(*Execution of the SFC diagram is stopped for as long as this boolean variable has the value TRUE.*)
SFCTrans: BOOL;
(*This boolean variable takes on the value TRUE whe n a transition is actuated. .*)
26.07.2007128
Sequential Function Chart step diagnosis
SFCError: BOOL;
(*This Boolean variable is TRUE when a timeout has occurred in a SFC diagram. If another timeout occurs in a program after the first one, it will not be registered unless the variable SFCError is reset first. *)
SFCErrorStep: STRING;
(*This variable is of the type STRING. If SFCError registers a timeout, in this variable is stored the name of the step which has caused the ti meout. *)
SFCErrorPOU: STRING;
(*This variable of the type STRING contains the nam e of the block in which a timeout has occurred. *)
26.07.2007129
Sequential Function Chart step diagnosis
SFCCurrentStep: : STRING;
(*This variable is of the type STRING. The name of the step is stored in this variable which is active, independently of the time monitori ng. In the case of simultaneous sequences the step is stored in the branch on the o uter right.No further timeout will be registered if a timeout occurs and the variable SFCError is not reset again.*)
26.07.2007130
Sequential Function Chart step diagnosis (from 2.8)
SFCErrorAnalyzation: STRING;
(*This variable, of type STRING, provides the trans ition expression as well as every variable in an assembled expression which gives a F ALSE result for the transition and thus produces a timeout in the preceding step. A re quirement for this is declaration of the SFCError flag, which registers the timeout. SFC ErrorAnalyzation refers back to a function called AppedErrorString in the TcSystem.Li b library. The output string separates multiple components with the symbol “|”. * )
SFCTip: BOOL;
SFCTipMode: BOOL;
(*This variables of type BOOL allow inching mode of the SFC. When this is switched on by SFCTipMode=TRUE, it is only possible to skip to the next step if SFCTip is set to TRUE. As long as SFCTipMode is set to FALSE, it is possible to skip even over transitions.*)
END_VAR
26.07.2007131
Sequential Function Chart process diagnosis
Implicit variable
26.07.2007132
• set step attributes for the step to be observed
Sequential Function Chart process diagnosis
26.07.2007133
Online (and per ADS) can be requested
26.07.2007134
Sequential Function Chart Tipmode
• insert implicit variable:
• effect:SFCTipSFCTipMode Transition
FALSETRUE TRUE
effect
Process stays in the current step
TRUETRUE TRUE Change to next step
TRUETRUE FALSE Change to next step
TRUEFALSE FALSE Process stays in the current step
FALSEFALSE TRUE Change to next step
26.07.2007135
Actions also in other IEC languages possible! (POU type : PRG, FB)
Action step2
Action step1
„Mainprogram“
26.07.2007136
Overview
Contents
Part 1
IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2
Variables II Structs, Enums
Variables II Arrays
Checkbounds
Structured text
Part 3Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.2007137
Remanent Flags Variables Attributes
These variables maintain their value, even after a power failure. When theprogram is run again, the stored values will be pro cessed further. A practical example would be an operations timer that recommences
timing after a power failure. A practical example wo uld be an operations timer that recommences timing after a power failure. All other variables
are newly initialized, either with their initialize d values or with the standard initializations.
TwinCAT supports two kind of remanent flags:
RETAIN PERSISTENT
26.07.2007138
Retain Persistent
Reset allRebuild all, ResetTo delete
To store
unlocated, located (%M)
Retain
Unlocated, located (%I, %Q, %M)Possible for
Persistent
26.07.2007139
Boot project
Requirement :
It should be possible to automate the loading and
the starting of the PLC project after switching on
the computer.
The PLC can start independent from the
user log on!
Power ON
Start NT
Start TwinCAT
Loading the boot project into the Run-Time
Start PLC
1
2
3
4
Log on
26.07.2007140
1&2
TwinCAT Auto boot Auto logon with Win NT
1
2
26.07.2007141
Create a boot project
Requirement:
1. The machine should work properly.
2. The hardware, software and the mappings are correct.
3. The PLC Control in the status online.
26.07.2007142
3&4
Enabling for loading the boot project for the run time system 1.
Number of run time systems
Enabling for loading and saving the RETAIN data for the run
time 1.
26.07.2007143
Sourcecode download
1.Goto Project/Options and press
the left mouse button.
2.A Window will open
3.Choose the Point Sourcedownload
26.07.2007144
Timing for Sourcecode download
1.Implicit at load
Every time when you open the PLC Project the Sourcecode will be written down to the controller.
2.Notice at load
If the PLC Project changed, you get a message box, when you open the project.
3.Implicit at create boot project.
Everytime you create a bootproject, the sourcecode will be transfered to the controller
26.07.2007145
Timing/Extent for Sourcecode download
1.On demand
The Sourcecode will be written down to the controller on demand.
Online/Sourcecode download
Extent
Sourcecode only
•The plc project will be written in the controller
All files
•The plc project with all libaries will be written tin the controller
26.07.2007146
Plc project open from the controller
1. You can open the actuell plc projekt direct from the controller
2. Under File/Open you can open the project direct from the plc.
26.07.2007147
Were retain and persitent data loaded successfully?
The structure component shows if the
persistent/retain data were loaded successfully.
In order to be able to view this data structure, the "PlcSystem.lib"
library must be linked in.
(Global variable)
26.07.2007148
Meaning of the flags
Reserved7
Reserved6
PERSISTENT variables: INVALID (the back-up copy was loaded, since no valid data was present)
5
PERSISTENT variables: LOADED (without error)4
Reserved3
RETAIN variables: REQUESTED (RETAIN variables should be loaded, a setting in TwinCAT System Control)2
RETAIN variables: INVALID (the back-up copy was loaded, since no valid data was present)
1
RETAIN variables: LOADED (without error)0
DescriptionBit number
26.07.2007149
How can an access to the bootdata flags take place?
Because the variable exists in the PLC, (implicit) it can be prompted directly.
TcPlcSystem.Lib
IF GETBIT32(inVal32:= SystemInfo.BootDataFlags , bitNo:=4) THEN
errLoadBootData:=FALSE;
strBootDataState:= 'PersistentData OK';
ELSIF GETBIT32(inVal32:= SystemInfo.BootDataFlags , bitNo:=5) THEN
errLoadBootData:=TRUE;
strBootDataState:= 'Error Load PersistentData ';
END_IF
26.07.2007150
Write Persistent Data on demand
With the fuction block„WritePersistentData“
(TcPlcUtilities.Lib) it is possible to initiate the writing of the Persistent
Data.
The writing takes place at the Shut Down of the PLC (standard).
While the function block is busy, the access to the Persistent Variable is
not allowed!
TcPlcUtilities.Lib
26.07.2007151
Write Persitent Data on demand, Example:
IF ReqWritePersistent THEN
fbWritePersistent(NETID:='' , PORT:=801 , START:=TR UE , TMOUT:=T#500ms );IF fbWritePersistent.ERR THEN
fbWritePersistent(START:=FALSE );ReqWritePersistent:=FALSE;
ELSIF NOT fbWritePersistent.BUSY THEN
fbWritePersistent(START:=FALSE );ReqWritePersistent :=FALSE;
END_IFEND_IF
PLC Runtime
Further start after edge
26.07.2007152
Internal Libraries
Create and test project
Delete unnecessary elements of a library
Unnecessary elements:All tasks will be deleted in the task
configuration.
All POUs, which are not to belong to thecontents of a library, are
removed.
All global variables will be deleted.
Valid: global constants, self defined data types.
Save as internal *.Lib
26.07.2007153
Overview
Contents
Part 1
IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2
Variables II Structs, Enums
Variables II Arrays
Checkbounds
Structured text
Part 3Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.2007154
CheckDivByte
26.07.2007155
CheckDivWord
26.07.2007156
CheckDivDWord
26.07.2007157
CheckDivReal
26.07.2007158
CheckRangeSigned
Variable to be checked
Checker function
26.07.2007159
CheckRangeUnsigned
Variable to be checked
Checker function
26.07.2007160
CheckRangexxx can be done with TYPES
26.07.2007161
Overview
Contents
Part 1
IEC 61131-3 Overview
Software model
Identifier
Elementary data types
Variables classes
Block types
TwinCAT System Service
Timing
Part 2
Variables II Structs, Enums
Variables II Arrays
Checkbounds
Structured text
Part 3Sequential Function Chart
Step diagnosis
Appendix
Bootprojects, Data remanence
Checker functions
Example Step by Step
26.07.2007162
Paint station (PRG)
Motor Encoder
Start
Stop
nozzle 1-3
workpiece
Part exercise:
� Switch on and off the plant
� simulate encoder
� Request marks & switch on the nozzles
� Safe state when plant off.
26.07.2007163
Creating the variables list
Identifier %I %Q Initialvalue
Type
bStart AT%IX0.0 False BOOL Global
bStop AT%IX0.1 False BOOL Global
bMotor AT %QX0.0 False BOOL Global
bDuese_1 AT %QX0.1 False BOOL Global
bDuese_2 AT %QX0.2 False BOOL Global
bDuese_3 AT %QX0.1 False BOOL Global
Marke_1 400 WORD Local
Marke_2 800 WORD Local
Marke_3 1200 WORD Local
Marke_End 1600 WORD Local
Inc 0 WORD Local
26.07.2007164
Switch on / off the plant
The switches bStart and bStop should be used as pus h-button.
To safe the status, it´s necessary to add a hold el ement (RS). There are two bistable memorys under the standard function blocks .
The dominant input is marked with xxx1.
Set
Reset1
Q1
Set1
Reset
Q1
26.07.2007165
Simulate encoder & check bounds
The encoder value is incremented each cycle around 1.This is implemented with the operator ADD. Thus a running encoder develop.
LD IncADD 1ST Inc
LD INCGT Marke_1AND (INCLT Marke_2)ST bDuese_1(
It is checked, if the encoder value stands between Marke_1 und Marke_2 .
Marke_1 GT Inc LT Marke_2
In this case, the Duese_1 is switched ST
IL
26.07.2007166
Safe state when plant off
If the plant is switched off, all nozzles and the conveyer should be stopped.
If the conveyor is stopped, the encoder should became the value 0.
LD FALSE
ST bDuese_1
ST bDuese_2
ST bDuese_3
ST bMotor
LD 0
ST Inc
Load example
26.07.2007167
System Manager
By adding a correct project (i.e. the project has been compiled in TwinCAT PLC Control without errors, and afterwards stored), the PLC configuration will be integrated into the current system configuration. The address located I/O variables will be read.
By selecting the added PLC project in the tree, the appropriate dialog IEC61131-3 appears on the right side.
At I/O configuration, you can configure the fieldbus cards (master) and the boxes (slave) for the given configuration.
26.07.2007168
Master cards
Different fieldbus systems. Each fieldbus has sever al master cards from different manufacturers (Beckhoff FC, Siemens CP, Hilscher CIF). Several different fieldb us master cards can be used parallel.
The FC 310X supports thePROFIBUS protocols:
� PROFIBUS-DP (as Master, Slave and Multi-Slave),
� PROFIBUS-DPV1 (as Master)
� PROFIBUS-MC (as Master)
DP Master
26.07.2007169
Slave modules
With the dialog “Insert I/O device” it´s possible t o insert the Beckhoff slave modules. If the Profibus Slave doesn´ t exist in the list it´s possible to select Generic Profibus Box and search the profibus box in the gse file.
Each GSE file which was read by TwinCAT, can bee seen in the list ( with the name of the producer).
26.07.2007170
Modular Structure of the Slaves modules
Beckhoff DP-Slave General DP-Slave
x N
26.07.2007171
Paint station (PRG)
contact coil
Cursor in KOP is used for inserting
new elementsLoad example Graphical elements in LD
26.07.2007172
context menue
26.07.2007173
Insert new elements
Identifier
The following elements can be inserted at the marke d cursor positions
26.07.2007174
Paint station (PRG)
Load exampleGraphical elementesin FBD
Operator
Cursor in FBD is used for inserting new elements
26.07.2007175
Context menue
26.07.2007176
Insert new elements
Dependent by the the cursor position
the following language elements
can be inserted.
The program can be expand to the left and the right side.
List of the operators (AND, OR, GE, ADD, ..) implemented by the system.