TwinCAT IEC61131-3
TwinCAT IEC61131-3
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Checkbounds
Appendix
Structured text
Variables classes
Checker functions
Block types
26.07.2007
-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)
-4
Guide line for the system
analysis of the user, the
system selection, the
realisation of the
application, as well as
maintenance and
servicing
-5
Definition of the
communication via
funcion blocks and
communication via
access paths
(additionally to 3)
-3
Rules for using
and implementation of
PLC programming
languages
-6
Communication via
fieldbus.
-7
Fuzzy systems in the
PLC
26.07.2007
Standard guide
Portability level
26.07.2007
Other systems
Operator
Programmer
MMI functions
Communication
function
Check functions
Power
supply
Operating system
Operating program
Executing
function
Data
process
26.07.2007
Communication functions
Ethernet,
RS232, Modem
Other systems
Server
MMI functions
Communication
function
Check functions
ADS/AMS router
Operator
Programmer
Forcen, Breakpoints,
single step, System
Manager, Scope View
26.07.2007
Operating
function
Operating system
Operating program
Data
PLC Server 1,
PLC Server 2,
PLC Server 3,
PLC Server 4,
NC Server,
Cam Server
26.07.2007
F-Sensor
8
F-FieldDevice
F-Actuator
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Checkbounds
Appendix
Structured text
Variables classes
Checker functions
Block types
26.07.2007
Software model
Configuration
Resource
Resource
Task2
Task1
Program
Main
Program Motion
FB
Task1
Task2
Program
Program
FB
FB
FB
FB
access paths
10
26.07.2007
Resource PC
Task2
Task1
Program
Resource BC9000
Main
Task1
Program Motion
FB
FB
Program
FB
FB
access paths
11
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Checkbounds
Appendix
Structured text
Variables classes
Checker functions
Block types
12
26.07.2007
Identifier
13
26.07.2007
Prefix
Prefixes are not specificated, but they make the handling of the identifier
easier. Here some suggestions:
Hungarian notation: Write part words together. The first letter of a part word
must be a capital letter.
b Boolean
r Real
s - String
ST_ - Declaration of structures
st - Initialisation of structures
FB_ - Declaration of function blocks
fb Initialisation of function blocks
M_ - Declaration of methods
14
bEndschalterLinks
rSollPosition
sRxDaten
ST_MotorDaten
stM1Parameter
(declaration)
(instance)
FB_Ueberlast
fbM1Ueberlast
(declaration)
(instance)
26.07.2007
15
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Checkbounds
Appendix
Structured text
Variables classes
Checker functions
Block types
16
26.07.2007
Data types
Value type
Data width
Initial value
Value range
Type
value
(Part)
STRING
SINT
-75
USINT
181
Memory
1
17
(WORD)
(2 Byte)
(0)
(0..65535)
1
26.07.2007
Type
ANY-Type
Key word
Data width
(Bit)
Initial
Value range
Boolean
ANY_Bit
BOOL
FALSE
TRUE/FALSE
Bit string(8)
BYTE
0..16#FF
Bit string(16)
WORD
16
0..16#FFFF
Bit string(32)
DWORD
32
0..16#FFFF_F
FFF
SINT
-27...27-1
Integer
INT
16
-215...215-1
Double integer
DINT
32
-231...231-1
USINT
0...28-1
Unsigned integer
UINT
16
0...216-1
UDINT
32
0...232-1
Short integer
ANY_Num
18
26.07.2007
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
LREAL
64
0.0
-2.22*10-308..
1.798*10308
DATE (D)
32
D#1970-01-01
Time of day
TIME_OF_DAY
(TOD)
32
TOD#00:00
Date time of
day
DATE_AND_TIME
(DT)
32
DT#1970-0101-00:00
ANY_Date
time
ANY_Time
TIME
32
T#0ms
Sequential
characters
ANY_String
STRING
(80+1)*8
19
TOD#00:00..
TOD#23:59
26.07.2007
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.
20
VAR
strVar :STRING(3);
lenVar: INT;
sizeVar: INT;
END_VAR
26.07.2007
Special characters
A
CR
1
0
0 (*Str. Abschluss*)
21
Special Characters
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
26.07.2007
2.
22
26.07.2007
A variable owns a name, behind which a value (number, string, date) hides.
The name of the variable is a way description to the declared data.
Variables distinguish themselves thereby, that their content can be changed
to the run time.
Identifier
Data type
Initial value
bStellerUntenLinks:BOOL:=TRUE;
26.07.2007
AT
Identifier
AT
Identifier
Address
%I
%Q
%M
W
D
Bit
Byte
Data type ;
Data type
Byte
bStellerUntenLinks AT%IX0.0:BOOL:=TRUE;
From TwinCAT 2.8 the addressing can be done automatically. Then the program
works with not completely located variables.
bStellerUntenLinks AT%I*:BOOL:=TRUE;
24
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Checkbounds
Appendix
Structured text
Variables classes
Checker functions
Block types
25
26.07.2007
Validity range
Key words
Key words
VAR ..
VAR_GLOBAL ..
END_VAR
VAR_INPUT ..
END_VAR
VAR_CONFIG ..
END_VAR
VAR_IN_OUT ..
END_VAR
END_VAR
VAR_OUTPUT ..
END_VAR
26
26.07.2007
Project Machine
PROGRAM A
PROGRAM B
VAR
VAR
locVar AT%MB2:WORD;
END_VAR
END_VAR
LD %MB2
27
26.07.2007
Project Machine
VAR_GLOBAL
Var1:WORD;
END_VAR
PROGRAM A
VAR
Var1 :WORD;
END_VAR
LD Var1
28
26.07.2007
Attributes
Attributes can be used to define special features of 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 with a special value at the PLC start
or reset.
VAR
AccelerationTime : TIME := T#3s200ms;
END_VAR
29
26.07.2007
Attributes (constants)
Projekt Maschine
VAR_GLOBAL CONSTANT
END_VAR
PROGRAM A
VAR CONSTANT
END_VAR
30
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Checkbounds
Appendix
Structured text
Variables classes
Checker functions
Block types
31
26.07.2007
In the IEC61131-3 exists under the main generic term three POUs:
Programs
Function blocks
Functions
The organisation POU is replaced by the task configurator.
32
26.07.2007
33
26.07.2007
PROGRAM PRG
Program PRG
Local variable : static, i.e. the local data are available at the next
cycle.
Debug: The local data are directly visible in the online mode of the
PLC Control
34
26.07.2007
Function block FB
Function block FB
Locale variable : static, i.e. the local data are again available at the
next cycle. At multiple call multiple instances (mulitply).
Each FB call can have own local data.
Using: multiple used function blocks, which need an own data range
each. Multiple sequences....
35
26.07.2007
Create an instance
FB
FUNCTION_BLOCK A
VAR _INPUT
Var_IN :WORD;
END_VAR
VAR _OUTPUT
Var_Out :BYTE;
END_VAR
VAR
Var1 :WORD;
Instanz_1: B;
END_VAR
LD Var1
CAL Instanz_1
36
PROGRAM MAIN
VAR
Instanz_1 :A;
Instanz_2 :A;
Instanz_3 :B;
END_VAR
PRG
CAL Instanz_1
CAL Instanz_3
FB
FUNCTION_BLOCK B
VAR_INPUT
X :REAL;
END_VAR
VAR _OUTPUT
Y :REAL;
END_VAR
Instanz_1
Var_In :WORD;
Var_Out :BYTE;
Var_1:WORD;
Instanz_1
X :REAL;
Y :REAL;
Instanz_2
Var_In :WORD;
Var_Out :BYTE;
Var_1:WORD;
Instanz_1
X :REAL;
Y :REAL;
Instanz_3
X :REAL;
Y :REAL;
26.07.2007
Function FC
Function FC
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.
Outputs: exactly 1!, but structure varaibale possible. The output name
is at the same time the name of the function.
Debug: The local variables are visible with ??? in the online mode of
PLC Control, because these variables are multiple used by all
functions in the cycle, and the monitoring (debug) takes place at the
cycle bounds. Hepl: program development with breakpoints
Breakpoints
37
26.07.2007
FC Specials
Function name
Return value
The name of the
output is scale.
Inputs
Local variables are only
valid for the operating
time of the function
38
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Checkbounds
Appendix
Structured text
Variables classes
Checker functions
Block types
39
26.07.2007
26.07.2007
26.07.2007
Multitasking
TwinCAT possesses more than 62 different tasks. The default settings can
use preset profiles or change the priority individually.
42
26.07.2007
Operate program
Win NT & HMI Interface
PLC cycle
PLC cycle
Real time operation of PLC software (1 task) on a PC with windows NT.
PLC cycle
43
PLC cycle
t
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Checkbounds
Appendix
Structured text
Variables classes
Checker functions
Block types
44
26.07.2007
Real time
45
26.07.2007
46
- 15s +15s
26.07.2007
Real time
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 too late is measured.
47
26.07.2007
20ms
10ms
30ms
0ms
40ms
80%
TwinCAT
0ms
80%
TC
1ms
PLC
PLC
80%
W
2ms
If TwinCAT does not need the (full) reserved time slice, the scheduler provides
this computing power to windows.
48
26.07.2007
PLC program
e.g.: 1ms
NC cycle
(e.g. 1ms)
SPS cycle
49
2ms
3ms
4ms
NC cycle
NC cycle
NC cycle
(e.g. 2ms)
3
5ms
t
t
PLC cycle
26.07.2007
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 to 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 given regularly.
The switch to the operating system takes place at the earliest, as soon as all
TwinCAT devices complete the processing, and at the latest at the CPU limit.
50
26.07.2007
Hard SPS
(BCXXX0)
51
26.07.2007
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 the execution control, which
is able to call several programs to execute.
At the configuration of the task one of the variants cyclic and event can
be chosen. TwinCAT only supports the cyclic variant.
52
26.07.2007
26.07.2007
File
Project
Element
new
Start
Cut
open
Stop
Copy
safe
Single step
Insert
Breakpoint
Find
Log in
Find next
Log off
PLC Control
54
26.07.2007
Main program
55
26.07.2007
Program
56
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Checkbounds
Appendix
Structured text
Variables classes
Checker functions
Block types
57
26.07.2007
The user can create own data types on the base of elementary data types or
already created data types. The new created data types are visible in the
whole project.
They begin with the keyword TYPE and end with END_TYPE.
Parent type
Name
Data type
New value
Derivation
58
Name
Data type
Initial value
Range
Initial value
Range
h
e
i
r
26.07.2007
Syntax:
TYPE
<Identifier>:<Assignment term>;
END_TYPE
Example: Ads_Net_ID
TYPE
Net_ID:STRING(23);
END_TYPE
59
26.07.2007
60
The <Identifier> can take on one of the enumeration values and will be
initialized with the first one. These values are compatible with whole numbers
which means that you can perform operations with them just as you would
with INT. You can assign a number x to the <Identifier>. If the enumeration
values are not initialized, counting will begin with 0. When initializing, make
certain the initial values are increasing. The validity of the number will be
reviewed at the time it is run.
VAR
WochenTag:Woche;
END_VAR
WochenTag:=3;
61
26.07.2007
form
Pers_Data
Name:
Firstname:
Age:
Address:
TYPE Pers_Data :
STRUCT
Name: STRING(25);
Firstname: STRING(25);
Age:USINT;
Address: STRING(55);
END_STRUCT
END_TYPE
62
26.07.2007
Name:=Mller
Firstname:=Peter
Age:=32
Address:=Postweg 34
P1
K2
P3
Name:=Koschnik
Firstname:=Heinz
Age:=37
Address:=Domplatz 10
P3
VAR
P1, P3 : Pers_Data;
END_VAR
VAR_OUTPUT
K2 : Pers_Data;
END_VAR
63
VAR_INPUT
Employees: Pers_Data;
END_VAR
Name_total:=CONCAT(P3.Firstname, P3.Name)
(*Heinz Koschnik*)
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Checkbounds
Appendix
Structured text
Variables classes
Checker functions
Block types
64
26.07.2007
Arrays describe lists resp. data arrays. All elements in the arrays are from the same
type. Arrays can also exist of own data types (structures).
One- , two-, and three-dimensional arrays are possible.
VAR
Feld_1 :ARRAY[1..10] OF BYTE;
Feld_2 :ARRAY[1..10, 2..5] OF UINT;
:ARRAY[1..10] OF DINT;
END_VAR
one-dimensional
two-dimensional
Feld_3
three-dimensional
26.07.2007
Identifier
Field
Data type
Initial value
Wert
T#1s
T#2s
T#1s
T#0s
T#0s
T#0s
T#0s
Access:
VAR
WertAusArray : TIME;
END_VAR
WertAusArray := DBZeiten[1];
66
26.07.2007
Identifier
Field
Data type
Initial value
1.7
Value
Access:
VAR
WertAusArray : REAL;
END_VAR
1.2
67
1.2
1.2
1.2
1.2
1.2
26.07.2007
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;
68
26.07.2007
Identifier
Array
Datatype
Initial value
2
1
0
1
23 24 25
20 21 22
13 14 15
5
0
10 11 12
0
Access:
VAR
ValfromArray : UINT;
END_VAR
ValfromArray
:=
Supportpoint[ 2,0,1 ];
2
69
26.07.2007
VAR
Feld_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
Feld_1[i+2] := 120;
Feld_1[9];
Feld_2[1,2];
120
70
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Check bounds
Appendix
Structured text
Variables classes
Checker functions
Block types
71
26.07.2007
IF I< L THEN
Error case
CheckBounds := L;
i
Min
Max
CheckBounds := U;
ELSE
OK case
CheckBounds := I;
END_IF
72
26.07.2007
CheckBounds can be copied with Copy Project from another PLC project to
the current project ( e.g. training project). Checkbounds can also be created or
written directley.
73
26.07.2007
74
26.07.2007
Program (* User*)
VAR
arrVar:ARRAY[0..3] OF INT
index :INT
END_VAR
VAR_INPUT
I,L,U : INT;
END_VAR
Automatical
call
IF I< L THEN
CheckBounds := L;
ELSIF I > U THEN
CheckBounds := U;
index:=2;
arrVar[Checkbounds[2,0,3]:=100;
Access at 2
->ok
ELSE
CheckBounds := I;
END_IF
FUNCTION CheckBounds :INT
index:=index+2
VAR_INPUT
I,L,U : INT;
arrVar[Checkbounds[4,0,3]:=100;
END_VAR
IF I< L THEN
CheckBounds := L;
Checkbounds
returns 3, the
access is
limited to the
maximum
index
75
CheckBounds := U;
ELSE
CheckBounds := I;
END_IF
26.07.2007
From TwinCAT 2.8 the following further Checker functions are possible:
Check division by 0
CheckDivByte
CheckDivWord
CheckDivDWord
CheckDivReal
76
26.07.2007
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
BOOL; (*Pump ?*)
26.07.2007
78
TRUE,
Positions[55].XPos ,
Positions[55].FeedrateX
Positions[55].AccelerationX,
Positions[55].DeccelerationX,
Positions[55].JerkX,
.........,
.............,
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Check bounds
Appendix
Structured text
Variables classes
Checker functions
Block types
79
26.07.2007
ST Structured Text
operators in the order of their binding strength:
Operation
Symbol
Binding strength
Put in parentheses
Function call
Exponentiation
Negate
Build. complements
Multiply
Divide
Modulo
Add
Substract
Compare
Equal to
Not Equal to
Bool AND
Bool XOR
Bool OR
(expression)
Function name (parameter list)
EXPT
NOT
*
/
MOD
+
<,>,<=,>=
=
<>
AND
XOR
OR
Strongest
binding
80
Weakest binding
26.07.2007
Instruction
Example
Assignment :=
PosWert := 10;
RETURN
RETURN;
IF
CASE
FOR
WHILE
REPEAT
EXIT
Empty instruction
81
26.07.2007
IF Instruction
Keywords:
IF
With the IF instructions its not
possible to jump back in the PLC cycle.
THEN
ELSIF
ELSE
END_IF
e.g.:
82
26.07.2007
IF Instruction (1)
Condition
IF Condition THEN
Instruction block;
END_IF
No
Yes
Instruction block
83
26.07.2007
IF Instruction (2)
Condition
IF a>b THEN
Instruction block A;
ELSE
Instruction block B;
END_IF
84
No
Yes
Instruction block A
Instruction block B
26.07.2007
IF Instruction (3)
Condition 1
No
Yes
Condition 2
No
Yes
Condition 3
No
Yes
Instruction block A
Instruction block B
85
Instruction block C
IF Condition1 THEN
Instruction block A;
ELSE
IF Condition2 THEN
Instruction block B;
ELSE
IF Condition3 THEN
Instruction block C;
ELSE
Instruction block D;
END_IF
END_IF
END_IF
Instruction block D
26.07.2007
IF Instruction (4)
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
86
Instruction block B
Instruction block C
Instruction block D
26.07.2007
IF Instruction (5)
What can the BOOLEAN EXPRESSION be ?
Conditions :
BOOLEAN Variable
Comparison
Function calls
Call FB Instances
NO FB call!
87
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
26.07.2007
CASE Instruction
Instruction 1
2,4,6:
Instruction 2
7..10 :
Instruction 3
Selection criterion = 1
Selection criterion = 2
Or 4 or 6
No
Selection criterion = 7
Or 8 or 9 or 10?
Yes
No
Yes
..
ELSE
No
Default
Instructions
Yes
Instruction 1
Instruction 2
Instruction 3
Default Instructions
END_CASE;
26.07.2007
CASE State OF
Enum Typ:
TYPE Schritte :
( INIT:=0, START, AUTOMATIK, ENDE);
END_TYPE
INIT:
instructions;(*State=0*)
START:
instructions;(*State=1*)
AUTOMATIK:
instructions;(*State=2*)
ENDE:
instructions;(*State=3*)
END_CASE
VAR
State:Schritte;
(* State:INT also possible*)
END_VAR
89
26.07.2007
VAR CONSTANT
Step1 : INT:= 0;
Step2 : INT:= 1;
CASE State OF
Step3 : INT:= 2;
Step1:
instructions;(*State=0*)
Step4 : INT:= 3;
Step2:
instructions;(*State=1*)
Step3..Step4:
END_VAR
END_CASE
VAR
State:INT;
END_VAR
90
26.07.2007
CASE State OF
(Actions)
INIT:
Q0:=TRUE;
IF Transition THEN state := START; END_IF
START:
Q1:=TRUE;
Step
AUTOMATIC: Q2:=TRUE;
IF Transition THEN state := END; END_IF
END:
Q3:=TRUE;
IF Transition THEN state := INIT; END_IF
END_CASE
91
26.07.2007
Repeat Instructions
Disadvantage of loops:
During faulty programming, many
repetitions take place infinitely.
Forced switch to
Win NT
e.g.: 1ms
2ms
92
3
3ms
Begin of a new
time slice
4
4ms
1
5ms
26.07.2007
Loops (Overview)
All loops can be ended with the EXIT instruction, regardless of the
break-off condition.
Expression
FOR
Work flow
n cycle fix
SINT/ INT /
DINT
Pre repel
Yes
WHILE
BOOL
Pre repel
No
REPEAT
BOOL
Post repel
No
93
26.07.2007
FOR loop
cycle n
At 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 (after
TO), the loop is not longer
processed.
i
>End value
Yes
No
Instruction block
FOR i:=1 TO 12 BY 2 DO
Field[i]:=i*2;(*instruction*)
END_FOR
94
cycle n
26.07.2007
WHILE loop
cycle n
The instruction block of a WHILE loop
is executed as long as the boolean
expression supplies TRUE .
The exit condition contains variables
which 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.
i:=0;
WHILE i<100 DO
Field[i]:=i*2;(*instruction*)
i:=i+1;
END_WHILE
95
Yes
Boolean
Expression
No
Instruction block
I:= i+ Step width
cycle n
26.07.2007
REPEAT loop
Cycle n
The instruction block of a REPEAT
loop is processed as long as
(UNTIL) the boolean expression is
no longer fullfilled.
Instruction block
I:= i+ Step width
i:=0;
REPEAT
Field[i]:=i*2;(*Instruction*)
i:=i+1;
UNTIL i>100
END_REPEAT
96
Yes
Boolean
expression
No
cycle n
26.07.2007
FB calls in ST
VAR
TON1:TON;
END_VAR
TON1 (IN:= NOT TON1.Q , PT:=T#1s );
Q0:= TON1.Q
from TwinCAT 2.8 :
97
26.07.2007
FB calls in ST explanation:
Create instance of FB
VAR
TON1:TON;
END_VAR
Q0:= TON1.Q
26.07.2007
FB calls in ST (alternative)
VAR
TON1:TON;
END_VAR
TON1.IN:= NOT TON1.Q ,
TON1. PT:=T#1s;
TON1();
Q0:= TON1.Q
99
26.07.2007
Declaration
VAR
TRANSFER ONLY INPUT
PARAMETER .
This is
NO FB CALL!!!!!
TON1:TON;
END_VAR
FB CALL
Q0:= TON1.Q;
26.07.2007
FC calls in ST
Result:=Scale
(* equal:*)
Result:=Scale
(* equal :*)
Result:=Scale
101
(
x:=
xug:=
xog:=
yug:=
yog:=
);
input,
0.0,
32767.0,
0.0,
100.0
26.07.2007
FC calls in ST explanation:
Result
CALL
(* equal:*)
Result:=Scale (
x:=
xug:=
xog:=
yug:=
yog:=
);
102
Input parameters
input,
0.0,
32767.0,
0.0,
100.0
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Checkbounds
Appendix
Structured text
Variables classes
Checker functions
Block types
103
26.07.2007
Step
N
Transition
Following
step
Action
Qualifier
Action
Transition
Action,
Qualifier
104
26.07.2007
Steps
Initial step
active at the
start
Init
N
Transition
Action
Normal
Step
Step1
N
Action
Transition
105
26.07.2007
Actions
Transition
Transition
Step1
N
Action
Step1
N
bOutput
Transition
Transition
Action,
can be a variable of type BOOL.
The variable is TRUE by
activating the the step and FALSE
by leaving the step.
106
26.07.2007
Transition
Step1
107
bOutput
STAction
LDAction
FBDAction
26.07.2007
Init
N
Action
Transition
Stepa
Stepb
N
Transition
108
Action
Action
Transition
26.07.2007
Init
N
Action
Transition
Transition
Stepb
N
Stepa
N
Action
Action
Transition
Stepc
Transition
Action
Transition
109
26.07.2007
Action
Action
Transition
Stepa
Transition
Transition
110
26.07.2007
Init
N
Action
Transition at the
beginning of the
simultaneous
branch
Transition
Step_a
Double line,
symbolises the
simultaneous
branch
Step_b
N
Transition
111
Action
Action
Transition at
the end
26.07.2007
Simultaneous branches
neednt be symmetrical.
Transition
Step_b
N
Action
Action
Transition
Step_a
N
Action
Step_c
Transition
112
26.07.2007
Transitions
BOOLEAN Variable
Action
ST Instruction
programmed Transition
BOOLEAN
VARIABLE
bVariable
Step1
N
Action
ST instruction.
A>B
113
26.07.2007
Transitions
Programmed Transitions
Init
N
Action
With this
mark its only a
comment.
A>B
NOTHING CONNECT
Step1
N
Action
001
Comment
GT
AND
B
Hides behind
Possible: FBD, LD, IL, ST.
Points to
programmed
transition
114
INPUT0
Final Scan
If a step is left, the processing takes exactly one more cycle. This
behaviour can be used for cleaningin the action. Example: Reset
outputs.
Step.X
1
0
Step1
Action
t
Action processing
1
0
Go on
t
1 Cycle
Following
step
001
Action
release
AND
Output
Step1.X
Transition
At the last pass the step.X =
FALSE. Thus the variable
Output is FALSE .
115
26.07.2007
Final Scan
At a certain action the final scan leads to an unwanted behaviour.
Step1
Action
Step.X
1
TRUE
0
t
Action processing
Behaviour:
Counter := Counter +1;
0
t
1 cycle
1 cycle
26.07.2007
Qualifier
Controls the action processing after activating a step.
N: Non Stored
Step
Action
Step.X
1
0
TRUE
t
Action processing
1
0
N: Non Stored
t
1 cycle
Combination in FBD
001
Step.X
117
Action processing
26.07.2007
Qualifier
Controls the action processing after activating a step
S: SET
Step
Action
Step.X
1
0
TRUE
t
Action processing
1
0
t
1 cycle
Combination in FBD
001
Step.X
SR
Action processing
118
26.07.2007
Qualifier
Controls the action processing after activating a step
R: RESET
Step
Aktion
Step.X
1
0
TRUE
t
Action processing
1
0
t
Combination in FBD
001
SR
Action processing
Step.X
119
26.07.2007
Qualifier
Controls the action processing after activating a step
D: DELAY
Step
D T#1s
Action
Step.X
1
0
TRUE
t
Action processing
1
0
Delay
Combination in FBD
001
Step.X
T#1s
120
TON
IN
Q
PT
Action processing
ET
26.07.2007
Qualifier
Controls the action processing after activating a step
L: LIMITED
Step
L T#1s
Action
Step.X
1
0
TRUE
t
Action processing
1
0
LIMITED
Combination in FBD
Step.X
1
001
AND
Step.X
T#1s
TON
IN
Q
PT
ET
Action processing
0
t
Action processing
1
0
Limit
121
26.07.2007
Qualifier
Controls the action processing after activating a step
P: PULSE
Step
Action
Step.X
1
0
TRUE
t
Action processing
1
0
1 cycle
1 cycle
Combination in FBD
001
R_TRIG
Step.X
122
Clk
Action processing
26.07.2007
Qualifier, Combinations
123
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Checkbounds
Appendix
Structured text
Variables classes
Checker functions
Block types
124
26.07.2007
VAR
SFCEnableLimit:
BOOL;
(*When it has the value TRUE, the timeouts of the steps 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 (initialization).
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. *)
125
26.07.2007
SFCReset:
BOOL;
(*This variable, of type BOOL, behaves similarly to SFCInit. Unlike the latter, however,
further processing takes place after the initialization of the Init step. Thus for example
the SFCReset flag could be re-set to FALSE in the Init step.*)
126
26.07.2007
SFCQuitError:
BOOL;
SFCPause:
BOOL;
SFCTrans:
BOOL;
(*This boolean variable takes on the value TRUE when a transition is actuated. .*)
127
26.07.2007
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 timeout. *)
SFCErrorPOU:
STRING;
(*This variable of the type STRING contains the name of the block in which a timeout
has occurred. *)
128
26.07.2007
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 monitoring. In the case of simultaneous
sequences the step is stored in the branch on the outer right.
No further timeout will be registered if a timeout occurs and the variable SFCError is not
reset again.*)
129
26.07.2007
SFCErrorAnalyzation:
STRING;
(*This variable, of type STRING, provides the transition expression as well as every
variable in an assembled expression which gives a FALSE result for the transition and
thus produces a timeout in the preceding step. A requirement for this is declaration of
the SFCError flag, which registers the timeout. SFCErrorAnalyzation refers back to a
function called AppedErrorString in the TcSystem.Lib 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
130
26.07.2007
Implicit variable
131
26.07.2007
132
26.07.2007
133
26.07.2007
effect:
SFCTipMode
SFCTip
Transition
effect
TRUE
TRUE
TRUE
FALSE
FALSE
FALSE
TRUE
TRUE
TRUE
FALSE
TRUE
TRUE
FALSE
FALSE
TRUE
134
Action step1
Action step2
135
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Checkbounds
Appendix
Structured text
Variables classes
Checker functions
Block types
136
26.07.2007
These variables maintain their value, even after a power failure. When the
program is run again, the stored values will be processed further. A
practical example would be an operations timer that recommences
timing after a power failure. A practical example would be an operations
timer that recommences timing after a power failure. All other variables
are newly initialized, either with their initialized values or with the
standard initializations.
TwinCAT supports two kind of remanent flags:
RETAIN
137
PERSISTENT
26.07.2007
Retain Persistent
Retain
Persistent
To store
To delete
Reset all
Possible for
138
26.07.2007
Boot project
Power ON
Requirement :
It should be possible to
automate the loading and
the starting of the PLC
project after switching on
the computer.
139
Start
NT
Start TwinCAT
Start PLC
Log on
26.07.2007
1&2
1
2
140
Auto logon
with Win NT
26.07.2007
Requirement:
1.
2.
The hardware,
software and the
mappings are correct.
3.
141
26.07.2007
3&4
Number of run time systems
142
Sourcecode download
143
26.07.2007
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
144
26.07.2007
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
145
26.07.2007
146
26.07.2007
147
26.07.2007
Description
Reserved
Reserved
Reserved
148
26.07.2007
IF
26.07.2007
TcPlcUtilities.Lib
150
26.07.2007
IF ReqWritePersistent THEN
fbWritePersistent(START:=FALSE );
ReqWritePersistent:=FALSE;
ELSIF NOT fbWritePersistent.BUSY THEN
PLC Runtime
fbWritePersistent(START:=FALSE );
ReqWritePersistent:=FALSE;
END_IF
END_IF
151
26.07.2007
Internal Libraries
Unnecessary elements:
All tasks will be deleted in the task
configuration.
Delete unnecessary
elements of a library
152
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Checkbounds
Appendix
Structured text
Variables classes
Checker functions
Block types
153
26.07.2007
CheckDivByte
154
26.07.2007
CheckDivWord
155
26.07.2007
CheckDivDWord
156
26.07.2007
CheckDivReal
157
26.07.2007
CheckRangeSigned
Variable to be
checked
Checker function
158
26.07.2007
CheckRangeUnsigned
Variable to be
checked
Checker function
159
26.07.2007
160
26.07.2007
Overview
Contents
Part 1
Part 2
Part 3
Software model
Variables II Arrays
Step diagnosis
Identifier
Checkbounds
Appendix
Structured text
Variables classes
Checker functions
Block types
161
26.07.2007
nozzle 1-3
Start
Stop
workpiece
Encoder
Motor
Part exercise:
Switch on and off the plant
simulate encoder
Request marks & switch on the nozzles
Safe state when plant off.
162
26.07.2007
Identifier
%I
bStart
bStop
%Q
Initial
value
Type
AT%IX0.0
False
BOOL
Global
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
WORD
Local
163
26.07.2007
Set
Set1
Reset1
Reset
Q1
Q1
164
26.07.2007
LD
Inc
ADD 1
ST
Inc
LD
GT
AND
LT
ST
INC
Marke_1
(INC
Marke_2)
bDuese_1(
IL
165
26.07.2007
LD
FALSE
ST
bDuese_1
ST
bDuese_2
ST
bDuese_3
ST
bMotor
LD
ST
Inc
Load example
166
26.07.2007
System Manager
167
26.07.2007
Master cards
DP Master
168
26.07.2007
Slave modules
With the dialog Insert I/O device its possible to insert the
Beckhoff slave modules. If the Profibus Slave doesnt exist in the
list its possible to select Generic Profibus Box and search the
profibus box in the gse file.
169
26.07.2007
Beckhoff DP-Slave
General DP-Slave
xN
170
26.07.2007
Load example
contact
Graphical elements in LD
Cursor in KOP is
used for inserting
new elements
coil
171
26.07.2007
context menue
172
26.07.2007
Identifier
26.07.2007
Load example
Graphical elementes
in FBD
Operator
174
26.07.2007
Context menue
175
26.07.2007
Dependent by the
the cursor position
the following
language elements
can be inserted.
176
26.07.2007