Instances of function blocks can be assigned to holding areas, i.e. all conditions for the function block’s variables remain intact after a power failure. In this case, the variables have to be entered under the class VAR_RETAIN or VAR_EXTERNAL_RETAIN in the POU header. For VAR_EXTERNAL_RETAIN, the FB instance must have been declared in the global variable list as VAR_GLOBAL_RETAIN.
If the class VAR_RETAIN or VAR_EXTERNAL_RETAIN is used for the instance, the compiler assigns addresses from the holding area to the non-holding variables of the classes VAR, VAR_INPUT, VAR_OUTPUT or VAR_IN_OUT, which are only initialized after downloading the program. Sub-instances of the class VAR are treated like sub-instances of the class VAR_RETAIN. The adresses for other variables or sub-instances of the classes VAR_RETAIN, VAR_OUTPUT_RETAIN, VAR_EXTERNAL, or VAR_EXTERNAL_RETAIN are assigned as for instances of the class VAR or VAR_EXTERNAL. The values of the variables of the classes VAR_CONSTANT and VAR_EXTERNAL_CONSTANT are entered as constant values in the program code.
If the class VAR or VAR_EXTERNAL is used for an instance, the declaration of the variables or sub-instances in the function block determines whether they are holding (VAR_RETAIN) or not (VAR).
POU header for the program Prog
A program Prog accesses the function block FB1 twice:
POU header of the function block FB1
The POU header of the function block FB1 has the following entries. Function block FB1 also draws upon two instances of function block FB2.
POU header of the function block FB2
The POU header of the function block FB2 has the following entries.
Memory distribution for the program Prog: