0% found this document useful (0 votes)
25 views23 pages

TIA PRO2 08 FC FB Multi Instances

The document provides a comprehensive guide on programming reusable blocks in the SIMATIC TIA Portal S7-1500, focusing on the concepts of functions, function blocks, and multiple instances. It outlines the differences between global and local operands, the principles of structured programming, and the importance of reusability in block programming. Additionally, it includes exercises and examples to illustrate the application of these concepts in practical scenarios.

Uploaded by

adamraz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views23 pages

TIA PRO2 08 FC FB Multi Instances

The document provides a comprehensive guide on programming reusable blocks in the SIMATIC TIA Portal S7-1500, focusing on the concepts of functions, function blocks, and multiple instances. It outlines the differences between global and local operands, the principles of structured programming, and the importance of reusability in block programming. Additionally, it includes exercises and examples to illustrate the application of these concepts in practical scenarios.

Uploaded by

adamraz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

SIMATIC TIA Portal S7-1500 Programming 2

Contents 8
Functions, Function Blocks and Multiple Instances ........................................... 8-2
8.1. Task Description: Programming Re-usable Blocks ............................................................. 8-3
8.2. Local and Global Operands .................................................................................................. 8-4
8.3. Structured Programming and Re-usable Blocks................................................................... 8-5
8.3.1. Block Properties: Compilation ............................................................................................... 8-6
8.4. Properties of Functions ......................................................................................................... 8-7
8.4.1. Properties of Function Blocks ............................................................................................... 8-8
8.5. Parameter Visibility / Predefinition (1) ................................................................................... 8-9
8.5.1. Parameter Visibility / Predefinition (2) ................................................................................. 8-10
8.6. Instance Formation of Function Blocks ............................................................................... 8-11
8.6.1. Creating Instances of IEC-Functions in a Global Data Block ............................................. 8-12
8.6.2. Passing an Instance as a Parameter .................................................................................. 8-13
8.7. Exercise 1: "FC_Fault": Using a Global-DB Variable for the IEC-Timer-Instance .............. 8-14
8.7.1. Exercise 2: Programming "FC_Fault" re-usable using a Parameter Instance .................... 8-15
8.8. Structure of the Multiple Instance Model ............................................................................ 8-16
8.9. Changing the Block Call ...................................................................................................... 8-17
8.10. Exercise 3: Programming "FB_Statistic" as Re-usable ...................................................... 8-18
8.10.1. Exercise 4: Programming "FB_Signal" as Re-usable ......................................................... 8-19
8.10.2. Exercise 5: Replacing the Call of "FC_Signal" with "FB_Signal" ........................................ 8-20
8.11. Additional Information ......................................................................................................... 8-21
8.11.1. Local, Temporary Variables ................................................................................................ 8-22
8.11.2. Local Data Stack ................................................................................................................. 8-23

TIA-PRO2 - Functions, Function Blocks and Multiple Instances 8-1


Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

Functions, Function Blocks and Multiple Instances

At the end of the chapter the participant will...

... have an overview of global and local operands

… understand the properties of functions and function


blocks

… understand the properties of block parameters and be able to


apply them

… understand the term “re-usability” and be able to


implement it

… understand the concept of multiple instances and be


able to use them

… be able to program re-usable blocks

TIA-PRO2 - Functions, Function Blocks and Multiple Instances


8-2 Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.1. Task Description:


Programming Re-usable Blocks

Task Description
According to the IEC61131-3 standard, global operands must not be used within FCs and FBs,
that is, no inputs, outputs, memory bits, data block variables, SIMATIC timers / counters. Allowed
are only local operands, that is, only parameters and local variables (tags).
The communication of the block with its "outside world" occurs exclusively through the interface
of the block or only through the input, output and in/out parameters. This also means that the
block works with no other operands than with those that are passed formal operands during the
block call.
This ensures that a block is "re-usable", that is, can also be integrated in other programs
unchanged.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances 8-3


Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.2. Local and Global Operands

Global Operands Local Operands


(valid in the entire program) (only valid in one block)
Formal Parameters (Input, Output, InOut)

• Process image for • interface for data exchange between calling and called block
inputs and outputs • temporary storage in the L-stack for FCs or storage in the IDB for FBs
• can be used in FCs / FBs

