You are on page 1of 69

TR3020 | Training for new users | Overview

TwinCAT 3 New Automation Technology

Training fr Umsteiger

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

TwinCAT Training: Programmer

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

TwinCAT Training: Programmer

29.10.2013

Keywords and comments


The comments are delimited by character strings with (* or *) at the beginning and at the end. Comments may be placed wherever spaces are also permitted. Exception: within string literals.

(*digitale Eingnge*) bStart AT %IX0.0 :BOOL;(*Anlagenstart*) (*analoge Eingnge*) TemK1 AT %IW10 (*Byte 10-11*) :WORD;

Comments to the end of the line bStart AT %IX0.0 :BOOL; // Anlagenstart

TwinCAT Training: Programmer

29.10.2013

Elementary data types


Type BOOL BYTE WORD DWORD Lower FALSE Upper TRUE 8 BIT 16 BIT 32 BIT Size Prefix x b by w dw Bitstring Bitstring Bitstring

TwinCAT Training: Programmer

29.10.2013

Elementary data types


Typ SINT USINT INT UINT DINT UDINT LINT ULINT 0 Lower -127 0 -32768 0 -134 217 728 0 Upper 127 255 32767 65535 134 217 727 4294 967 295 Gre 8 Bit 8 BIT 16 BIT 16 BIT 32 BIT 32 BIT 64 BIT 64 BIT Prfix si usi i ui di udi li uli

Detail slides Overflows Example: EL3102 Example: KL2531


TwinCAT Training: Programmer 29.10.2013 6

Data types 1: Elementary data types


Type TIME_OF_DAY DATE DATE_AND_TIME TIME Lower TOD#0:0:0 D#1970:01:01
DT#1970:01:01:00:00:00

Upper TOD#23:59: 59 D#2106 ??? DT#2106 ???

Size 32 Bit 32 Bit 32 Bit

Prefix tod date dt tim

T#0s

T#49d17h2m 32BIT 47s295ms

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

TwinCAT Training: Programmer

29.10.2013

Elementary data types


Type REAL LREAL Lower Upper Size 4 Byte 8 Byte Prefix r lr

TwinCAT Training: Programmer

29.10.2013

Data types: STRING


Type STRING Description String in ASCII code. Standard length 80 characters. Maximum length 255. Strings are zero-terminated Example 1234ABCDE ABCDE$R$L ABCDE$0D$0A Size 80 +1 Prefix s

String length specifications Example declaration


sVar : STRING; sVar1 :STRING(1); sVar: STRING(255);

Assignment sVar:=ABC; sVar := X; sVar:=ABC;

Result SIZEOF 81 2 256

Result LEN 3 1 3

TwinCAT Training: Programmer

29.10.2013

Data types: STRING


Constants $<2 Hex values> $0D $R $L $N $T $r $l $n $t ASCII Code CR CR Line Feed New Line Tab

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

TwinCAT Training: Programmer

29.10.2013

10

Data types: WSTRING


Type WSTRING Description String in Unicode format Example Description Level 0,Block 0x0400-0x4FFF Cyrillic Pre fix ws

Training, seminar Level 0 Block 0x00000x007F Basic Latin

TwinCAT Training: Programmer

29.10.2013

11

Data types: Examples of literals


Variable Type BOOL WORD, DWORD INT TIME
d h m s ms day hours min sec ms

Examples TRUE FALSE 2#1 2#0 16#1 16#0 16#AFFE 16#8001 t#60m t#12h t#0.505025h 3.333e-1 1 0 45054 -32768 t#3600000ms t#43200000ms t#1818090ms

2#1010111111111110 2#1000000000000001 t#1h t#0.5d t#30m18s90ms 0.3333

REAL

TwinCAT Training: Programmer

29.10.2013

12

Data types 1: Variable declaration el. data types


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

Identifier

Data type

Initial value The physical-logical storage location of this variable is unknown to the user (unlocated)

bStellerUntenLinks:BOOL:=TRUE;

The degrees of freedom and restrictions in the assignment of the identifiers can be found on the slide entitled Identifiers and Prefixes
TwinCAT Training: Programmer 29.10.2013 13

Data types 1: Located variables


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

TwinCAT Training: Programmer

29.10.2013

14

Data types 1: Located variables


Completely located variables.
Identifier AT %I %Q %M X B W D Byte . Byte Bit Type

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

Detail slides Detail - Replace %MB by UNION


