Allen Bradley PLC programming course.
Enroll Today!
Siemens PLC programming course
Register for FREE!
Back to tutorials

Understanding Function Block Instances (Single, Multi and Parameter) in Siemens TIA Portal

By
Victory Edema
Learning Path
No items found.
Table of Contents

Introduction

Function blocks are program blocks that permanently store their input, output, and in-out parameters in instance data blocks, allowing them to be accessed even after the block has been processed. As a result, they are also known as "memory blocks." An instance is the result of a function block's call. Each function block instance requires an instance data block, which includes instance-specific values for the function block's formal parameters. The function block instance-specific data might be stored in its instance data block or the calling block's instance data block.

In this tutorial, we will be looking at the different types of function block instances that can be used in PLC programming using Siemens TIA Portal.

Prerequisite

In order to follow along with this tutorial, you will need:

Differences between Function and Function Block

There are many difference between a function and function. Some are highlighted below

Basics of Instance

A function block requires memory for its working data once it is called. A single piece of data is referred to as an instance.

  • When a function block is called, instances are created automatically.
  • An instance's structure is generated from the related FB's interface and may only be altered there.
  • Instances are permanently assigned to a function block.

Instance Storage

There are three different options for storing instances, they are as follows

  1. Single Instance
  2. Multi-Instance
  3. Parameter Instance

Single Instance

In a single instance, the called block saves its own data in its instance block. Let us look at an example.

Create a new project in TIA Portal

Fig 1.1 showing the addition of a new device 

Create a function block with the following parameters

Fig 1.2 Parameters of the function block 

Write the following ladder logic operation to perform a simple calculation as shown in the image below

Fig 1.3 Ladder logic example for a single instance

Next, we call the function block in OB1. At the call, a prompt is shown seeking if you want to create a data block for the called function block. We select single instance.

Fig 1.4 Function block call prompting for data block creation

A data block is created in the project tree for the function block we just called. The data block “Use case_DB” is the instance of the Use Case function block that holds the data.

Fig 1.5 Called function block in OB1

We pass our parameter tags through the FB. Compile and download.

Fig 1.6 Parameter passed through the called function block

The data block for this function block instance holds the data as shown below

Fig 1.7 Data block for called function block

The Input, Output, InOut, and Static parameters are stored in the instance data block. Temp and constant are not stored. 

If another instance of the Function block is called, it generates another separate data block as seen below.

Fig 1.8 Another instance of the function block call

Parameter Instance

A unique option for instantiation is provided by the parameter instance. Here, the block instance that will be used is passed as an in-out argument (InOut) to the calling block during execution. Also calling a function block in a function will give the option of choosing multi-instance.

Let us create a function and call the Use Case Function block we have already created.

Fig 1.9 Multi-Instance drop-down

 

The instance data is stored in the “Use Case_instance” in the InOut parameter section of the calling function or function block. This is shown in Fig 2.0

Fig 2.0 Parameter Instance Data block

Calling this function on the OB1, the data block selected will be the “Reuseable’’ function we created. 

The input and outputs parameter will need to be created 

Fig 2.1 Function call in OB1

Now, the function needs a data block to work with it. Create a data block, navigate to the drop-down arrow, and select the function block (Use Case). This means that this data block to be created will have the parameters of the use case.

Fig 2.2 Data block for ‘’Reusable’’ function instance

Tag the function with the data block created in OB1.

Fig 2.3 Data block passed as an instance parameter to the function

A separate data block instance will be needed any other time this block is called. This is illustrated in the image below.

Fig 2.4 Instances of the ‘’Reusable’’ function 

Advantages of Parameter Instance

  • Which instance is currently being utilized can be specified at runtime.
  • In program loops, various instances can be processed iteratively.

Multi-Instance

A function block (FB) can keep its instance data in the calling FB's instance database when it calls another Function block. A multi-instance block call is this kind of block call. 

Create a function block and call it "Use case”. Call the function block in ‘’This Case function block and select multi-instance as the call option.

Fig 2.5 Function block call while selecting Multi-Instance

Here, the use case instance data is stored in the static parameter of the calling function block.

Fig 2.6 Figure showing the static parameter of the block call

We noticed that the Use Case data block is stored in the static variable parameter area of the calling function block. 

Calling the function block in OB1 will give a prompt to create a data block select ‘’ok’.

Fig 2.7 Function block call in OB1

We can see that the data is being stored in the data block of the calling function block as shown in the image below

Fig 2.8 Data Block parameter view of ‘’This Case’’ Function block

Calling the “Use Case” function block again shows the following

Fig 2.9 Another block call of Use Case function block in “This case” Function Block

So for every block call, the data is being stored in the static area data area.

Array Method for Multi-Instance

Another method for multi-instance block call will be to use an array. Delete the previously created data in the static area of the function block and create an array as shown below.

Fig 3.0 Array data type creation for Multi-Instance

Here, the data type selected is “Use Case”. This will give the format of the arrays created Use Case parameters.

Address the function blocks as shown below.

Fig 3.1 Using Array as the data block Instance

The final addressing is displayed below

Fig 3.2 Multi-Instance arrays for function block call

Update the block call in OB1. The data is also stored in the ‘’This Case’’ data block. 

Fig 3.3 Data block parameters showing arrays of multi-instances

This is another effective way to create multi-instances of a Function block.

Advantages of Multi-Instance

  • Fewer instance Data blocks
  • Provides a good structuring approach for complex blocks

More on Parameter Instance

The parameter instance could also be an array of multi-instance from another Function block. From our previous example on parameter instance, let us use the multi-instance array we created as an instance parameter.

Fig 3.4 Passing Multi-Instance arrays as parameter instance

Consequently, you can pass the following types of instances as a parameter instance each time the higher-level function block is called:

  • Single instance: Transfer an existing instance data block of the called function block. 
  • Multi-instance: Transfer an existing multi-instance of the called function block. 
  • Individual element of an ARRAY of multi-instances: Transfer an element of an existing ARRAY of multi-instances.

Conclusion

As a Siemens PLC programmer using TIA Portal, function block instances is a piece of knowledge, you would want to have under your belt. This makes the parameterization of blocks easier and more efficient. This is for advanced PLC programmers seeking to take their programming skills to the next level. A good practice will be to experiment with the different instance methods taught in this tutorial to become proficient in them.

Back to tutorials

Ready To Learn More?

Level-up your career with unlimited access to practical, in-depth technical courses taught by industry experts. Explore our courses