• I / O peripherals
Temporary Variables (Temp)
• are overwritten after the block is executed
• Memory bits • temporary storage in the local data stack (L-stack)
• can be used in OBs / FCs / FBs
• Variables in DBs Static Variables (Static)
• retain their value after the block is executed
• S5-Timers and Counters • permanent storage in instance data block (IDB)
(not for S7-1200)
• can only be declared in FBs
Constants (Constant)
• Constants • read-only as well as only symbolic access
• no memory usage
• can be used in OBs / FCs / FBs

Global Operands
Global operands are valid throughout the entire S7 program. Accordingly, every code (logic) block
(OB, FC, FB) can access these operands.
Global operands include inputs, outputs, memory bits, SIMATIC timers, SIMATIC counters,
constants and variables which are declared in global data blocks.

Local Operands
Local operands are only valid in the block in which they were declared in the declaration part.
Accordingly, only this block can access them.
• Formal Parameters
Formal parameters form the interface between the calling and the called block (FC, FB).
They are used to realize a data exchange between the calling and the called block.
• Temporary Variables
Temporary variables can be declared in every code (logic) block (OB, FC, FB) and are
managed in the local data stack of the CPU. Accordingly, they only retain their values while
the block is being executed. For that reason, it is important that in the current cycle, a write
access must have taken place on the temporary variable in the block before a read access
can take place. They are, for example, unsuitable as auxiliary variables for edge evaluations
or to store quantities. They are, in fact, used to store intermediate results, such as, for
complex calculations or format conversions.
• Static Variables
Static variables can only be declared in FBs and are stored in the associated instance data
block. Accordingly, these variables retain their value even after the FB is executed.
• Constants
Constants are fixed values which have a read-only access and which do not take up any
memory space.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances


8-4 Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.3. Structured Programming and Re-usable Blocks

"iDB_Motor" "iDB_Controller"
Modularization of the entire task:
"FB_ "FB_
 Partial tasks are solved in separate "TON"
Motor" Controller"
programs or blocks "OB_
Cyclic_A"
 Parameter assignment enables "iDB_Valves"
flexible usage
"FB_ "FC_
"BLKMOV"
• Example: Drilling cycle with Valves" Limit"
changeable depth

Re-usability of blocks: "iDB_Motor"


"OB_Cyclic_B"
 Blocks can be called as often as is "FB_Motor"
required
"iDB_Motor" Decl. Name Type
 Restrictions: "FB_Motor"
in Start BOOL
in Stop BOOL
out Motor_on BOOL
• No access to global operands or Start Motor_on
out Speed INT
global constants Stop Speed stat Speed_old INT
temp Calc_1 INT
• Communication only via the parameter :
:
list A #Start

Modularization of the Entire Task


Abstraction is the basis for solving complex problems, in which we concentrate on the
fundamental aspects of a program in every abstraction level and ignore all the details that are not
essential. Abstraction helps us to divide complex tasks into partial tasks which can then be solved
on their own.

Parameter-assignable (Re-usable) Blocks


STEP 7 supports this concept of modularization with its block model. The partial tasks that result
from the division of the entire task are assigned to blocks in which the necessary algorithms and
data for solving the partial problems are stored. STEP 7 blocks such as functions (FC) and
function blocks (FB) can be assigned parameters so that the concepts of structured programming
can be implemented with them. This means:
• Blocks for solving partial tasks implement their own data management with the help of local
variables.
• Blocks communicate with the "outside world", that is, with the sensors and actuators of the
process control or with other blocks, exclusively through their block parameters. No access to
global operands such as inputs, outputs, memory bits or variables in DBs can be made from
within the statement section of blocks.

Advantages
• The blocks for the partial tasks can be created and tested independent of one another.
• With the help of parameters, blocks can be designed so that they are flexible. That way, for
example, a drilling cycle can be created that has the coordinates and the depth of the drilling
hole passed on to it by means of parameters.
• Blocks can be called as often as is required in different locations with different parameter
sets, that is, they can be reused.
• "Re-usable" blocks for special tasks can be delivered in pre-designed libraries.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances 8-5


Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.3.1. Block Properties: Compilation

Re-usable

Cannot
nicht be re-used
Wiederverwendbar

Can be called several times in


the current program

In the Properties of FCs and FBs, you can check whether the block was programmed as re-
usable.