TwinCAT Training: Programmer 29.10.2013 15

Data types 1: Address division


Examples:
IX10.7 IX10.6 IX10.5 IX10.4 IX10.3 IX10.2 IX10.1 IX10.0

Din0 AT%IX10.0 : BOOL;

IB10

IB1 IW0

IB0

Ain AT%IB0 : INT; equivalent Ain AT%IW0 : INT;

IX22.7

IX22.6

IX22.5

IX22.4

IX22.3

IX22.2

IX22.1

IX22.0

BitVar AT%IX22.1 : BOOL; Posi AT%IB20 : UDINT;


equivalent

IB23 IW22

IB22

IB21 IW20 ID20

IB20

Posi AT%ID20 : UDINT;

TwinCAT Training: Programmer

29.10.2013

16

Data types 1: Variable classes, scope


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

Global variables are known in each block within a project.


Keywords VAR_GLOBAL .. END_VAR VAR_CONFIG .. END_VAR

TwinCAT Training: Programmer

29.10.2013

17

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


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

Implementation
TwinCAT Training: Programmer 29.10.2013 18

Data types 1: Access via the located variables


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

Project machine
PROGRAM A VAR END_VAR PROGRAM B VAR locVar AT%MB2:WORD; END_VAR

LD %MB2

TwinCAT Training: Programmer

29.10.2013

19

Data types 1: Overlaps in the scope


Project machine
VAR_GLOBAL Var1:WORD; END_VAR

Example name: Gvl1

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

PROGRAM A VAR Var1 :WORD; END_VAR LD Var1 LD Gvl1.Var1

TwinCAT Training: Programmer

29.10.2013

20

Data types 1: PERSISTENT attribute


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

TwinCAT Training: Programmer

29.10.2013

21

Data types 1: Initialisation and CONSTANT


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

Global

Also locally possible

Data Types 2: Derived data types


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

Parent type

Name

Data type

Initial value

Area

New value

Inherit ance

Derivation

Name

Data type

Initial value

Area

TwinCAT Training: Programmer

29.10.2013

23

Data Types 2: References (alias types)


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

Declaration

TwinCAT Training: Programmer

29.10.2013

24

Data Types 2: References (alias types)


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

TwinCAT Training: Programmer

29.10.2013

25

Data Types 2: References (alias types)


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

TwinCAT Training: Programmer

29.10.2013

26

Data Types 2: References (alias types)


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

TwinCAT Training: Programmer

29.10.2013

27

Data Types 2: References (alias types)


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

TwinCAT Training: Programmer

29.10.2013

28

Data Types 2: Enumerated type (Enum)


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

The same enumeration value can be used twice via Namespace. Example: Woche.Dn Richtung.Dn
TwinCAT Training: Programmer 29.10.2013 29

Data Types 2: Enumerated type (Enum)


Example: signal light without Enum:
Declaration Use

Online

TwinCAT Training: Programmer

29.10.2013

30

Data Types 2: Enumerated type (Enum)


Example: signal light with Enum:
Type Use

Declaration

Online

TwinCAT Training: Programmer

29.10.2013

31

Data Types 2: Structure declaration


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

TwinCAT Training: Programmer

29.10.2013

32

Data Types 2: Structures instancing

ST_KL5101In_1 AT%I* : KL5101_IN ST_KL5101Out_1 AT%Q* : KL5101_OUT

TwinCAT Training: Programmer

29.10.2013

33

Data Types 2: Arrays


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

1-dimensional 2-dimensional 3-dimensional

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

TwinCAT Training: Programmer

29.10.2013

34

Data Types 2: Limit transgressions


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

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

Feld_1[9]; Feld_2[1,2];

0 120

TwinCAT Training: Programmer

29.10.2013

35

Data Types 2: CheckBounds (FUN)


The access can be monitored by the PLC at PLC runtime This function enables a limit transgression occurring in the program to be recognised and rectified.
FUNCTION CheckBounds :DINT VAR_INPUT I,L,U : DINT; END_VAR

IF I< L THEN
Error case

CheckBounds := L;

ELSIF I > U THEN


Error case i Min Max Limited value

CheckBounds := U;

ELSE
OK case

CheckBounds := I;

END_IF

TwinCAT Training: Programmer

29.10.2013

36

Data Types 2: Adding CheckBounds 1 (FUN)


Adding Checkbounds:

TwinCAT Training: Programmer

29.10.2013

37

Data Types 2: Adding CheckBounds 2 (FUN)

TwinCAT Training: Programmer

29.10.2013

38

Data Types 2: Method of operation of CheckBounds (FUN) Example: user error source code Checkbounds is compiled-in in XAR

10

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

10
Can be checked with call build:
TwinCAT Training: Programmer 29.10.2013 39

Note about further checker functions


The following further checker functions are possible from TwinCAT 2.8: Check for division by 0 CheckDivByte CheckDivWord CheckDivDWord CheckDivReal Check value ranges CheckRangeSigned CheckRangeUnsigned (see appendix)

TwinCAT Training: Programmer

29.10.2013

40

Data Types 2: Combination: structures and arrays


An array can consist of structures:
Structure:
TYPE DrillPos : STRUCT XPos: FeedrateX: AccelerationX: DeccelerationX: JerkX: YPos: FeedrateY: AcceleartionY: DeccelerationY: JerkY: FeedDrill: Kuehlen: END_STRUCT END_TYPE Declaration of the array: LREAL; LREAL; LREAL; LREAL; LREAL; LREAL; LREAL; LREAL; LREAL; LREAL; LREAL; BOOL; (*Pumpe ?*)

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


TwinCAT Training: Programmer 29.10.2013 41

Data Types 2: Combination: structures and arrays


Access to Drillpos 55: Access: MoveXAx (*FB Instanz*) ( Execute:= Position:= Velocity:= Acceleration:= Deceleration:= Jerk:= Direction:= Axis:= );
TwinCAT Training: Programmer 29.10.2013 42

TRUE, Positions[55].XPos , Positions[55].FeedrateX Positions[55].AccelerationX, Positions[55].DeccelerationX, Positions[55].JerkX, ........., .............,

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

TwinCAT Training: Programmer

29.10.2013

43

Block types: program PRG


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

TwinCAT Training: Programmer

29.10.2013

44

Block types: function block FB


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

TwinCAT Training: Programmer

29.10.2013

45

Block types: Function: FC


Function: FC
Called by programs, function blocks and other functions Calls: Functions Local variable: temporary, i.e. the local data are available only for the processing time of the function. Afterwards this data area is used by other functions. Inputs: 1,2,3........ VAR_INPUT Outputs: precisely 1!, but structure variable possible. The name of the output is at the same time the name of the function. Transfer by reference 1,2,3........ VAR_IN_OUT , Monitoring: In the online mode of the PLC control only ??? are visible for the local variables, since this data area is used by all functions in the cycle and monitoring (debug) takes place only at the cycle limits. Remedy: program development with breakpoints Use: algorithms where the result is available after a run. Scaling, comparison, etc.

TwinCAT Training: Programmer

29.10.2013

46

ST Structured Text: Operators


Operation put in parentheses Function call Exponentiation Negate Build. complements Multiply Divide Modulo Add Subtract Compare Equal to Not Equal to BOOL AND BOOL XOR BOOL OR Symbol Binding strength (expression) Strongest binding Function name (parameter list) EXPT NOT * Same binding strength, processing from left to right /
(10/2*5 = 25 ) MOD + Same binding strength <,>,<=,>= = <> AND XOR OR

Weakest binding
TwinCAT Training: Programmer 29.10.2013 47

ST Structured Text: Instructions


Instruction Assignment:= Calling a Function Block RETURN IF CASE FOR WHILE REPEAT EXIT Empty instruction ; Example PosWert := 10; Ton1(IN:=Start, PT:=T2s); Output:= Ton1.Q; RETURN; more precise explanations and examples on the following pages

TwinCAT Training: Programmer

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 ELSIF ELSE END_IF

THEN

TwinCAT Training: Programmer

29.10.2013

49

ST: IF instruction

IF Condition THEN Instruction block; END_IF

No Condition Yes

Instruction block

TwinCAT Training: Programmer

29.10.2013

50

ST: IF instruction

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

Condition Yes

No

Instruction block A

Instruction block B

TwinCAT Training: Programmer

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

TwinCAT Training: Programmer

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

TwinCAT Training: Programmer

29.10.2013

53

ST: IF instruction
What can the BOOLEAN EXPRESSION be? Conditions:
BOOLEAN variable Comparison Function calls 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

Querying of FB instances NO FB call!

TwinCAT Training: Programmer

29.10.2013

54

ST CASE Instruction
CASE Selection criterion OF 1: Instruction 1
Selection criterion = 1
Yes No No

Selection criterion = 2 or 4 or 6 Selection criterion = 7 or 8 or 9 or 10?

2, 4, 6: Instruction 2 7..10: Instruction 3 .. ELSE Default instructions END_CASE; Two identical values may not be available for selection in the list.

Yes No Yes

Instruction 1

Instruction 2

Instruction 3

Default instructions

TwinCAT Training: Programmer

29.10.2013

55

ST: CASE instruction: possibility for a step chain / state machine


CASE State OF 0: Q0:=TRUE; IF Transition THEN state := 1; END_IF 1: Q1:=TRUE; IF Transition THEN state := 2; END_IF 2: Q2:=TRUE; IF Transition THEN state := 3; END_IF 3: Q3:=TRUE; IF Transition THEN state := 0; END_IF END_CASE Step-further condition (Transition) Instructions for the step (Actions)

TwinCAT Training: Programmer

29.10.2013

56

ST: CASE instruction Integer Selector Value with constants


CASE State OF 0: Instructions;(*State=0*) IF THEN 1: Instructions;(*State=1*) Instructions if state = 1 Instructions if state = 2 Instructions if state = 3 Instructions if state = 0

2:

Instructions;(*State=2*)

3:

Instructions;(*State=3*)

END_CASE

TwinCAT Training: Programmer

29.10.2013

57

ST: CASE instruction Integer Selector Value with Enum types

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

CASE State OF INIT: START: AUTOMATIK: ENDE: END_CASE Instructions;(*State=0*) Instructions;(*State=1*) Instructions;(*State=2*) Instructions;(*State=3*)

TwinCAT Training: Programmer

29.10.2013

58

ST: CASE instruction: suggestion for a step chain / state machine


TYPE Schritte : ( INIT:=0, START, AUTOMATIK, ENDE); END_TYPE
CASE State OF INIT: Q0:=TRUE; IF Transition THEN state := START; END_IF START: Q1:=TRUE; IF Transition THEN state := AUTOMATIK; END_IF AUTOMATIK: Q2:=TRUE; Step IF Transition THEN state := ENDE; END_IF ENDE: Q3:=TRUE; IF Transition THEN state := INIT; END_IF END_CASE
TwinCAT Training: Programmer 29.10.2013 59

Instructions for the step (Actions) Step-further condition (Transition)

ST: CASE instruction Integer Selector Value with constants


VAR CONSTANT Step1 : INT:= Step2 : INT:= Step3 : INT:= Step4 : INT:= END_VAR 0; 1; 2; 3; CASE State OF Step1: Step2: Step3..Step4: END_CASE Instructions;(*State=0*) Instructions;(*State=1*) Instructions;(*State=2 oder 3*)

VAR State:INT; END_VAR

TwinCAT Training: Programmer

29.10.2013

60

ST: Repeat instructions


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

1
e.g.: 1ms

2
2ms

3
3ms

4
4ms

1
5ms

TwinCAT Training: Programmer

29.10.2013

61

ST: Loops (overview)


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

Expression FOR WHILE SINT/INT/DINT BOOL

Processing

n cycle fix

Yes Instructions follow condition Instructions No follow condition Condition follows instructions No

REPEAT

BOOL

TwinCAT Training: Programmer

29.10.2013

62

ST: FOR loop


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

Start i:=StartValue

i >EndValue No Instruction block

Yes

i: = i + step size

ST: WHILE loop


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

Yes

Boolean expression

No

Instruction block i: = i + step size

Cycle n
TwinCAT Training: Programmer 29.10.2013 64

ST: REPEAT loop


The instruction block of a REPEAT loop is executed as long as the Boolean expression is satisfied. The instruction block is processed at least once.
Cycle n

Instruction block i:= i + step size

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


Cycle n
TwinCAT Training: Programmer 29.10.2013 65

No

Boolean expression Yes

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

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

TwinCAT Training: Programmer

29.10.2013

66

ST: FB calls in ST (alternative)


VAR TON1:TON; END_VAR

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

TwinCAT Training: Programmer

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 ( x:= xug:= xog:= 32767.0, yug:= yog:= ); In case of functions, all inputs must be occupied
TwinCAT Training: Programmer 29.10.2013 68

Eingang, 0.0,

0.0, 100.0

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

TwinCAT Training: Programmer

29.10.2013

69

You might also like