Creating user-defined function blocks

One of the most useful features of PLC programming is the ability to create user defined function blocks, which allow the user to break down code into meaningful chunks, making the program simpler and easier to follow. This Tech Tip will show you how to create user-defined function blocks in Panasonic’s PLC programming software FPWIN Pro.

STEP ONE > Create a new function block

In the project window, right-click POUs and click New POU. Select “Function Block (FB)”, choose the desired language and give the block a meaningful name.

Note that you can choose to have the block with or without an enable.

STEP TWO > Create the code for the function block

This example shows a function block that converts temperatures in ℃ to ℉.

Be sure to change the class of any variables that are going to be inputs or outputs to either VAR_INPUT or VAR_OUTPUT. This will make them appear as legs on the actual function block in the main program.

STEP THREE > Insert the function block into the main program

In the main program, open the instructions pane on the right side of the screen. If it is not there, go to Window > Panes > Instructions to open it. Enter the name of the function block, in this case “C_to_F” into the search bar and click drag it into a rung.

Note that a variable with type “C_to_F” has been created. You can create as many instances as you like as long as they have unique identifiers.

STEP FOUR > Create variables for inputs and outputs

The last step is to populate the input and output variables. Simply click the question marks and enter some names. Compile the program, enter online mode and click run.

Click the Input variable, enter a value and the output variable will automatically update.

And we are done!
Now that you have this function block, you can easily drop it in as many times as you like, which saves having to write it over and over. Hopefully this saves you some time down the track.