Ladder- Using Functions and Function Blocks
-
Functions vs Function blocks
-
Inserting Function/FB in a ladder program
Functions and Function Blocks
XG5000 divides function instructions into two types: Function and Function Block (FB). Function/FB instructions are available for use in Ladder or Structured text programming in the XEM CPU.
The XG5000 Software Help file features descriptions for Functions/FB for use in all CPU types. Ensure the instruction is supported by the XEM CPU by checking for XEM or XEC in the “Availability” section.
-
There is no memory allocated to a Function.
-
No initial value or internal variables can be set.
-
Input and output data type are typically the same.
-
Some functions allow flexibility to the choose different data types; this is defined by the following terms per the diagram below:
ANY, ANY_BIT, ANY_STRING, ANY_DATE, ANY_REAL, ANY_INT.
For example, the Limit function can handle the data type specified ANY. This references the data types shown below in red. The input & output data types must match.
Data Type specific Limit functions can be used as well. These are different instructions: Limit_Bool, Limit_Byte, etc.
-
Can have multiple inputs/outputs with different data types
-
Different Function block instructions are required for specific data types. For example, LIMR is the displacement instruction. There are 2 variations:
-
LIMR: for INT data type
-
LIMR_R: for REAL data type
-
-
Memory is allocated for each function block by a User assigned variable via a Global or Local tag. This tag has member variables to define the inputs/outputs (INST2 example below)
-
Allows for initial value and internal value registers.
The default ladder diagram interface is divided into a grid that is 10 sections across. Sections can be added by the user.
Function blocks cannot be inserted into the last 2 sections. Otherwise, they can be placed anywhere, and even stacked in the same rung.
Click in the section that the function block will reside in….press F10 to open the Function/FB window.
For each function block you will need to allow vertical space for 1 grid section for each input variable, plus one extra. For example, the LimitR function has 8 inputs, so it will require 9 vertical grid sections (L1-L9).
Choose the instruction. If Function Block, define the Instance Name variable.
If the tag is not defined in Instance Name above, the following window will appear:
Check View all ANY Type Function in the Function List to show all data type specific functions.
Note: The Edit Function Block Instance Name First option is not used by the XEM CPU.
Deselect the View all ANY Type Functions in the function list to show only functions with configurable data type.
.
Input tags must be defined for each Function block. Outputs can be left blank or have a tag defined per the programmer’s preference.
The Function Block variable member variables can be used to define the input/outputs of the blocks. The benefit of these variables is that the correct data type is predefined.
External Variables or Constant Values can be defined for any function block input/output as well. Variables are not required for outputs, but they can be entered if preferred.
Note: Double-click on cell next to the input/output to assign a constant or variable.
LP301