Chapter 2. Program Organization12 PACSystems* RX7i, RX3i and RSTi-EP CPU Programmer's Reference Manual GFK-2950CCreating UDFB InstancesYou create an instance of a UDFB by calling it in your logic and assigning an instance name in thefunction properties.Figure 4: Creating a User-Defined Function BlockIn the following LD example, the first rung creates two instances of the UDFB, Motors. The instancevariables associated with the instances are motors.motor1 and motors.motor2. The second runguses the two instances of the internal variable temp in logic.Figure 5: Use of User-Defined Function Block in Ladder LogicInstance Data StructuresA variable with the format function_block_name.instance_name isautomatically created for each instance of a UDFB. The instance datamakes up a single composite variable that is of a structure type. Theexample to the right shows the variable structures associated with twoinstances of the UDFB named Motors. Each instance variable haselements corresponding to parameters In1, Out1, and Y0, and internalvariables modelno, speed, and temp.Instances are created as symbolic variables, never as mapped variables.This ensures that instance data is only referenced by the instance nameand not by a memory address, which means that no aliases can becreated for the UDFB data elements. The indirect reference operatorcannot be used on an instance variable because indirect references arenot permitted on symbolic variables.Figure 6: Display ofInstance DataStructuresUDFBs and ScopeUnlike a parameterized subroutine, a UDFB has its own %L memory.By default, internal variables of a UDFB have local scope, making them visible only to the logic insidethe UDFB. They cannot be read or written by any external logic or by the hardware configuration. Aninternal variable can be made visible outside the UDFB by changing its scope to global. Logic outsidethe UDFB can read but cannot write to internal variables whose scope is global.Note: If you give internal variables global scope, your application will not conform to IECrequirements.