127955753-Beckhoff-IEC61131-3

Share Embed Donate


Short Description

test...

Description

TwinCAT IEC61131-3

1

06.11.2012

Overview

Contents

Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Checkbounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

2

06.11.2012

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)

-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

3

(additionally to –3)

-3 Rules for using and implementation of PLC programming languages

-6 Communication via fieldbus.

-7 Fuzzy systems in the PLC

06.11.2012

Standard guide

The PLCopen contains 3 devaluation compatible compliance classes: Base level

Portability level

Full compliance level

4

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.

06.11.2012

Functional structure of a PLC Power supply system

Other systems

Operator

Programmer

MMI functions Communication function Check functions

Power supply

Signal executing function

Operating system Operating program

Executing function

Data

Interface function to sensors and actuators

5

process

06.11.2012

Communication functions

Ethernet, RS232, Modem Other systems

Server

ADS OCX, ADS DLL, TwinCAT OPC

MMI functions Communication function Check functions ADS/AMS router

6

Operator Programmer

Forcen, Breakpoints, single step, System Manager, Scope View

06.11.2012

Signal executing function

Compiled PLC project, selfdefined server

Signal executing function

Operating function

Win NT, 2000, XP

Operating system Operating program

Data

PLC Server 1, PLC Server 2, PLC Server 3, PLC Server 4, NC Server, Cam Server

ADS-, I/O process image

7

06.11.2012

Interface function between sensors and actuators

Interface function between sensors and actuators Copy rule DP RAM PA PLC

A

E

Actuators and sensors DP/PA

F-Sensor 8

F-FieldDevice

F-Actuator 06.11.2012

Overview

Contents

Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Checkbounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

9

06.11.2012

Software model

Configuration Resource

Resource Task2

Task1 Program

Main

Program Motion FB

Task1

Task2

Program

Program

FB

FB

FB

FB

Global and direct addressed variable

access paths

10

06.11.2012

Software model Example Example PC PLC with 1 run time und zwei Task 1 BC900 (Ethernet Controller) Configuration

Resource BC9000

Resource PC Task2

Task1 Program

Main

Task1

Program Motion FB

FB

Program FB

FB

Global and direct addressed variable Mapping in the TwinCAT System Manager

access paths

11

06.11.2012

Overview Contents

Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Checkbounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

12

06.11.2012

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 letters Not allowed • Special characters (!,“,§,$..) • Blank character • Sequential underscores • mutated vowel

13

06.11.2012

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)

06.11.2012

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.

15

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;

06.11.2012

Overview Contents

Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Checkbounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

16

06.11.2012

Data types

Data types describe memory locations resp. appoint their features.

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)

0

1

1

0

1

0

1 06.11.2012

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_F FFF

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

Short integer

ANY_Num

18

06.11.2012

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

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

Long slide point Date

ANY_Date

time

ANY_Time

TIME

32

T#0ms

Sequential characters

ANY_String

STRING

(80+1)*8

‚‘

19

TOD#00:00.. TOD#23:59

06.11.2012

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;

Strings are zero terminated, that means the last character of a string is always zero. Each character inside a string needs one byte.

END_VAR

06.11.2012

Special characters

If you want to add a special character into a string, you have to begin with a $character.

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

06.11.2012

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 library ChrAsc.lib.

(Component of the Comlib)

22

06.11.2012

Variables declaration el. data types

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;

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. 23

06.11.2012

Variables declaration el. data types At the declaration of the variables it´s possible to 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 essential.

Identifier

AT AT

Identifier

Address

:

%I

X

%Q

B

%M

W D

Bit

Byte

Data type ; Data type

Byte

These variables own a unique address (located)

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

06.11.2012

Overview

Contents

Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Checkbounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

25

06.11.2012

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

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

06.11.2012

Access via the located variables

From program A is a direct access by address %MB2 to the local declared variable ‚locVar‘ in program B possible.

