If you have ever constructed a program using ladder logic (and if you haven’t then check out this link explaining why you should), you will have seen the plethora of function blocks that typically come with the software. Rockwell Automation’s Connected Components Workbench (CCW) is a great example of this as the out-of-the-box program contains mathematical, timing, comparative, triggering, logical, conversion, and a few other categories each with multiple function blocks. With this range of tools at our disposal, what more could we possibly need? Simply put – personalized convenience.
Imagine a program in which you need to calculate the difference of two variables. On a single rung, you only need to use the subtraction function block with an input of those two variables, which then move the difference into a third variable. There’s no need for a function block in this case as the function is simple and easy to follow. Now instead of a program that calculates the difference of two variables, imagine creating a program that calculates the quadratic formula of variables A, B, and C where each variable has multiple values depending on the input. To do this, you would end up creating much more than the variables A, B, and C, and soon for even just a single instance of the quadratic formula you may have multiple rungs with many function blocks filling it. This makes error much more likely as the difficulty to read and understand how each variable flows into the next grows more complicated at an exponential rate.
This is where the benefits of the User Defined Function Block (UDFB) really shine. Instead of immensely increasing the length of the program (and variable count) for each instance of the quadratic formula, the UDFB allows you to create a single instance of the function and instantiate it into a single function block. Now, you can simplify your program by having each variation of an input on it’s own rung with the instantiated quadradic formula. Your program is now as neat and easy to follow as the simple subtraction function mentioned earlier. Adding another benefit to list, you can also save your UDFB for other programs as well as add it to a library to be used whenever you need.
Ultimately, creating a UDFB is not much different than creating a program itself. If the program is something you will create for a very specific purpose and may never be used again, then turning it into a UDFB will most likely not bring any benefit. If you find yourself using a combination of pre-existing functions at multiple points in a program, for multiple different programs, or even just want to present a high-level operation for any technicians that may be looking at your program, then creating and reusing the User Defined Function Block will not only save you time in creation but in reading and changing programs as well.