Creating a User Function Block

Step Action
1 Create or Open your project.
2

In the Project window panel locate the User Function/Function Block section.

3 Right-click on the User Function/Function Block section. Select Add Itemè Function Block…

4

Enter in information for your function block in the window that pops up.

Give your function block a descriptive name.

Choose the language of the function block’s code.

Choices:

  1. LD – Ladder Diagram

  2. SFC – Sequential Function Chart

  3. ST – Structured Text

  4. IL(IEC) – Instruction List

Select or de-select the Use EN/ENO option.

Choose a value for Width (Columns).

Add a Program Description to let other users know what the function block does.

5

Select Password tab to add security options to your Function Block. Using the password functions is optional.

Use New Password section to password protect your function block. This step is optional.

Enable or disable Protect Program check box. This step is optional.

6

Open the Local Variables file for your function block.

7

Add Local Variables to your function block.

Choose Variable Kind for your local variable.

Variable Kind Definitions:

  • VAR: This is a local variable for the function block. Can not be accessed outside of it.

  • VAR_CONSTANT: This is a local constant variable for the function block. Can not be accessed outside of it.

  • VAR_INPUT: This is a read only input variable to your function block.

  • VAR_OUTPUT: This is an output variable from your function block. It is read only to outside programs.

  • VAR_IN_OUT: This in an input variable that has read and write access from your function block.

  • VAR_EXTERNAL: This allows you to give access to an external variable from the function block. These can be global variables but outside Function declarations can not be used.

  • VAR_EXTERNAL_CONSTANT: This allows you to give access to an external constant variable from the function block.

Enter a name for your variable in the Variablecolumn.

Choose the data type of your variable in the Type column.

Available data types:

If using a BOOL variable of VAR_INPUT kind, select if an edge trigger is needed

Trigger Options:

  • R_EDGE: This is a rising edge one shot trigger.

  • F_EDGE: This is a falling edge one shot trigger.

.Pay attention to the address column for memory address usage.

Note: Grouping BOOL variables together can save on memory address usage.

If using a VAR or VAR_CONSTANT type variable, you can setup an initial value for the variable. This will set it to that value on first function block call.

Note: When using a variable of VAR_CONSTANT type, the Initial Value is the constant value of the variable. It needs to be set to the appropriate value.

Retain check box will be grayed out for Function Blocks. Used check box is checked if variable is used in the code.

Add a Comment to the variable to let other users know what the variable is used for.

8

Open Function Block Program to add code.

The chosen language editor will appear. This example is Structured Text.

9

After adding Function block code, press Check Program to check your function block for errors.

10

Fix any errors that appear or proceed to Using a User Function Block to start using your function block.

 

 

 

 

 

 

 

LP306A