Project Machine PROGRAM A

PROGRAM B

VAR

VAR locVar AT%MB2:WORD; END_VAR

END_VAR

LD %MB2

27

06.11.2012

Overlapping in the validity range

Project Machine VAR_GLOBAL Var1:WORD; END_VAR

PROGRAM A VAR Var1 :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.

LD Var1

28

06.11.2012

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

06.11.2012

Attributes (constants)

Projekt Maschine VAR_GLOBAL CONSTANT END_VAR PROGRAM A VAR CONSTANT END_VAR

30

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 CONSTANT pi:REAL:=3.141592654; END_VAR

06.11.2012

Overview

Contents

Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Checkbounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

31

06.11.2012

POU program organisation units

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.

The data POUs are replaced by multi-dimensional fields (ARRAY‘s).

32

06.11.2012

POU program organisation units

Each POU consists of a declaration part and a body. The declaration part is the same in each IEC programming language. The local variables of the block are declared there.

The body is written in one of the IEC programming languages which include IL, ST, SFC, FBD, LD or CFC.

33

06.11.2012

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 available 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 online mode of the PLC Control



Using: Main programms, main, hand, automatic....

34

06.11.2012

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 again available at the next cycle. At multiple call multiple instances (mulitply). 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 instance of the according call has to declared. After this, the local data are visible for each call.



Using: multiple used function blocks, which need an own data range each. Multiple sequences....

35

06.11.2012

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;

06.11.2012

Function FC Function FC •

called by: programs, function blocks and other functions



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 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



Using: algorithms, at which the result is available after a pass. Scaling, compare......

37

06.11.2012

FC Specials

From TwinCAT 2.8: The return value can be defined directly if a new function is created.

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

Scale can be used as local variable inside the function(Write/Read)

06.11.2012

Overview Contents

Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Checkbounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

39

06.11.2012

TwinCAT System Service

The TwinCAT System Service operates as Windows NT service in the local system account. In this way, the TwinCAT System Service is started by Windows NT before a user has logged on. As an activity symbol, the TwinCAT System Service incorporates its icon into the task bar of the desktop. In addition, the colour of the icon indicates the state of the TwinCAT system. TwinCAT stopped TwinCAT starting. TwinCAT running. TwinCAT Config Mode

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. . 40

06.11.2012

TwinCAT System Service

The event display is a programm to moniotor the events in the system. The event logging service starts automatically, if you execute Windows NT.

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. 41

06.11.2012

Multitasking

TwinCAT possesses more than 62 different tasks. The default settings can use preset profiles or change the priority individually.

42

06.11.2012

Assigning the computing power Real time operation of PLC software in the classical PLC. Read inputs Write outputs

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

t 06.11.2012

Overview

Contents

Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Checkbounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

44

06.11.2012

Real time

Many industrial applications demand a guarantee, that, clearly predictable and reproduceable, the system load reacts sufficient fast to the process event in a defined time. The real time is very important for the digital control. The sampling of an analog signal (actual position) with a PC should have absolute constant distances between two measurements. Each part process requires different reaction times. Because of this, several part processes with different features and different reaction times can be created in one automation task. If several tasks want to access the CPU simultaneously, the IEC 61131-3 defines two procedures: 1. Preemptive (interruptible execution) multi tasking (TwinCAT) 2. Non preemptive (not interruptible execution) multi tasking

45

06.11.2012

Real time operation

The real time operation will be achieved with deterministic time slices. The width of the time slices can be chosen in steps: (1000µs ... 50µs). The default setting is 1ms.

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.

With the begin of a new time slice, the software devices (PLC, NC) will be executed with priority control.

46

- 15µs +15µs

06.11.2012

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 millisecond. 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 too late is measured. 47

06.11.2012

Real time operation Cyclic PLC task e.g. 10ms

20ms

10ms

30ms

0ms

40ms

Refinement: Behavior under TwinCAT base cycle 1 ms

