How to Program Functions and Function Blocks in Ladder Diagram
XG5000 divides function instructions into 2 types: Function and Function Block (FB). Function/FB instructions are available for use in Ladder or Structured text programming in the XG5000.
The XG5000 Software Help file features descriptions for Functions/Function block that are for use in all CPU types. Ensure the instruction is supported by the XMC Motion Controller by checking for XMC in the Availability section.
There is no memory allocated to a Function. No initial value or internal variables can be set and input and output data type are typically the same. Some functions allow the flexibility to choose different data types as shown in the list and 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.
Function Blocks can have multiple inputs/outputs with different data types. Different function block instructions are required for specific data types. For example:
TON is a On Delay Timer and there are 2 versions:
-
TON – simple on delay timer
-
TON_UINT – On delay timer with UNIT settings
Memory is allocated for each function block by a User assigned variable via a Global or Local variable. This variable has member variables to define the inputs/outputs (INST2 example below). This 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 FB will reside in….press F10 to open the Function/FB window.
-
For each function block you will need to allow vertical space for all inputs. XG5000 will display a message if the function block will not fit in the selected area.
Choose the instruction. If Function Block, define the Instance Name variable.
Item | Description |
---|---|
1 | If the Function/FB name is known, type it here. Then click Search. |
2 | Filter by Function or Function block, or choose both. |
3 |
Detailed description of Function/FB use shows up once the instruction is highlighted above. Note: The diagram shows the required data type for each input/output. This is key information for creating the tags in the next step. Hovering over the top of the FB also shows the information. |
4 |
For FB only, Instance Name can be defined here. Type in the name and press enter. If the variable is not defined, the window below will open.
|
5 | Click Help for Function/FB details. |
To display all the Function instructions, deselect the View all ANY Type Functions in the function list.
Input variables must be defined for each Function block. Outputs can be left blank or have a variable 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 the correct data type is pre-defined.
External Variables or Constant Values can be defined for any FB input/output as well. Variables are not required for outputs, but they can be entered if that is the preference.
Note: Double-click on cell next to the input/output to assign a constant or variable.
Data Type Reference
Note: The diagram shows the required data type for each input/output. This is key information for creating the tags in the next step. Hovering over the top of the FB also shows the information.
LM112-7