Object is Library-conformant:
The block is re-usable and so can be called several times without a problem. It can also be used
in other projects/devices without adjustments and can be implemented with the help of libraries.

Warning or Error:
The use of the block in other devices or projects can lead to problems or requires adjustments in
the new project or in the block itself. Calling the block several times in the same program may not
be possible.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances


8-6 Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.4. Properties of Functions

Parameter-assignable blocks:
Function FC10
• As many input, output and
in/out parameters as required in On1 BOOL
• Without memory, that is, only in On2 BOOL
temporary variables out Off BOOL
temp …
• Constants Program const …
execution
...
IEC 61131-3-conforming:
FC 10 &
• As many input parameters as required Off #On1 IN2
%I 0.0 On1 %Q8.4
#On2 IN1 OUT #Off
• Only one output parameter RET_VAL %I 0.1 On2
• No access to global variables, global ...
constants and absolute operands
• Deliver the identical result for the
same input parameters

Overview
Functions represent parameter-assignable blocks without memory. In STEP 7 they can have as
many input parameters, output parameters and in/out parameters as are required. Additionally,
constants that are local in the block can be created for S7-1200/1500.
Functions have no memory; no separate, permanent data area for storing results exists.
Temporary results that occur during function execution can only be stored in the temporary
variables of the respective local data stack.

Application
Functions are primarily used when function values are to be returned to the calling blocks (for
example, mathematical functions, single control with binary logic operation).

IEC-61131-Conforming Functions
If IEC 61131-3-conforming functions are to be created, then the following rules must be observed:
• Functions can have as many input parameters as is required. They can, however, only return
one result to the output parameter RET_VAL.
• Global operands can neither be read nor written within functions.
• No instances of function blocks can be called within functions.
• Because of the missing "memory", the returned result of a norm-conforming function is solely
dependent on the values of the input parameter. For identical values of the input parameter, a
function also returns the identical result.
It is therefore up to the programming person to create norm-conforming functions or to do the
block programming and structuring in STEP 7 as it is in STEP 5.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances 8-7


Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.4.1. Properties of Function Blocks

Parameter-assignable blocks: Drive


DB 16
• IEC 61131-3-conforming
0.0 Start BOOL
• As many input, output and 0.1 Stop BOOL
in/out parameters as required 2.0 Motor_ON BOOL
• With memory, that is, not only FB 5 4.0 Speed INT
temporary but also static variables 6.0 stat_ON BOOL
Program
• Constants execution in Start BOOL
• Call with own data area in Stop BOOL
(instantiating) out Motor_ON BOOL
DB6
• "Data encapsulation" out Speed INT
FB5
stat stat_ON BOOL
Application: %I 0.0 Start Motor_ON %Q8.0 temp ...
%I 0.1 Stop Speed %QW6 const …
• Timer and counter functions
#stat_ON
• Controlling process units with
internal states SR
#Start S
• boilers
#Stop R
• drives, valves, etc. OUT #Motor_ON

Overview
Function blocks (FB) are blocks of the user program and represent logic blocks with memory
according to the IEC Standard 61131-3. They can be called by OBs, FBs and FCs.
In function blocks, as many input, output and in/out parameters, static and temporary variables as
are required can be declared, as well as constants that are local in the block for S7-1200/1500.
Unlike FCs, FBs are instantiated, that is, an FB is assigned its own private data area in which the
FB can "remember" process states from call to call, for example. In the simplest form, this private
data area is its own DB, the so-called instance DB.

"Memory"
The programming person has the opportunity to declare static variables in the declaration section
of a function block. The function block can "remember" information from call to call in these
variables.
The ability of a function block to "remember" information over several calls is the essential
difference to functions.

Application
With the help of this "memory", a function block can implement counter and timer functions or
control process units, such as processing stations, drives, boilers etc., for example.
In particular, function blocks are well suited for controlling all those process units whose
performance depends not only on outside influences but also on internal states, such as
processing step, speed, temperature etc.
When controlling such units, the internal status data of the process unit are then copied to the
static variables of the function block.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances


8-8 Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.5. Parameter Visibility / Predefinition (1)

Visibility in Block Calls in LAD/FBD:


When a block is called, the block parameters can be hidden. Here, there are several possibilities:
‘Show’, ‘Hide’ or ‘Hide if no parameter is assigned’.
In a block call, hidden parameters can be indicated through a small icon in the form of a triangle
(see next page).

