09 FC FB

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 24

Functions and Function Blocks (1)

Program
execution
CALL FC 10
On_1 :=
On_2 :=
Off
:=

I 0.1
I 0.2
Q8.0

FB 5
Function FC10
in
in
out
...

...
A
A
=
...

SIMATIC S7

Siemens AG 2004. All rights reserved.

On_1
On_2
Off

Drive

CALL FB5, DB5


Start
:=I 0.0
Stop
:=I 0.1
Motor_on
:=Q8.0
Speed :=QW12

DB 5
0.0
0.1
2.0
4.0

Start
Stop
Motor_on
Speed

BOOL
BOOL
BOOL
INT

in
Start
BOOL
in
Stop
BOOL
out Motor_On BOOL
out Speed
INT
stat ...
Temp...

BOOL
BOOL
BOOL

#On_1
#On_2
#Off

...
A
AN
=
...

Date:
File:

04/20/15
PRO1_12E.1

#Start
#Stop
#Motor_on

SITRAIN Training for


Automation and Drives

Objectives
Upon completion of this chapter the participant will ...

SIMATIC S7

Siemens AG 2004. All rights reserved.

...

be familiar with the purpose of parameter-assignable blocks

...

be able to program parameter-assignable functions and their calls

...

know the difference between functions (FCs) and function blocks


(FBs)

...

be familiar with the purpose of static variables

...

be able to declare static variables and apply them in the program

...

be able to program parameter-assignable function blocks and call


them

Date:
File:

04/20/15
PRO1_12E.2

SITRAIN Training for


Automation and Drives

Variables - Overview

Global Variables / Data


(valid in the entire program)

PII / PIQ

Local Variables / Data


(only valid in one block)
Static Variables

Temporary Variables

M/T/C

are overwritten with undefined


values after the associated
block is executed

DB areas

temporary storage in L stack

I / O Peripherals

usable in OBs / FCs / FBs

absolute

are retained even after the


block is executed
permanent storage in DBs
can be used in FBs only

symbolic
Access

SIMATIC S7

Siemens AG 2004. All rights reserved.

Date:
File:

04/20/15
PRO1_12E.3

SITRAIN Training for


Automation and Drives

Temporary Variables

Declaration

Use

SIMATIC S7

Siemens AG 2004. All rights reserved.

Date:
File:

04/20/15
PRO1_12E.4

SITRAIN Training for


Automation and Drives

Total Usage of the Local Data Stack


Operating
system
1

FC 17

OB 1
2

with temp.
variables

Result

FC 20

with temp.
variables

FC 30

with temp.
variables

FC20

256 Bytes

Usage of
the L stack
FC30

FC17 FC17 FC17 FC17 FC17


OB1

SIMATIC S7

Siemens AG 2004. All rights reserved.

OB1

OB1

OB1

OB1

Date:
File:

OB1

04/20/15
PRO1_12E.5

OB1
SITRAIN Training for
Automation and Drives

Example: Fault Signal Displayed with Output LED


Task

Fault_Signal
Acknowledge
Stored_Fault
Display
Solution Suggestion

SIMATIC S7

Siemens AG 2004. All rights reserved.

Date:
File:

04/20/15
PRO1_12E.6

SITRAIN Training for


Automation and Drives

Parameter-assignable Blocks
Solution with nonparameterassignable block

Solution with parameter-assignable block


Program in FC 20

Call of FC 20 (e.g. in OB 1)
FC 20

1.1

A #Fault_Signal

FP

M 17.2

FP #Edge_Memory

M 17.1

I 1.1

Fault_
Signal

S #Stored_Fault

I 1.0

Acknowledge Display

A #Acknowledge

M 10.3

Flash_Freq.

M 17.1

R #Stored_Fault

M 17.1

M 17.1

A #Stored_Fault

Stored_
Fault

M 17.2

M 10.3

A #Flash_Freq.

Edge_
Memory

1.0

Q 5.1

AN

M 17.1

AN #Stored_Fault

A #Fault_Signal

Formal parameters

Q 5.1

Actual parameters

1.1

SIMATIC S7

Siemens AG 2004. All rights reserved.

#Display

Date:
File:

04/20/15
PRO1_12E.7

SITRAIN Training for


Automation and Drives

Declaring the Formal Parameters in FC 20


Formal Parameters
Type of Parameter
Input parameter
Output parameter
In/Out parameter

SIMATIC S7

Siemens AG 2004. All rights reserved.

Declaration
in
out
In_out

Use
Read only
Write only
Read / Write

Date:
File:

04/20/15
PRO1_12E.8

Graphic Display
To the left of the block box
To the right of the block box
To the left of the block box

SITRAIN Training for


Automation and Drives

Editing a Parameter-assignable Block

SIMATIC S7

Siemens AG 2004. All rights reserved.

Date:
File:

04/20/15
PRO1_12E.9

SITRAIN Training for


Automation and Drives

Calling a Parameter-assignable Block

SIMATIC S7

Siemens AG 2004. All rights reserved.

Date:
File:

04/20/15
PRO1_12E.10

SITRAIN Training for


Automation and Drives

Exercise 1: Editing a Parameter-assignable Function

Declaring the Formal Parameter

SIMATIC S7

Siemens AG 2004. All rights reserved.

Date:
File:

04/20/15
PRO1_12E.11

SITRAIN Training for


Automation and Drives

