Function Block (Fb) - Siemens S7-1200 System Manual

Hide thumbs Also See for S7-1200:
Table of Contents
6.3.3

Function block (FB)

A function block (FB) is a code block that uses an instance data block for its parameters and
static data. FBs have variable memory that is located in a data block (DB), or "instance" DB.
The instance DB provides a block of memory that is associated with that instance (or call) of
the FB and stores data after the FB finishes. You can associate different instance DBs with
different calls of the FB. The instance DBs allow you to use one generic FB to control
multiple devices. You structure your program by having one code block make a call to an FB
and an instance DB. The CPU then executes the program code in that FB, and stores the
block parameters and the static local data in the instance DB. When the execution of the FB
finishes, the CPU returns to the code block that called the FB. The instance DB retains the
values for that instance of the FB. These values are available to subsequent calls to the
function block either in the same scan cycle or other scan cycles.
Reusable code blocks with associated memory
You typically use an FB to control the operation for tasks or devices that do not finish their
operation within one scan cycle. To store the operating parameters so that they can be
quickly accessed from one scan to the next, each FB in your user program has one or more
instance DBs. When you call an FB, you also specify an instance DB that contains the block
parameters and the static local data for that call or "instance" of the FB. The instance DB
maintains these values after the FB finishes execution.
By designing the FB for generic control tasks, you can reuse the FB for multiple devices by
selecting different instance DBs for different calls of the FB.
An FB stores the Input, Output, and InOut, and Static parameters in an instance DB.
You can also modify and download the function block interface in RUN mode.
Assigning the start value in the instance DB
The instance DB stores both a default value and a start value for each parameter. The start
value provides the value to be used when the FB is executed. The start value can then be
modified during the execution of your user program.
The FB interface also provides a "Default value" column that allows you to assign a new start
value for the parameter as you are writing the program code. This default value in the FB is
then transferred to the start value in the associated instance DB. If you do not assign a new
start value for a parameter in the FB interface, the default value from instance DB is copied
to start value.
S7-1200 Programmable controller
System Manual, 03/2014, A5E02486680-AG
Programming concepts
6.3 Using blocks to structure your program
175
Table of Contents
loading

Table of Contents