Predefined Actual Parameter:


If it is already clear during block creation with which actual parameter the formal parameter is to
be supplied, then you can store this information as a property of the parameter. When the block is
called, this parameter is then automatically supplied with the actual parameter. However, it can
be changed at any time.
In addition, you can also store the property “Show if parameter assigned on block call is not
identical to the predefined actual parameter” for the parameter (only to be displayed when the
actual parameter does not match the predefined actual parameter).

TIA-PRO2 - Functions, Function Blocks and Multiple Instances 8-9


Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.5.1. Parameter Visibility / Predefinition (2)

1 2

3
4

In the example you can see that the parameters "Sensor1" and "Sensor2" have the property
“Hide”. For that reason, they are not displayed during the call Picture (1). In addition, the
parameter "Sensor1" was preassigned with the actual parameter "B_Bay1" Picture (2) and given
the property “Show if parameter assigned on block call is not identical to the predefined actual
parameter”. Since the actual parameter of "Sensor_1" is changed in Picture (3) vis-à-vis Picture
(2), it is no longer hidden in Picture (4).

TIA-PRO2 - Functions, Function Blocks and Multiple Instances


8-10 Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.6. Instance Formation of Function Blocks

FBx "instance" • Single instance (DB)


OB, FB or FC • Instance in Global–DB
Algorithm Count • Parameter instance
CALL FBx, "instance" for
... + values for
... counting Bay 1

FB instance
FB x

Count
stat Bay_1_count FBx
stat Bay_2_count FBx values for
stat Bay_3_count FBx
FBy Bay 1

CALL #Bay_1_count Algorithm Count


CALL #Bay_2_count for values for
CALL #Bay_3_count counting Bay 2

Count
• Multiple instances
values for
Bay 3

What is an Instance?
The concept of the instantiation of function blocks has importance and forms the fundamental
difference to functions. The creation of tags within a high level language, such as, "C" specifying
the tag name and the data type is called "instantiation" or "instance formation".
Just like tags, function blocks are also "instantiated". Only through the assignment of its own data
area in which the values of the block parameter as well as the static variables are stored does a
function block become an executable unit (FB instance).
The control of a physical process unit, such as, a drive or a boiler then takes place with the help
of an FB instance, that is, a function block with associated data area. The relevant data for this
process unit is then stored in this data area.
The formation of an instance, that is, the assignment of its own memory area during an FB call
can occur in several ways in STEP 7:
− by explicitly specifying a so-called instance data block during the call of the function block.
− by explicitly declaring instances of an IEC function within a global data block
− by explicitly declaring a parameter instance and transfer the instance as an in/out
parameter,
− by explicitly declaring instances of a function block within a higher-level function block
(multiple instance model).

Advantages
• In the call of FBs, no measures for saving and administrating local data are necessary except
for the assignment of instance DBs.
• A function block can be used several times due to the instance concept. If, for example,
several drives of the same type are to be controlled, then this takes place using several
instances of an FB. The status data of the individual drives are stored in the static variables of
the FB.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances 8-11


Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.6.1. Creating Instances of IEC-Functions in a Global Data Block

Application
With that, the instance data of IEC counters and timers used within a global data block (see
picture).
However, it must be noted that because of this the calling Block (in the example "FC_Counter") is
not IEC-conform and with that is not re-usable, since even the passing of IEC counter instances,
represents the use of global operands.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances


8-12 Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.6.2. Passing an Instance as a Parameter

• Single instance
• Instance in Global–DB
• Multiple instance
• Parameter instance

The passing of an instance by means of an IN-OUT parameter offers a further possibility of


instantiation. This has the advantage that the actual instance which is required within a block can
be specified during the call of the block. This makes it possible to also blocks, which use function
blocks or instructions with instances, as re-usable.

Supplying the Formal Parameter:


The actual parameter can, in turn, be an instance data block, a DB-variable of the type IEC-
Function, a multiple instance or a parameter instance.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances 8-13


Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.7. Exercise 1: "FC_Fault": Using a Global-DB Variable for the IEC-


Timer-Instance

Horizontally split
editor area

Task
Using drag & drop, you are to replace the separate single instance in "FC_Fault" with an instance
which was previously declared in the global "DB_Conveyor".
Note:
With this change, the block is not yet re-usable. This will be realized in the next exercise.

What to Do:
1. In "DB_Conveyor", create the variable "instance_IECTimer" shown in the picture.
2. Horizontally split the editor area (see picture) so that the two blocks "DB_Conveyor" and
"FC_Fault" are displayed simultaneously.
3 In "FC_Fault", using drag & drop, replace the separate single instance-DB with the Global-
DB-Instance which you previously declared in "DB_Conveyor".
4. Transfer all modified blocks into the CPU and test the program.
5. Save your project.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances


8-14 Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.7.1. Exercise 2: Programming "FC_Fault" re-usable using a Parameter Instance

Change single instance into


a parameter instance

Update FC call

1xR

Task
In "FC_Fault", you are to replace the Global-DB-Instance with a Parameter-Instance which then is
once again assigned with the Global-DB-Instance during the call of "FC_Fault".
Realize an automatic parameter assignment of the parameter instance by setting the Properties
of the parameter.
Note:
With this change, the block is re-usable.

What to Do:
1. Open the "FC_Fault" block.
2. Through the context menu of the ON-Delay, open the "Call options" function via the "Change
instance…" function.
3. Change the single instance into a parameter instance with the name "instance_IECTimer".
4. Select the parameter instance in the interface of the block and open the Properties in the
Inspector window.
5. As predefined "Actual Parameter", specify the variable "DB_Conveyor".instance_IECTimer.
6. Update the call of the function in "OB_Cycle".
Note: The new parameter is automatically linked to the variable
"DB_Conveyor".instance_IECTimer.
7. Transfer all modified blocks into the CPU and test the program.
8. Save your project.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances 8-15


Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.8. Structure of the Multiple Instance Model

"Instance-x"
FBx FBy
...
OB, FB or FC stat Drill FBy Algorithms
for drilling
stat Motor_1 FBz Data for
stat Motor_2 FBz Drill

.
CALL FBx,
"instance-x" CALL Drill
. Data
. FBz for Motor_1
CALL Motor_1
. Control of a
motor
CALL Motor_2

Data
for Motor_2
• Single instance (DB)
• Instance in Global–DB
• Parameter instance
• Multiple instance also possible Instance of FBx

Multiple Instance Model


In addition to instantiation of function blocks when you specify an instance DB in an FB call,
STEP 7 also supports the explicit declaration of FB instances within a higher-level function block.
For this purpose, instances of the called function blocks are declared with data type FBy or FBz
using symbolic identifiers (Drill, Motor_1 and Motor_2). This takes place in the declaration section
of the calling FBx function block in the section "static variable". Within the higher-level function
block, the individual instances are then called using their symbolic identifier. The higher-level FBx
function block must however be called with its own instance DB (instance-x).
In the creation of the higher-level instance DB, STEP 7 makes sure that the data areas required
for the individual instances are set up in the data area of the higher-level FBx.

Advantages
The use of the multiple instance model has the following advantages:
• The individual instances do not require their own data block every time. Within a call hierarchy
of function blocks, only one instance DB is used in the call of the "outer" function block.
• The multiple instance model "welds" a function block and an instance data area into one
object (FB instance), that can also be handled as one unit. The programming person does not
have to take care of the management (creation, addressing) of the individual instance data
areas. He must simply provide an instance DB for the "outer" FB.
• The multiple instance model supports an object-oriented programming style.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances


8-16 Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.9. Changing the Block Call

In order to replace the call of a block with another block call, you can open a selection list of all
FCs and FBs at the calling point by double-clicking on the name of the already called block.

Advantage:
If the newly called block has the same formal parameters, it retains its actual parameters and
doesn’t have to be resupplied.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances 8-17


Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.10. Exercise 3: Programming "FB_Statistic" as Re-usable

Change to Multi-Instance

1xR

Task
In "FB_Statistic", the counting of the parts transported to Bay 1, 2 or 3 is implemented with IEC
counters whose data is stored in individual instances.
As previously with the "FC_Fault" block, "FB_Statistic" is now also to be modified in such a way
that it fulfills the requirements of IEC61131-3, making it "re-usable".
For this, the instances used so far in the program, which were used to store the instance data of
the IEC-COUNTER, must be replaced with multiple instances.

