STEP7 multiple background data blocks(Including example program)

 How to understand the multiple background data blocks in STEP7? (Including example program) 

We know that when calling a function block (FB) in STEP7, it is necessary to specify a background data block (Instance DB) to store the input, output parameters, and static variables of the function block. In a large program, there are often many function blocks. Creating a separate background data block for each function block (FB) can be time-consuming and make the program structure confusing and less understandable. To simplify programming and improve program readability, Siemens STEP7 supports the use of multiple background data blocks (Multi-instance DB).

Multi-instance DB blocks are essentially background data blocks (Instance DB), with the key difference being that they can serve as the background data block for multiple function blocks (FB). For example, in organizing block OB1, if you call function block FB1 and allocate background data block DB1 for FB1, and within FB1, you call function block FB10, typically, you would need to create a new background data block for FB10. However, if instead of creating a new background data block, you assign the background data block of the parent function block (DB1 from FB1) to FB10, then DB1 becomes a multi-instance data block.

Siemens development environments STEP7 V5.5 and TIA Portal both support multiple background data blocks. Below, we'll take a look at how to use background data blocks in the TIA Portal (STEP 7 V13) development environment:

Continuing with the previous example, let's assume that FB10 has three input parameters: E_P1, E_P2, and E_P3, and one output parameter, A_R1 (both inputs and outputs are boolean variables).

We want to implement the following simple logic:

  1. When both E_P1 and E_P2 are 1, and E_P3 is 0, the output A_R1 should be 1.

  2. When E_P3 is 1, the output A_R1 should be 0.

The program for the FB10 function block is written as follows:


Then, when we call FB10 in FB1, as shown in the diagram: 



When we input the command "CALL FB10" without assigning a background DB, and press Enter, the system will automatically pop up the following dialog box:



This dialog box requests the allocation of a background data block for FB10. The default selection is "Single instance DB," and there is a default DB block name "FB10_DB" in the name column. If you click OK at this point, the system will automatically create a new background data block (FB10_DB).

However, since we want to use a multi-instance background data block, click the "Multi-instance DB" button, and the system dialog box will change to the following interface:


The dialog box contains a default interface name: FB10_Instance_DB, accompanied by an explanation expressing the following idea: The called function block (FB10 in this example) will save its data to the background data block (DB1) of the calling function block (FB1). This operation allows related data to be stored in a background data block to reduce the number of data blocks (DB) used in the program.

After clicking OK, enter the programming for FB1, input the corresponding parameters for FB1, and then save. As shown in the diagram:



Finally, it is necessary to compile the entire program block. After completion, you will see the input, output parameters, and static variables of FB10 in DB1, as shown in the diagram:


The above illustrates how to use multiple background data blocks in the TIA Portal environment. The process is somewhat similar in the STEP7 V5.5 environment, with slight differences. You can try it out yourself.