In this post, we will understand the use of user defined function blocks in a PLC (programmable logic controller).
Function blocks are objects which are defined in a PLC program to simplify the process of programming. Basically, it is a means of reducing the programming length and complexity written by the programmer.
Table of contents
Consider a simple example of a timer. A timer is a logic which sets it’s output after a certain time.
Now, if a PLC programmer was required to write timer logic by himself, it would be a long and cumbersome process for him.
And, if there were many such timers required to be used in the logic, then you could imagine the length of the program code.
It would become difficult for him to troubleshoot if any issue occurs; and even difficult if some other programmer tries to study it.
This is made easier by a function block. A function block comprises of a logic written inside in it; with inputs and outputs linked to it.
So, you can use multiple instances of this function block by simply linking its inputs and outputs with different variables.
Refer to the below image. It shows two instances or uses of the timer in the program.
The first one is named alarm_t1 and the second one is named alarm_t2.
The first-timer is turned on by a different condition and the second timer is turned on by a different condition.
This shows that you can use multiple timers in the program with different trigger conditions and different set intervals.
You just have to name the timers properly; such that anyone should not clash with others.
So, consider this same thing without a function block. If it was not used, then you would have to write the logic of the timer manually; which would indirectly increase the complexities.
Function blocks make the job much easier, as you do not have to write the logic every time if it is the same.
You just have to link the inputs and outputs as discussed before.
They are categorized into two types.
- system and
System Function Blocks
System blocks are that function blocks that are developed by the manufacturer and preloaded in the software.
A simple example can be a timer, which we discussed before.
User-defined Function Blocks
Now, let us look ahead to our main topic. Suppose if you are writing logic to start five motors after a set interval of time. All of them are required to turn off after a set interval of time.
Now, you can use a timer here. But what about the remaining logic? If you see, it is the same; with only the number of motors varying.
Now it is five motors; tomorrow a need can be raised for six. You cannot afford to write the whole logic manually every time, as it will waste time and also resources in the PLC software.
So, PLCs have a provision for user-defined function blocks. It gives programmer the facility to create a function block by himself, and assign the inputs and outputs accordingly.
This is extremely useful in conditions where the logic repeats several times and only the inputs and outputs change.
PLC Function Block Programming Example
Refer to the below image.
Hourmeter is a function block defined by a user which has a logic written inside by him, for counting the running hours of a pump. ROFP_P_101A_HRS is the first block and ROFP_P_101B_HRS is the second function block.
The function block has its user-defined inputs and outputs; where you just have to link the conditions according to your requirements. This makes the work very easy and time-saving; as you will not have to write the logic of running hours individually for every pump.
One more advantage is that you can use any data type inside the function block. As you can use its multiple instances, it reduces the load of the programmer and saves time indirectly.
If you liked this article, then please subscribe to our YouTube Channel for Instrumentation, Electrical, PLC, and SCADA video tutorials.