80% TwinCAT 0ms

80%

W

TC

1ms PLC

PLC

W

80% W

2ms

Time slice for Windows 3ms

Time slice for TwinCAT PLC program cyclic task

If TwinCAT does not need the (full) reserved time slice, the scheduler provides this computing power to windows. 48

06.11.2012

Real time operation

PLC tasks and drive control will be executed deterministically with multiple tasking.

Real time operation of a PLC program and NC control with a PC NC

PLC program

Win NT & HMI Interface

1

1

2

e.g.: 1ms

NC cycle

(e.g. 1ms)

SPS cycle 49

1‘

3

2

4

2‘

2ms

3ms

4ms

NC cycle

NC cycle

NC cycle

(e.g. 2ms)

3 5ms

t t

PLC cycle 06.11.2012

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 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

06.11.2012

Task + POU´s -> Create a new project

Before a new project starts, the following questions 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) 51

06.11.2012

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 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.

It´s possible to create an event driven task from a cyclic task. For this, the program call must depend on an event.

52

06.11.2012

Create a new project

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 task name is an identifier. Respectively the rules for the identifier obtain.

The interval time is always a multiple of the time slice. 53

06.11.2012

PLC Control Symbol bar

File

Project

Element

new

Start

Cut

open

Stop

Copy

safe

Single step

Insert

Breakpoint

Find

Log in

Find next

The field for the variables depends on the selected IEC language.

Log off

PLC Control 54

06.11.2012

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 dialog. The name is an identifier. Respectively the rules for the identifier obtain. The type of the POU depends on the problem. The language of the POU should be used according to the problem.

55

06.11.2012

Program

A program is a POU which returns several values during 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 program is called, even if the program has been called from within another POU.

56

06.11.2012

Overview

Contents Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Checkbounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

57

06.11.2012

Derivated data types (Variable II)

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

06.11.2012

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 :; END_TYPE

Example: Ads_Net_ID TYPE Net_ID:STRING(23); END_TYPE

59

06.11.2012

Enumeration (Variable II)

Enumeration is a user-defined data type that is made up of a number of string constants. These constants are referred to as enumeration values. Enumeration values are recognized in all areas of the 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 Data types. They begin with the keyword TYPE and end with END_TYPE. Syntax: TYPE :( ,, ...,); 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

60

You may not use the same enumeration value more than once. 06.11.2012

Enumeration (Variable II)

The 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 . 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

06.11.2012

Structure declaration (Variable II)

form

Structures are self defined data types. They are important aids for managing the process data.

Pers_Data Name:

Furthermore the structures are suited for capsulated data transfer to function blocks.

Firstname:

Age:

Address:

TYPE Pers_Data : STRUCT Name: STRING(25); Firstname: STRING(25); Age:USINT; Address: STRING(55); END_STRUCT END_TYPE 62

Structures can be used like single element variables.

Identifier for the new data type Identifier : parents data type ■ ■ ■

06.11.2012

Structures Instances (Variable II) P1

Name:=‚Müller‘ 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*)

06.11.2012

Overview

Contents Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Checkbounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

64

06.11.2012

Arrays (Variable II)

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

It´s possible to put a data array to a direct addressed memory position VAR Feld_1 AT%MB100:ARRAY[1..10] OF BYTE; END_VAR

Access to the sub-elements of a data array Feld_1[2] := 120; (* explicit access*) Feld_2[i,j] := EXPT(i,j); (*indicated access*) 65

06.11.2012

Array one-dimensional example with initialisation (Variable II) One-dimensional

Identifier

Field

Data type

Initial value

DBZeiten :ARRAY [0..6] OF TIME:= T#1s, T#2s, T#1s, 4(T#0s); 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

The field length can be done explicit or with the aid of constants. A dynamic change of the field size is not possible.

WertAusArray : TIME; END_VAR

WertAusArray := DBZeiten[1]; 66

06.11.2012