Exercise 2: Calling a Parameter-assignable Function

1st. call of FC 20 for


display of Disturb. 1

2nd. call of FC 20 for


display of Disturb. 2

SIMATIC S7

Siemens AG 2004. All rights reserved.

Date:
File:

04/20/15
PRO1_12E.12

SITRAIN Training for


Automation and Drives

Function Blocks (FB)

Declaration Table
of the
Function Block

Call of
Function Block
such as in OB1

DB 2
FB 20
EN
Fault_Signal
Acknowledge
Flash_Freq.

SIMATIC S7

Siemens AG 2004. All rights reserved.

Date:
File:

04/20/15
PRO1_12E.13

Display
ENO

SITRAIN Training for


Automation and Drives

Function Block for Fault Display

Declaration Table
of the
Function Block
Instance
Data block

SIMATIC S7

Siemens AG 2004. All rights reserved.

Date:
File:

04/20/15
PRO1_12E.14

SITRAIN Training for


Automation and Drives

Generating Instance Data Blocks


1. Generate instance DB with FB call

2. Create new instance DB

In the LAD/STL/FBD Editor

SIMATIC S7

Siemens AG 2004. All rights reserved.

In the SIMATIC Manager

Date:
File:

04/20/15
PRO1_12E.15

SITRAIN Training for


Automation and Drives

Exercise 3: Editing a Function Block

SIMATIC S7

Siemens AG 2004. All rights reserved.

Date:
File:

04/20/15
PRO1_12E.16

SITRAIN Training for


Automation and Drives

Exercise 4: Calling a Function Block and Testing It


Current situation

SIMATIC S7

Siemens AG 2004. All rights reserved.

Result after the exercise

Date:
File:

04/20/15
PRO1_12E.17

SITRAIN Training for


Automation and Drives

Sa

ve

Inserting/Deleting Block Parameters Later On

SIMATIC S7

Siemens AG 2004. All rights reserved.

Date:
File:

04/20/15
PRO1_12E.18

SITRAIN Training for


Automation and Drives

Checking the Block Consistency

Block inconsistency

SIMATIC S7

Siemens AG 2004. All rights reserved.

Date:
File:

04/20/15
PRO1_12E.19

SITRAIN Training for


Automation and Drives

Corrections when Calling Modified Blocks

Once with the right

SIMATIC S7

Siemens AG 2004. All rights reserved.

Date:
File:

04/20/15
PRO1_12E.20

SITRAIN Training for


Automation and Drives

Comparison of Functions and Function Blocks


Program
execution
CALL FC 10
On_1 :=
On_2 :=
Off
:=

I 0.1
I 0.2
Q8.0

Function FC10

...
A
A
=
...

SIMATIC S7

Siemens AG 2004. All rights reserved.

On_1
On_2
Off

in
Start
in
Stop
out Motor_on
out Speed
stat ...
Temp...

BOOL
BOOL
BOOL

#On_1
#On_2
#Off

...
A
AN
=
...

Date:
File:

04/20/15
PRO1_12E.21

DB 5
0.0
0.1
2.0
4.0

FB 5
in
in
out
...

Drive

CALL FB5, DB5


Start
:=I 0.0
Stop
:=I 0.1
Motor_on
:=Q8.0
Speed :=QW12

Start
Stop
Motor_on
Speed

BOOL
BOOL
BOOL
INT

BOOL
BOOL
BOOL
INT

#Start
#Stop
#Motor_on

SITRAIN Training for


Automation and Drives

Exercise 5: Recognizing Types of Variables

Statement
L
L
T
L
T
T

Global

Local

Absolute

Symbolic

Static

Parameter

#Number_1
#Number_2
#Maximum_value
"Number_1"
MW 40
MW 40
#Number_2

SIMATIC S7

Siemens AG 2004. All rights reserved.

Date:
File:

04/20/15
PRO1_12E.22

SITRAIN Training for


Automation and Drives

Using the EN/ENO Output


LAD/FBD

STL

FC 1
Unconditional call

Conditional call

...

EN

ENO

Q5.0

FC 1
EN
ENO

I 0.1

=
_001:

Example

ADD_I
...

SIMATIC S7

Siemens AG 2004. All rights reserved.

EN

MUL_I

ENO

EN

Date:
File:

ENO

04/20/15
PRO1_12E.23

CALL
NOP 0

FC

A
JNB
CALL
A
=

I
_001
FC
BR
Q

0.1

DIV_I
EN

ENO

1
5.0

Q 5.1
=

SITRAIN Training for


Automation and Drives

Summary: Block Calls


FC
Language

STL

FB

without parameters

with parameters

CALL FC1
UC FC1
CC FC1

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

w/o parm., w/o stat var.

UC FB1
CC FB1

with parm., and/or stat var

CALL FB2, DB3


Par1: ...
Par2: ...
Par3: ...

FC1
( CALL )
LAD

FC2

FC1
EN

ENO

EN

not available

ENO

Par1
Par2

DB3
FB2
EN
Par1

Par3

Par2

FC1
CALL
FBD

EN

EN

Par3

DB3
FC2

FC1

ENO

FB2
Par3

not available

Par1
Par2

EN
Par1
Par2

ENO

Par3
ENO

ENO

SIMATIC S7

Siemens AG 2004. All rights reserved.

Date:
File:

04/20/15
PRO1_12E.24

SITRAIN Training for


Automation and Drives

You might also like