Understanding Function Block Instances (Single, Multi and Parameter) in Siemens TIA Portal
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.
In order to follow along with this tutorial, you will need:
- A basic understanding of function, function block and data block. A good place to start will be to take the tutorial The Complete Practical Guide to Siemens Tia Portal Programming
- TIA Portal – TIA Portal V16 is being used in this tutorial
- An installation of PLCSIM
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.
There are three different options for storing instances, they are as follows
- Single Instance
- Parameter 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
Create a function block with the following parameters
Write the following ladder logic operation to perform a simple calculation as shown in the image below
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.
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.
We pass our parameter tags through the FB. Compile and download.
The data block for this function block instance holds the data as shown below
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.
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.
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
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
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.
Tag the function with the data block created in OB1.
A separate data block instance will be needed any other time this block is called. This is illustrated in the image below.
Advantages of Parameter Instance
- Which instance is currently being utilized can be specified at runtime.
- In program loops, various instances can be processed iteratively.
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.
Here, the use case instance data is stored in the static parameter of the calling function block.
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’.
We can see that the data is being stored in the data block of the calling function block as shown in the image below
Calling the “Use Case” function block again shows the following
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.
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.
The final addressing is displayed below
Update the block call in OB1. The data is also stored in the ‘’This Case’’ data block.
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.
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.
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.