Array two-dimensional example with initialisation (Variable II)

To assign for example support points, an array is well qualified.

Identifier

Field

Data type

Initial value

Supportpoint:ARRAY [0..1, 0..6] OF REAL:= 0, 1.7, 2, 4(3.33), 6, 6(1.2); Factor

0

0

1

2

3

4

5

6

0

1.7

2

3.33 3.33 3.33 3.33

Value

Access: VAR WertAusArray : REAL; END_VAR

1

6

1.2

67

1.2

1.2

1.2

1.2

1.2

WertAusArray := Supportpoint[1 ,0];

06.11.2012

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;

68

06.11.2012

Array three-dimensional example with initialisation (Variable II)

Identifier

Array

Datatype

Initial value

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

2 1 0 1

3

1

4

0

0

1

2

23 24 25

0

20 21 22

13 14 15

5 0

1

10 11 12 0

1

2

Access: VAR ValfromArray : UINT;

0

1

2

END_VAR ValfromArray

:=

Supportpoint[ 2,0,1 ];

0

1

2 69

06.11.2012

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.

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;

9

Feld_1[9];

0

Feld_2[1,2];

120

70

06.11.2012

Overview Contents Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Check bounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

71

06.11.2012

Check Bounds (FUN)

If you define a function in your project with the name CheckBounds, you can automatically check for outof-range errors in arrays.

FUNCTION CheckBounds :INT VAR_INPUT I,L,U : INT; END_VAR

IF I< L THEN Error case

CheckBounds := L;

ELSIF I > U THEN Error case Limited value

i Min Max

CheckBounds := U;

ELSE „OK“ case

CheckBounds := I;

END_IF

72

06.11.2012

Inserting Check Bounds 1(FUN)

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

06.11.2012

Inserting Check Bounds 2(FUN) So that CheckBounds is recognised by translating, the 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 only temporary (at functions). Such a variable has to be declared (in this case) under the global variables.

74

06.11.2012

Check Bounds (FUN) mode of operation FUNCTION CheckBounds :INT VAR_INPUT I,L,U : INT; END_VAR Automatical call

IF I< L THEN CheckBounds := L; ELSIF I > U THEN CheckBounds := U;

Access at 2 ->ok

ELSE

CheckBounds := I; END_IF FUNCTION CheckBounds :INT VAR_INPUT I,L,U : INT; END_VAR IF I< L THEN CheckBounds := L;

Checkbounds returns 3, the access is limited to the maximum index 75

ELSIF I > U THEN

CheckBounds := U; ELSE CheckBounds := I; END_IF 06.11.2012

Note: Further Checker functions

From TwinCAT 2.8 the following further Checker functions are possible:

Check division by 0 CheckDivByte CheckDivWord CheckDivDWord CheckDivReal

Check value range CheckRangeSigned CheckRangeUnsigned (see Appendix)

76

06.11.2012

Combination Structures and Arrays (1) An array can consist of structures: Structure: TYPE DrillPos : STRUCT XPos: FeedrateX: AccelerationX: DeccelerationX: JerkX: YPos: FeedrateY: AcceleartionY: DeccelerationY: JerkY: FeedDrill: Kuehlen: END_STRUCT END_TYPE

LREAL; LREAL; LREAL; LREAL; LREAL; LREAL; LREAL; LREAL; LREAL; LREAL; LREAL; BOOL; (*Pump ?*)

Declaration of the arrays :

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

06.11.2012

Combination Structures and Arrays (1)

Access to „Drillpos 55“: Access: MoveXAx (*FB Instance*) ( Execute:= Position:= Velocity:= Acceleration:= Deceleration:= Jerk:= Direction:= Axis:= );

78

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

06.11.2012

Overview

Contents Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Check bounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

79

06.11.2012

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

06.11.2012

ST Structured text: Overview about Instructions

Instruction

Example

Assignment :=

PosWert := 10;

Callin a function block

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

RETURN

RETURN;

IF

See the following pages

CASE FOR WHILE REPEAT EXIT Empty instruction

81

;

06.11.2012

IF Instruction

Is needed to branch in a program depending on conditions.

Keywords:

IF With the IF instructions it´s not possible to jump back in the PLC cycle.

THEN

ELSIF ELSE END_IF

„GOTO“ is not available

e.g.:

82

06.11.2012

IF Instruction (1)

Condition IF Condition THEN Instruction block; END_IF

No

Yes

Instruction block

83

06.11.2012

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

06.11.2012

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

06.11.2012

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

06.11.2012

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

06.11.2012

CASE Instruction

CASE Selection criterion OF 1:

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;

Two same values mustn´t be available at the listing. 88

06.11.2012

CASE Instruction Integer Selector Value with Enum types

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

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 89

06.11.2012

CASE Instruction Integer Selector Value with constants

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:

instructions;(*State=2 oder 3*)

END_VAR

END_CASE VAR State:INT; END_VAR

90

06.11.2012

CASE Instruction proposal for a Statemachine TYPE Steps : ( INIT:=0, START, AUTOMATIC, END); END_TYPE Instruction for the step

CASE State OF

(Actions)

INIT:

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

START:

Q1:=TRUE;

„step enabling condition“ (Transition)

IF Transition THEN state := AUTOMATIC; END_IF

Step

AUTOMATIC: Q2:=TRUE; IF Transition THEN state := END; END_IF END:

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

END_CASE 91

06.11.2012

Repeat Instructions

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.

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.

Begin of a new time slice

Forced switch to Win NT

1

1

2

e.g.: 1ms

2ms

92

1‘

3 3ms

1‘‘

4 4ms

1‘‘‘

1‘ 5ms

06.11.2012

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

06.11.2012

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.

Start i:=Start value

i >End value

Yes

No Instruction block

I:= i+ Step width

FOR i:=1 TO 12 BY 2 DO Field[i]:=i*2;(*instruction*) END_FOR 94

cycle n 06.11.2012

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 i100 END_REPEAT 96

Yes

Boolean expression

No

cycle n 06.11.2012

FB calls in ST

VAR TON1:TON; END_VAR TON1 (IN:= NOT TON1.Q , PT:=T#1s ); Q0:= TON1.Q from TwinCAT 2.8 :

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

97

06.11.2012

FB calls in ST explanation: Create instance of FB

VAR TON1:TON; END_VAR

Call with instance name

TON1 (IN:= NOT TON1.Q , PT:=T#1s ); input parameters Scan output

Q0:= TON1.Q

Not possible: FB can have several outputs:

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

06.11.2012

FB calls in ST (alternative)

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

99

06.11.2012

FB calls in ST (alternative) explanation

Declaration

VAR TRANSFER ONLY INPUT PARAMETER . This is

NO FB CALL!!!!!

TON1:TON; END_VAR

TON1.IN:= NOT TON1.Q ; TON1. PT:=T#1s; TON1(); scan output 100

FB CALL

Q0:= TON1.Q; 06.11.2012

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

101

( x:= xug:= xog:= yug:= yog:= );

input, 0.0, 32767.0, 0.0, 100.0

06.11.2012

FC calls in ST explanation:

Result := Scale (x:=input, xug:=0.0, xog:=32767.0, yug:=0.0,yog:=100.0);

Result

CALL

(* equal:*) Result:=Scale ( x:= xug:= xog:= yug:= yog:= ); 102

Input parameters

input, 0.0, 32767.0, 0.0, 100.0

06.11.2012

Overview Contents Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Checkbounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

103

06.11.2012

SFC Sequential Function Chart

Step N

Transition Following step

N

Action

Qualifier

• 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.

Action

Transition Action,

Qualifier

104

Can be written in Structured Text, Instruction list, Ladder Diagram, Function Block Diagram and in Sequential Function Chart .

06.11.2012

Steps

Initial step active at the start Init N

Transition

Action

„Normal“ Step“

Step1 N

Action

• 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 be read.

Transition

105

06.11.2012

Actions Transition Transition Step1 N

Action

Step1 N

bOutput

Transition Transition

Action, can be programmed in -> Structured Text, -> Instruction List, -> Ladder Diagram, -> Function block diagram, CFC/FBD

Action, can be a variable of type BOOL. The variable is TRUE by activating the the step and FALSE by leaving the step.

-> Sequential Function Chart

106

06.11.2012

Actions, several allowed per step

Transition

Step1

107

N

bOutput

P

STAction

N

LDAction

R

FBDAction

06.11.2012

Steps /alternative branches

• Only one branch can be active.

Init N

Action

• Because only the left or the right branch is important, two transitions are necessary before the combination. Transition

Transition

Stepa

Stepb N

Transition

108

Action

N

Action

Transition

06.11.2012

Steps / alternative branches

• The branches needn´t be symmetrical.

Init N

Action

Transition

Transition

Stepb N

Stepa N

Action

Action Transition Stepc

Transition

N

Action

Transition

109

06.11.2012

Steps /alternative branches

• Branches can be skipped. Init N

Action

N

Action

Transition

Stepa Transition

Transition

110

06.11.2012

Steps /simultaneous branches

•Two branches are processed “simultaneous”.

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

N

Action

Transition at the „end“

06.11.2012

Steps /simultaneous branches

• Simultaneous branches needn´t be symmetrical.

Transition

Step_b N

Action

N

Action

Transition

Step_a N

Action Step_c

Transition 112

06.11.2012

Transitions

A Transition must be of type „BOOL“. Possibilities: Init N

• BOOLEAN Variable

Action

• ST Instruction • „programmed“ Transition

BOOLEAN VARIABLE

bVariable Step1 N

Action ST instruction.

A>B

The result be must be of type BOOL. Note: If the instruction is too long, the display will be shorten automatically.

113

06.11.2012

Transitions Programmed Transitions Init N

Action With this mark it´s only a comment.

A>B

„NOTHING CONNECT“

Step1 N

The result must be of type BOOL and is the transition

Action 001

Comment

A

GT AND

B Hides behind Possible: FBD, LD, IL, ST. Points to programmed transition 114

INPUT0

Limitations: one network, one Instruction sequence, no FB calls. 06.11.2012

Final Scan If a step is left, the processing takes exactly one more cycle. This behaviour can be used for “cleaning”in the action. Example: Reset outputs. Step.X 1 0

Step1

N

Action

t Action processing

1 0

Go on

t 1 Cycle

Following step

001

N

Action

release

AND

Output Step1.X

Transition At the last pass the step.X = FALSE. Thus the variable „Output “ is FALSE . 115

06.11.2012

Final Scan At a certain action the final scan leads to an unwanted behaviour. Step1

N

Action

Step.X 1

TRUE

0 t Action processing

1

Behaviour: Counter := Counter +1;

0 t 1 cycle

1 cycle

(*Counter increases at 2*) Remedy: The step flag is only for one cycle 1: IF Schritt.X THEN Counter := Counter +1; END_IF (*Counter increases at 1*) 116

06.11.2012

Qualifier Controls the action processing after activating a step. N: Non Stored Step

N

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

06.11.2012

Qualifier Controls the action processing after activating a step S: SET Step

S

Action

Step.X 1 0

TRUE

t Action processing

1 0 t 1 cycle

Combination in FBD 001 Step.X

S

SR Action processing

R

118

06.11.2012

Qualifier Controls the action processing after activating a step R: RESET Step

R

Aktion

Step.X 1 0

TRUE

t Action processing

1 0 t

Combination in FBD 001

S

SR Action processing

Step.X

119

R

06.11.2012

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

t

Combination in FBD 001

Step.X T#1s

120

TON IN Q PT

Action processing

ET

06.11.2012

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

t

Step.X 1

001

AND Step.X T#1s

TON IN Q PT

ET

Action processing

0 t Action processing

1 0 Limit

121

t

06.11.2012

Qualifier Controls the action processing after activating a step P: PULSE Step

P

Action

Step.X 1 0

TRUE

t Action processing

1 0 1 cycle

1 cycle

t

Combination in FBD 001 R_TRIG Step.X

122

Clk

Q

Action processing

ATTENTION: A SECOND FLOW PROCESSES!

06.11.2012

Qualifier, Combinations

SD: Stored and delayed DS: Delayed and stored SL: Stored and time limeted

123

06.11.2012

Overview Contents Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Checkbounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

124

06.11.2012

Sequential Function Chart step diagnosis

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

06.11.2012

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 initialization of the Init step. Thus for example the SFCReset flag could be re-set to FALSE in the Init step.*)

126

06.11.2012

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 when 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 when a transition is actuated. .*)

127

06.11.2012

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 timeout. *)

SFCErrorPOU:

STRING;

(*This variable of the type STRING contains the name of the block in which a timeout has occurred. *)

128

06.11.2012

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 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

06.11.2012

Sequential Function Chart step diagnosis (from 2.8)

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

06.11.2012

Sequential Function Chart process diagnosis

Implicit variable

131

06.11.2012

Sequential Function Chart process diagnosis

• set step attributes for the step to be observed

132

06.11.2012

Online (and per ADS) can be requested

133

06.11.2012

Sequential Function Chart Tipmode

• insert implicit variable:

• effect: SFCTipMode

SFCTip

Transition

effect

TRUE TRUE TRUE FALSE FALSE

FALSE TRUE TRUE TRUE FALSE

TRUE TRUE FALSE FALSE TRUE

Process stays in the current step

134

Change to next step Change to next step Process stays in the current step Change to next step 06.11.2012

Actions also in other IEC languages possible! (POU type : PRG, FB) „Mainprogram“

Action step1

Action step2 135

06.11.2012

Overview

Contents Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Checkbounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

136

06.11.2012

Remanent Flags Variables Attributes

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

06.11.2012

Retain Persistent Retain

Persistent

To store

To delete

Rebuild all, Reset

Reset all

Possible for

unlocated, located (%M)

Unlocated, located (%I, %Q, %M)

138

06.11.2012

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.

The PLC can start independent from the user log on!

139

1

Start NT

2

Start TwinCAT

3

Loading the boot project into the Run-Time

4

Start PLC

Log on

06.11.2012

1&2

1 2

140

TwinCAT Auto boot

Auto logon with Win NT

06.11.2012

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.

141

06.11.2012

3&4 Number of run time systems

Enabling for loading the boot project for the run time system 1.

142

Enabling for loading and saving the RETAIN data for the run time 1. 06.11.2012

Sourcecode download

1.Goto Project/Options and press the left mouse button. 2.A Window will open 3.Choose the Point Sourcedownload

143

06.11.2012

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 144

06.11.2012

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 145

06.11.2012

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.

146

06.11.2012

Were retain and persitent data loaded successfully?

In order to be able to view this data structure, the "PlcSystem.lib" library must be linked in. (Global variable)

147

The structure component shows if the persistent/retain data were loaded successfully.

06.11.2012

Meaning of the flags Bit number

Description

0

RETAIN variables: LOADED (without error)

1

RETAIN variables: INVALID (the back-up copy was loaded, since no valid data was present)

2

RETAIN variables: REQUESTED (RETAIN variables should be loaded, a setting in TwinCAT System Control)

3

Reserved

4

PERSISTENT variables: LOADED (without error)

5

PERSISTENT variables: INVALID (the back-up copy was loaded, since no valid data was present)

6

Reserved

7

Reserved

148

06.11.2012

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 149