What to Do
1. Open "FB_Statistic", right-click on the first IEC-Counter and select the function "Change
instance…" (see picture).
2. In the dialog that appears, select "Multi-Instance" and give it the name
instance_IECCounter_1.
3. Repeat this with the two other IEC-Counters and give them the names
instance_IECCounter_2 and instance_IECCounter_3
4. Additional: If you programmed the function block "FB_TP_Sync" in the last chapter, then you
change the instances of the IEC-Timers in the function block "FB_TP_Sync" also.
5. After you have changed all instances into multi-instances, compile the entire S7 program,
because the call of "FB_Statistic" in "OB_Cycle" and the instance-DB passed there to the FB
are thereby also updated.
6. Delete the instance-DBs of the IEC-Counters since they are now no longer required.
7. Download the entire S7 program into the CPU and check all program functions.
8. Save your project.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances


8-18 Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.10.1. Exercise 4: Programming "FB_Signal" as Re-usable

3
Multi-instance

Task
Up until now, "FC_Signal" has been responsible for energizing the indicator lights.
The new "FB_Signal" block is to replace the previous "FC_Signal" and is to be created in such a
way that it fulfills the requirements of IEC61131-3, making it "re-usable".

What to Do
1. Insert the new "FB_Signal" block into your S7 program and open it.
2. Split the working area and open the "FC_Signal" block in the second half.
3. Copy all parameters and local variables from the interface of "FC_Signal" into the interface of
"FB_Signal".
4. Copy all networks from the "FC_Signal" block into the "FB_Signal" block.
5. Change the instance of the "LGF_Frequency" function block into a multiple instance.
6. Save your project.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances 8-19


Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.10.2. Exercise 5: Replacing the Call of "FC_Signal" with "FB_Signal"

Task
The call of the "FC_Signal" block is to be replaced with the call of the "FB_Signal" block.

What to Do
1. Open "OB_Cycle" and go to the call of "FC_Signal".
2. Open the selection menu of the blocks by double-clicking on the name "FC_Signal".
3. Select the "FB_Signal" block.
4. Open the context menu of the block call and choose the function "Create instance…".
5. In the follow-up window, give the single instance the name "iDB_FB_Signal"
6. As backup, you can copy "FC_Signal" into your Project library and then delete it since it is no
longer required.
7. Save, compile, download and test your project.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances


8-20 Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.11. Additional Information

TIA-PRO2 - Functions, Function Blocks and Multiple Instances 8-21


Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.11.1. Local, Temporary Variables

1. Declaration

2. Assignment

3. Scan

Declaration
The variables are also defined in the declaration part of the block. The name of the variable and
the data type must be specified.

Access
With optimized blocks, all temporary variables are initialized with 0 at the beginning of block
execution.
With non-optimized blocks, all temporary variables have an undefined value at the beginning of
block execution. When working with temporary variables, you must therefore make sure that the
variable is first of all assigned a defined value before it is scanned.
In the example, the result of the Addition is assigned to the temporary variable #inRes before it is
then scanned during the Multiplication.

Note
Variables that begin with the # special character are local variables (parameters or local
variables) that must be declared in the declaration part of the block. Local variables are only valid
and usable in the block in which they were declared.
The Program Editor automatically inserts the # character.

TIA-PRO2 - Functions, Function Blocks and Multiple Instances


8-22 Training Document V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

8.11.2. Local Data Stack

Operating system

OB 1 2 FC 17 3 FC 20 Event 1 2 3 4 5 6 7

with temp. 4 with temp.


variables variables
Usage of
the Local FC20
5 FC30
FC 30 data stack
7 FC17 FC17 FC17 FC17 FC17
6 with temp. OB 1 OB 1 OB 1 OB 1 OB 1 OB 1 OB 1
variables

Total Usage of the Local Data Stack (L-Stack)


For every program execution level or priority class (such as, OB 1 with all blocks that are called in
it), a separate local data stack is reserved. That is, a segment of defined size is reserved on the L
stack of the CPU (allocation or reservation of memory space).
The local variables/operands of OB 1 as well as the local, temporary variables of the blocks (FCs
and FBs) called in or by OB 1 are stored in this local data stack.
You can use the "Reference Data" tool to display the "Program Structure" to see to what extent
an S7 program puts a burden on the local data stack. (The reference data and where they are
displayed is dealt with in the chapter "Troubleshooting".)

TIA-PRO2 - Functions, Function Blocks and Multiple Instances 8-23


Training Document V15.01.00

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy