For the function blocks created by the user in the project or user library, a subprogram is created in the compiled program. Each time it is loaded, the input parameters of the classes VAR_INPUT and VAR_IN_OUT are transferred first. Then the corresponding subprogram is jumped into. Finally the output parameters of the classes VAR_OUTPUT and VAR_IN_OUT are read again. The number of subprograms or function blocks you may define depends on the type of controller.
Function blocks are equipped with a "memory", i.e. each entity of this function block is assigned a data area and a subprogram when loaded. All entities of a function block then use the same subprogram. Via the index register, the data area valid for the respective entity is accessed.
This implementation helps save a lot of useful space in the program memory, especially when the same user-defined function blocks are frequently used. However, accessing the data areas via index registers may prolong the scan time.
With some controllers, you can activate the option Indexed function block instances under .
With FB indexing, some basic functions do not work correctly when they are called up several times within a cycle. You will receive an error message with the following commands:
Counters: F118_UDC, F166_HighSpeedCounter_Set, F167_HighSpeedCounter_Reset, F168_PulseOutput_Home
Shift instructions: F119_LRSR