30.8.2 Function Block Variables

In the Function Block screen editor, use function block (FB) exclusive variables and system variables to create programs.

There are 3 types of FB-specific variables: one type of variables can be used within FBs only, and other 2 types of variables function as operands for Function Block Instructions, passing and receiving FB data to/from logic programs. You create variables in the Function Block screen's variable list, and they can be used within the FB where they were created.

Local Variables

Local variables are variables used within FBs only. You cannot write to local variables directly from Logic Screens where FBs are inserted.

You can register up to 512 local variables per FB.

Input Variables/Output Variables

You can use input variables and output variables to pass and receive data between FBs and logic programs. When you insert a FB in the Logic Screen, input variables created in the FB display as S operands, and output variables display as D operands.

You can register up to 63 input variables and 63 output variables per FB.

For operands, specify addresses or variables that match the variable type of input variables or output variables. The values stored in the addresses or variables of S operands are passed to input variables, and used in FBs. Also, the values of output variables in FBs are stored in addresses or variables set for D operands.

Notes

When creating or using FBs, please consider the following behaviors for creating logic programs.

When the display unit is switched ON, FBs are not reset even when the conducting state is finished, and variables in FBs retain the last values. Please reset FBs as necessary.

You can position the same FB multiple times. All of them use the same memory space. Therefore, when multiple identical FBs operate, they write to and read from the same variable, resulting in unexpected results. When using identical FBs multiple times, make sure they do not conduct at the same time, or they finish operations with one conduction.

For example, you have a Function Block (FB_0000) which counts up by 1 every time instruction is conducted, and the FB_0000 is placed twice in the Logic Screen. For the first scan, the "Count" (local variable) for both instances of FB_0000 is reset before starting to count, both S1 and S2 operands are turned ON. For subsequent scans, only addition is performed, and only the S2 operand is turned ON.

For D100 and D200, the output results are not increments of 1, but increments of 2, as 1 is added in D100 and D200 alternatively.

This happens because both instances of FB_0000 are using the same variable in the memory space. The first and the second instances of FB_0000 are adding 1 to the same variable "Count" alternatively, resulting in values with an increment of 2 in D100 and D200.

In order to have the outputs with increment of 1 for both, D100 and D200, input the value before addition as an S operand, then add 1 to the value.

Example:

  1. Add an integer-type input variable "Input" to FB_0000.

  2. Insert the MOV instruction before the ADD instruction. Initialize "Count" when "Clear" is ON. When "Clear" is OFF, enter the value of "Input" to "Count".

  3. For the FB_0000 instruction's S3 operand, specify the same address as the D1 operand.