You are on page 1of 27

Functions and Function Blocks

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.1

Information and Training Center Knowledge for Automation

Introduction

Global Variables / Data (valid in the entire program)

Local Variables / Data (only valid in one block)

PII / PIQ I/ O M/T/C DB areas

Temporary Variables are deleted after the associated block is executed temporary storage in L stack useable in OBs / FCs / FBs

Static Variables are retained even after the block is executed permanent storage in DBs can only be used in FBs

absolute Access

symbolic

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.2

Information and Training Center Knowledge for Automation

Temporary Variables

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.3

Information and Training Center Knowledge for Automation

Local Data Stack Size


Entire size:

1.5 Kbyte
(CPU 313..316)

Execution

For S7-300: Priority class L stack size

Startup (one-time execution) Cyclic execution Time-controlled execution Time-of-Day Interrupt Time-Delay Interrupt

27 1 2 3 256 bytes 256 bytes 256 bytes

Cyclic Interrupt
Hardware Interrupt Event-driven execution Error handling in startup Error handling in scan cycle

12
16 28 26

256 bytes
256 bytes 256 bytes

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.4

Information and Training Center Knowledge for Automation

Byte Requirement of a Block in the Local Data Stack

rechts

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.5

Information and Training Center Knowledge for Automation

Total Occupation in the Local Data Stack


Operating system
1

OB 1
2

FC 1
with temp. variables

3 4

FC 2
with temp. variables

5 7

FC 3
with temp. variables
4 5 6 7

Event Occupation in the L stack

FC2 FC1 OB1 OB1 FC1 OB1 FC1 OB1

FC3 FC1 OB1 FC1 OB1 OB1

SIMATIC S7
Siemens AG 1999. All rights reserved.

256 Bytes

Date: File:

01.09.2012 PRO1_11E.6

Information and Training Center Knowledge for Automation

Exercise: Use of Temporary Variables

Replace by the temporary variable "Packages"

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.7

Information and Training Center Knowledge for Automation

Example of a Message Display Indicating a Problem in the Process


Task

Disturbance Acknowledge Report Memory LED


Solution Suggestion Edge Mem. Bit Disturb. Input P Acknowl. Report Memory RS R S Q & >=1 Flash Freq. Report Memory Disturb. Input & Display =

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.8

Information and Training Center Knowledge for Automation

Parameter-Assignable Blocks
Non-parameterassignable block Parameter-assignable block Program Call FC 20

A I
R M A I FP M S M A M A M O ANM A I = Q

1.2
40.0 1.3 40.1 40.0 40.0 10.3

A #Acknowledge
R #Report Memory U #Disturb. input FP #Edge mem. bit S #Report memory A #Report memory A #Flashing freq. O

I 1.3

Disturb. input

I 1.2
M 10.3 M 40.0

Edge mem.bit Acknowledge Display Flash freq. Report memory

M 40.1

A 8.3

40.0 1.3 8.3

AN #Reportmemory A #Disturb. input = #Display

Formal parameters Actual parameters

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.9

Information and Training Center Knowledge for Automation

Declaration of the Formal Parameters

Formal parameters Type of parameter


Input parameter Output parameter In/out parameter

Declaration
in out In_out

Use
Read only Write only Read / write

Graphic Display
To the left of the block

To the right of the block To the left of the block

Declaration table of the FC 20 block

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.10

Information and Training Center Knowledge for Automation

Editing a Parameter-assignable Block

Here was, e.g., with a non-parameter-assignable FC: with absolute addressing: I1.3 with symbolic addressing: End_left"

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.11

Information and Training Center Knowledge for Automation

Calling a Parameter-assignable Block


Network 3: First Call .... EN Disturb.input Acknowledge Flash freq. Report memory Display ENO FC20

absolute

End left" Acknow.button" M10.3

Edge mem. bit

M40.1 Position error"

Addressing

M40.0

Network 4: Second Call A8.1 EN Disturb.input Acknowledge Flash freq. Report memory ENO FC20 Edge mem. bit Display M40.3 Q9.4

symbolic

End right" Acknow.button" M10.3 M40.2

Symboltable

Global Symbols

Symbols

Local Symbols --> Formal parameters

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.12

Information and Training Center Knowledge for Automation

Using the EN/ENO Parameters with Block Calls


LAD/FBD
FC 1 Unconditional call

STL

?? . ?

EN

ENO

CALL NOP 0

FC

Conditional call

I 0.1

FC 1 EN ENO

Q 9.0 = _001:

A JNB CALL A =

I _001 FC BR Q

0.1

1
9.0

Example

FC 1 ?? . ? EN ENO EN

FC 2 ENO EN

FC 3 ENO =

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.13

Information and Training Center Knowledge for Automation

Exercise: Creating a Parameter-assignable FC Block


1. Declaration table of the FC 20 block

Non-parameterassignable block

A I R M A I FP M S M A M A M O AN M A I = Q

1.2 40.0 1.3 40.1 40.0 40.0 10.3 40.0 1.3 9.3(Q5.3)

Parameter-assignable FC 20 block 2.

A #Acknowledge R #Report memory A #Disturb. ... : : : : : : : :

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.14

Information and Training Center Knowledge for Automation

Exercise: Calling a Parameter-assignable FC Block


FC 20 I 1.3 Parameter-assignment of FC20 in the 1st. call I 1.2 M 10.3 M 40.0 Disturb. input Edge mem. bit Display Acknowledge M 40.1 Q 9.3 (Q 5.3)

Flash freq. Report memory

FC 20 I 1.4 Parameter-assignment of FC20 in the 2nd. call I 1.2 M 10.3 M 40.2 Disturb. input Edge mem. bit Display Acknowledge M 40.3 Q 9.4 (Q 5.4)

Flash freq. Report memory

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.15

Information and Training Center Knowledge for Automation

Function Blocks (FBs)


OB 1 DB 2 FB 2
EN Disturb. input Acknowledge Flash freq. Display ENO Declaration table of the function block

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.16

Information and Training Center Knowledge for Automation

Function Block for Message Display

Declaration table of the function block

Instance data block

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.17

Information and Training Center Knowledge for Automation

Generating Instance Data Blocks


1. Generate instance DB with FB call 2. Create new instance DB

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.18

Information and Training Center Knowledge for Automation

The Multiple Instance Model


The Instance Model
OB 1 Call FB20, DB10 Disturb._Input:= Acknowledge:= Flash_Freq:= Display:= Call FB20, DB11 Disturb._Input:= Acknowledge:= Flash_Freq:= Display:= DB10 FB20 FB 100 stat DB11 FB20 stat Dist_1 Dist_2 FB20 FB20

The Multiple Instance Model


OB 1 Call FB100, DB100

DB100
Parameters and static variables of the 1st. call of FB20

Call Dist_1 Disturb._Input:= Acknowledge:= Flash_Freq:= Display:= Call Dist_2 Disturb._Input:= Acknowledge:= Flash_Freq:= Display:=

Call FB20, DB12 Disturb._Input:= Acknowledge:= Flash_Freq:= Display:=

DB12 FB20

Parameters and static variables of the 2nd. call of FB20

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.19

Information and Training Center Knowledge for Automation

Inserting/Deleting Block Parameters Later On

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.20

Information and Training Center Knowledge for Automation

Corrections when Calling Modified Blocks


When the calling block is opened:

Once with the right

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.21

Information and Training Center Knowledge for Automation

Exercise: Editing a Function Block


1. Declaration table of the FB 20 block

2.

A #Acknowledge Program section of FB 20 R #Report memory A #Disturb. ... : :

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.22

Information and Training Center Knowledge for Automation

Exercise: Calling a Function Block and Testing It

(Q 5.3)

(Q 5.3)

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.23

Information and Training Center Knowledge for Automation

Converting an FC to an FB using a Source Program (1)

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.24

Information and Training Center Knowledge for Automation

Converting an FC Block to an FB using a Source Program (2)

: :

: :

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.25

Information and Training Center Knowledge for Automation

Exercise: Recognizing Types of Variables

Statement L L T L L T T #Number_1 #Number_2 #Max_value #Intermediate_result Number_1" MW 40 #Number_2

Global Local

Absolute

Symbolic

Temporary

Static

Parameter

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.26

Information and Training Center Knowledge for Automation

Summary: Block Calls


FC
Language

FB
With parameters W/o param., w/o inst. DB With param., with inst.DB

Without parameters

STL

CALL FC1 UC FC1 CC FC1 FC1 ( CALL )

CALL FC2 Par1: ... Par2: ... Par3: ...

UC FB1 CC FB1

CALL FB2, DB3 Par1: ... Par2: ... Par3: ...

LAD

FC1
EN ENO

FC2
EN Par1 Par2 Par3 ENO EN

FB1
ENO EN Par1 Par2

DB3 FB2
ENO

Par3

FC1 CALL
FC2 FB1
Par3 EN EN

DB3 FB2
Par3 ENO Par1 ENO ENO Par2 EN Par1 Par2

FBD

FC1
EN

ENO

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

01.09.2012 PRO1_11E.27

Information and Training Center Knowledge for Automation

You might also like