Beruflich Dokumente
Kultur Dokumente
Training fr Umsteiger
Identifier
Indentifier serves to assign individual names to variables, data types,
functions, etc.
The identifier starts with a letter or underscore
followed by numbers, letters and underscore
No distinction is made between upper and lower case
The following are not permitted
special characters (!, , , $, etc.)
spaces
consecutive underscores
umlauts
29.10.2013
Keywords
Keywords are identifiers specified by IEC61131-3. They are thus fixed
components of the syntax and therefore may not be used for other
purposes.
Examples
Standard operators AND, OR, NOT
Standard types BOOL, INT, REAL...
Types TYPE, STRUCT
Block types FUNCTION, FUNCTION_BLOCK, PROGRAM
29.10.2013
(*digitale Eingnge*)
bStart AT %IX0.0 :BOOL;(*Anlagenstart*)
(*analoge Eingnge*)
TemK1 AT %IW10 (*Byte 10-11*) :WORD;
29.10.2013
Lower
Upper
BOOL
FALSE
TRUE
Size
Prefix
x
b
BYTE
8 BIT
by
Bitstring
WORD
16 BIT
Bitstring
DWORD
32 BIT
dw
Bitstring
29.10.2013
Lower
Upper
Gre
Prfix
SINT
-127
127
8 Bit
si
USINT
255
8 BIT
usi
INT
-32768
32767
16 BIT
UINT
65535
16 BIT
ui
DINT
32 BIT
di
UDINT
32 BIT
udi
64 BIT
li
64 BIT
uli
LINT
ULINT
Detail slides
Overflows
Example: EL3102
Example: KL2531
TwinCAT Training: Programmer
29.10.2013
Lower
Upper
Size
Prefix
TIME_OF_DAY
TOD#0:0:0
TOD#23:59:
59
32 Bit
tod
DATE
D#1970:01:01
D#2106 ???
32 Bit
date
DATE_AND_TIME
DT#1970:01:01:00:00:00
DT#2106
???
32 Bit
dt
TIME
T#0s
T#49d17h2m 32BIT
47s295ms
tim
Detail slides
DT example - reading the system time
DT example - working with standard operators
29.10.2013
Lower
Upper
Size
Prefix
REAL
4 Byte
LREAL
8 Byte
lr
29.10.2013
Description
Example
Size
Prefix
STRING
String in ASCII
code. Standard
length 80
characters.
Maximum length
255. Strings are
zero-terminated
1234ABCDE
80 +1
ABCDE$R$L
ABCDE$0D$0A
Assignment
Result SIZEOF
Result LEN
sVar : STRING;
sVar:=ABC;
81
sVar1 :STRING(1);
sVar := X;
sVar: STRING(255);
sVar:=ABC;
256
29.10.2013
ASCII Code
$0D
CR
$R
$r
CR
$L
$l
Line Feed
$N
$n
New Line
$T
$t
Tab
Detail slides
Example: FIND
Example: string functions LEN, REPLACE
String conversion with Union
29.10.2013
10
Description
Example
Description
Pre
fix
WSTRING
String in Unicode
format
Level 0,Block
0x0400-0x4FFF
Cyrillic
ws
Training, seminar
Level 0
Block 0x00000x007F
Basic Latin
29.10.2013
11
Examples
BOOL
TRUE
2#1
16#1
FALSE
2#0
16#0
WORD,
DWORD
2#1010111111111110
16#AFFE
45054
INT
2#1000000000000001
16#8001
-32768
TIME
t#1h
t#60m
t#3600000ms
t#0.5d
t#12h
t#43200000ms
day
hours
min
sec
ms
ms
REAL
t#30m18s90ms
t#0.505025h
0.3333
3.333e-1
t#1818090ms
29.10.2013
12
Identifier
Data type
Initial value
bStellerUntenLinks:BOOL:=TRUE;
29.10.2013
13
AT
%I
Data type;
%Q*
29.10.2013
14
AT
%I
%Q
%M
Byte
Bit
Type
Byte
Detail slides
Detail - Replace %MB by UNION
TwinCAT Training: Programmer
29.10.2013
15
IX10.6
IX10.5
IX10.4
IX10.3
IX10.2
IX10.1
IX10.0
IB10
IB1
IB0
IW0
IX22.6
IX22.5
IB23
IX22.4
IX22.3
IB22
IX22.2
IX22.1
IB21
IW22
IB20
IW20
ID20
IX22.0
29.10.2013
16
END_VAR
VAR_OUTPUT ..
END_VAR
29.10.2013
17
Implementation
TwinCAT Training: Programmer
29.10.2013
18
Project machine
PROGRAM A
PROGRAM B
VAR
VAR
locVar AT%MB2:WORD;
END_VAR
END_VAR
LD %MB2
29.10.2013
19
PROGRAM A
VAR
Var1 :WORD;
END_VAR
Example
name:
Gvl1
LD Var1
LD Gvl1.Var1
29.10.2013
20
29.10.2013
21
Global
END_VAR
VAR CONSTANT
pi:REAL:=3.141592654;
END_VAR
TwinCAT Training: Programmer
29.10.2013
22
Parent type
Name
Data type
New value
Derivation
Name
Data type
Initial value
Area
Inherit
ance
Initial value
Area
29.10.2013
23
Syntax:
TYPE
<Bezeichner>:<Zuweisungsausdruck>;
END_TYPE
Type
Declaration
29.10.2013
24
29.10.2013
25
29.10.2013
26
29.10.2013
27
29.10.2013
28
29.10.2013
29
Use
Online
29.10.2013
30
Use
Declaration
Online
29.10.2013
31
29.10.2013
32
29.10.2013
33
1-dimensional
2-dimensional
3-dimensional
29.10.2013
34
i:= 9
Feld_1[i+2] := 120;
Feld_1[9];
Feld_2[1,2];
120
29.10.2013
35
IF I< L THEN
Error case
CheckBounds := L;
Limited
value
CheckBounds := U;
ELSE
OK case
CheckBounds := I;
END_IF
29.10.2013
36
29.10.2013
37
29.10.2013
38
Checkbounds is compiled-in
in XAR
10
Do not write,
it is called
automaticall
y
(not visible
in the code)
10
Can be checked with call build:
TwinCAT Training: Programmer
29.10.2013
39
29.10.2013
40
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
BOOL; (*Pumpe ?*)
29.10.2013
41
TRUE,
Position:=
Positions[55].XPos ,
Velocity:=
Positions[55].FeedrateX
Acceleration:=
Positions[55].AccelerationX,
Deceleration:=
Positions[55].DeccelerationX,
Jerk:=
Positions[55].JerkX,
Direction:=
.........,
Axis:=
.............,
);
TwinCAT Training: Programmer
29.10.2013
42
Block types
In IEC61131-3 there are three types of block covered by the generic
term POU (PROGRAM ORGANISATION UNIT):
Program
Function Block
Function
29.10.2013
43
29.10.2013
44
29.10.2013
45
1,2,3........ VAR_INPUT
Outputs:
precisely 1!, but structure variable possible. The name of
the output is at the same time the name of the function.
Transfer by reference
1,2,3........ VAR_IN_OUT ,
Monitoring: In the online mode of the PLC control only ??? are visible
for the local variables, since this data area is used by all functions in the
cycle and monitoring (debug) takes place only at the cycle limits.
Remedy: program development with breakpoints
Use: algorithms where the result is available after a run. Scaling,
comparison, etc.
29.10.2013
46
Symbol
Binding strength
(expression)
Strongest binding
Function name (parameter list)
EXPT
NOT
*
Same binding strength,
processing from left to right
/
(10/2*5 = 25 )
MOD
+
Same binding strength
<,>,<=,>=
=
<>
AND
XOR
OR
Weakest binding
TwinCAT Training: Programmer
29.10.2013
47
Example
Assignment:=
PosWert := 10;
RETURN
RETURN;
IF
CASE
FOR
WHILE
REPEAT
EXIT
Empty instruction
29.10.2013
48
ST: IF instruction
Is needed to branch in a program, depending on conditions. With the
IF instructions its not possible to jump back in the PLC cycle.
GOTO is also not available
Keywords:
IF
THEN
ELSIF
ELSE
END_IF
29.10.2013
49
ST: IF instruction
IF Condition THEN
Instruction block;
END_IF
No
Condition
Yes
Instruction block
29.10.2013
50
ST: IF instruction
IF a>b THEN
Instruction block A;
ELSE
Instruction block B;
END_IF
Condition
No
Yes
Instruction block A
Instruction block B
29.10.2013
51
ST: IF instruction
IF Condition1 THEN
Instruction block A;
ELSE
IF Condition2 THEN
Instruction block B;
Condition 1
ELSE
No
Yes
IF Condition3 THEN
Condition 2
Instruction block C;
ELSE
Yes
Instruction block D;
END_IF
END_IF
END_IF
Instruction
Instruction
block A
block B
No
Condition 3
No
Yes
Instruction
block C
Instruction
block D
29.10.2013
52
ST: IF instruction
IF Condition1 THEN
Instruction block A;
ELSIF Condition2 THEN
Instruction block B;
ELSIF Condition3 THEN
Instruction block C;
ELSE
Instruction block D;
END_IF
Condition 1
No
Yes
Condition 2
No
Yes
Condition 3
No
Yes
Instruction
block A
Instruction
block B
Instruction
block C
Instruction
block D
29.10.2013
53
ST: IF instruction
What can the BOOLEAN EXPRESSION be?
Conditions:
BOOLEAN variable
Comparison
Function calls
Querying of FB instances
NO FB call!
IF bVar THEN
.
IF a>b THEN
.
IF LEFT(STR:= strVar, SIZE:=7) = 'TwinCAT'
THEN
.
IF Ton1.Q THEN
.
IF Ton1(IN:=bVar, PT:=T#1s ) THEN
29.10.2013
54
ST CASE Instruction
CASE Selection criterion OF
1:
Selection criterion = 2
or 4 or 6
Instruction 1
2, 4, 6: Instruction 2
Selection
criterion = 1
7..10: Instruction 3
Selection criterion = 7
or 8 or 9 or 10?
No
Yes
..
No
ELSE
Yes
Default
instructions
No
Yes
END_CASE;
Two identical values
may not be available
for selection in the list.
Instruction 1
Instruction 2
Instruction 3
Default
instructions
29.10.2013
55
CASE State OF
0:
Q0:=TRUE;
IF Transition THEN state := 1; END_IF
1:
Q1:=TRUE;
IF Transition THEN state := 2; END_IF
2:
Step-further condition
(Transition)
Q2:=TRUE;
IF Transition THEN state := 3; END_IF
3:
Q3:=TRUE;
IF Transition THEN state := 0; END_IF
END_CASE
29.10.2013
56
Instructions;(*State=0*)
Instructions
if state = 0
IF THEN
1:
Instructions;(*State=1*)
Instructions
if state = 1
2:
Instructions;(*State=2*)
Instructions
if state = 2
3:
Instructions;(*State=3*)
Instructions
if state = 3
END_CASE
29.10.2013
57
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
29.10.2013
58
CASE State OF
INIT:
Q0:=TRUE;
IF Transition THEN state := START; END_IF
START:
Step-further condition
(Transition)
Q1:=TRUE;
IF Transition THEN state := AUTOMATIK; END_IF
Q3:=TRUE;
IF Transition THEN state := INIT; END_IF
END_CASE
TwinCAT Training: Programmer
29.10.2013
59
VAR CONSTANT
Step1 : INT:=
0;
Step1:
Instructions;(*State=0*)
Step2 : INT:=
1;
Step2:
Instructions;(*State=1*)
Step3 : INT:=
2;
Step3..Step4:
Step4 : INT:=
3;
END_CASE
END_VAR
VAR
State:INT;
END_VAR
29.10.2013
60
1
e.g.: 1ms
2
2ms
3
3ms
Begin of a new
time slice
4
4ms
1
5ms
29.10.2013
61
Expression
Processing
n cycle fix
FOR
SINT/INT/DINT
Yes
Instructions
follow condition
WHILE
BOOL
Instructions
No
follow condition
REPEAT
BOOL
Condition
follows
instructions
No
29.10.2013
62
Start i:=StartValue
Yes
i
>EndValue
No
Instruction block
i: = i + step size
FOR i:=1 TO 12 BY 2 DO
Feld[i]:=i*2;(*Anweisung*)
END_FOR
Cycle n
TwinCAT Training: Programmer
29.10.2013
63
Cycle n
Yes
Boolean
expression
No
Instruction block
i: = i + step size
Cycle n
TwinCAT Training: Programmer
29.10.2013
64
Instruction block
i:= i + step size
i:=0;
REPEAT
Feld[i]:=i*2;(*Anweisung*)
i:=i+1;
UNTIL i>100
No
Boolean
expression
Yes
END_REPEAT
Cycle n
TwinCAT Training: Programmer
29.10.2013
65
ST: FB calls in ST
VAR
TON1:TON;
END_VAR
TON1 (IN:= NOT TON1.Q , PT:=T#1s );
Q0:= TON1.Q;
29.10.2013
66
29.10.2013
67
ST: FC calls in ST
Result:=Scale (x:=Eingang, xug:=0.0, xog:=32767.0, yug:=0.0,yog:=100.0);
(* Gleichwertig:*)
Result:=Scale (Eingang, 0.0, 32767.0, 0.0, 100.0);
(* Gleichwertig:*)
Result:=Scale (
xog:=
x:=
Eingang,
xug:=
0.0,
32767.0,
yug:=
0.0,
yog:=
100.0
);
In case of functions, all inputs must be occupied
TwinCAT Training: Programmer
29.10.2013
68
ST: FC calls in ST
Result := Scale (x:=Eingang, xug:=0.0, xog:=32767.0, yug:=0.0,yog:=100.0);
Result
CALL
Input parameters
(* Gleichwertig:*)
Result:=Scale
(
x:=
xug:=
xog:=
yug:=
yog:=
);
Eingang,
0.0,
32767.0,
0.0,
100.0
29.10.2013
69