06.11.2012

Write Persistent Data on demand

With the fuction block „WritePersistentData“ (TcPlcUtilities.Lib) it is possible to initiate the writing of the Persistent Data.

TcPlcUtilities.Lib

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!

150

06.11.2012

Write Persitent Data on demand, Example:

IF ReqWritePersistent THEN

fbWritePersistent(NETID:='' , PORT:=801 , START:=TRUE , TMOUT:=T#500ms ); IF fbWritePersistent.ERR THEN

fbWritePersistent(START:=FALSE ); ReqWritePersistent:=FALSE; ELSIF NOT fbWritePersistent.BUSY THEN

PLC Runtime

fbWritePersistent(START:=FALSE ); ReqWritePersistent:=FALSE;

Further start after edge

END_IF END_IF

151

06.11.2012

Internal Libraries

Unnecessary elements: All tasks will be deleted in the task configuration.

Create and test project

All POUs, which are not to belong to thecontents of a library, are removed. All global variables will be deleted.

Delete unnecessary elements of a library

Valid: global constants, self defined data types.

Save as internal *.Lib

152

06.11.2012

Overview Contents Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Checkbounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

153

06.11.2012

CheckDivByte

154

06.11.2012

CheckDivWord

155

06.11.2012

CheckDivDWord

156

06.11.2012

CheckDivReal

157

06.11.2012

CheckRangeSigned Variable to be checked

Checker function

158

06.11.2012

CheckRangeUnsigned Variable to be checked

Checker function

159

06.11.2012

CheckRangexxx can be done with TYPES

160

06.11.2012

Overview

Contents Part 1

Part 2

Part 3

IEC 61131-3 Overview

Variables II Structs, Enums

Sequential Function Chart

Software model

Variables II Arrays

Step diagnosis

Identifier

Checkbounds

Appendix

Elementary data types

Structured text

Bootprojects, Data remanence

Variables classes

Checker functions

Block types

Example Step by Step

TwinCAT System Service Timing

161

06.11.2012

Paint station (PRG)

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

06.11.2012

Creating the variables list

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

0

WORD

Local

163

06.11.2012

Switch on / off the plant

The switches bStart and bStop should be used as push-button. To safe the status, it´s necessary to add a hold element (RS). There are two bistable memorys under the standard function blocks. The dominant input is marked with xxx1.

Set

Set1

Reset1

Reset

Q1

Q1 164

06.11.2012

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.

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

LD Inc ADD 1 ST Inc

LD GT AND LT ST

INC Marke_1 (INC Marke_2) bDuese_1(

IL 165

06.11.2012

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

166

06.11.2012

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.

167

06.11.2012

Master cards

Different fieldbus systems. Each fieldbus has several master cards from different manufacturers (Beckhoff FC, Siemens CP, Hilscher CIF). Several different fieldbus master cards can be used parallel.

DP Master

The FC 310X supports the PROFIBUS protocols: PROFIBUS-DP (as Master, Slave and Multi-Slave), PROFIBUS-DPV1 (as Master) PROFIBUS-MC (as Master)

168

06.11.2012

Slave modules

With the dialog “Insert I/O device” it´s possible to 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).

169

06.11.2012

Modular Structure of the Slaves modules

Beckhoff DP-Slave

General DP-Slave

xN

170

06.11.2012

Paint station (PRG)

Load example

contact

Graphical elements in LD

Cursor in KOP is used for inserting new elements

coil

171

06.11.2012

context menue

172

06.11.2012

Insert new elements

Identifier

The following elements can be inserted at the marked cursor positions 173

06.11.2012

Paint station (PRG)

Load example

Graphical elementes in FBD

Cursor in FBD is used for inserting new elements

Operator

174

06.11.2012

Context menue

175

06.11.2012

Insert new elements

List of the operators (AND, OR, GE, ADD, ..) implemented by the system.

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.

176

06.11.2012

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF