In this post, we will see how to create user-defined data types and function blocks in Studio 5000 software.
As we know, user-derived data types and function blocks play a very important role in PLC software. A programmer finds it easier to develop the logic faster and more efficiently if there is a repeated type of logic in the whole program.
That means, suppose there are 10 motors and each motor should start by pressing the start button and stop by pressing the stop button.
Instead of writing the same logic for all the 10 motors every time, he can just create his own library or data type which will contain a common logic; and it can be used in multiple instances within the whole logic.
User-defined types are available in almost every PLC software. In this post, we will see one such software of Rockwell Automation – Studio 5000. This software is used to program Rockwell PLCs like Compact Logix, Control Logix, and Flex Logix series. It is a very high-end one and has many advanced features available to make the task easier for the programmer.
User-Defined Data Types in Studio 5000
So, what is a data type? A Boolean, integer, real, etc.; the terms which a programmer has faced while creating a variable is called data type. It defines the type of data or variable used.
User-defined data type means a programmer can manually create his own data type and give it any name according to his convenience. Refer to the below steps to create a user-defined data type in Studio 5000.
As shown in the image, expand the assets category. Expand the data types category and in that, right-click the user-defined option as shown to create a new data type.
On clicking it, the following window will appear. Here, you have to click add a member as shown; to add variables of the data type you want; and give a name for the data type.
For example, as discussed earlier, two variables have been created – start and stop. Both these variables are of Boolean type.
Clicking Ok will create a data type of the name motor. Now, understand the logic. If you are creating a variable named M1 of type Boolean; you can create it as type motor also.
This means, if created, then the M1 variable will have two members accordingly – M1. Start and M1. Stop.
Add-On Instructions (User Defined Function Blocks)
A user-defined function block is a library created by the programmer himself. For example, as the timer is a predefined library that comes inbuilt with the PLC software, a user-defined library is the one that will be customized by the programmer according to his requirements accordingly.
Refer to the below steps to create a user-defined function block in Studio 5000.
As shown in the image, expand the assets category. Right-click the Add-on Instructions option as shown to create a new function block.
On clicking it, the following window will appear. Name the library according to you and define the programming language.
Here, I have named the function block as Motor_Logic and chosen the ladder diagram as the programming language.
On clicking Ok, the following window will appear.
Just click Ok.
Develop the logic according to you, as shown in the figure. When you create, you will be asked to create variables first; if undeclared.
As shown, I have not created variables initially; that is why it is showing as the red cross mark on the left side. This is because the rung has errors.
Here, create start and stop as input parameters; and create motor as output variable.
When you right-click any undeclared or undefined variable to create a new parameter, the following popup will appear.
Select the Input parameter for the input variable and the output parameter for the output variable. Choose the data type and click ok.
The variable will be created.
When the whole rung is now clear without any error, it will appear as follows:
Create the Program
Now that your data type and function block is created, you can use them in your main program. Refer to the below image.
In the add-on option, choose Motor_Logic library.
An undeclared library will be added. Type M1_Logic and create it with type – Motor_Library.
Right-click the newly created library and select open instruction definition.
The following window will appear. Tick Req (Required) option for the variables required to be pinned in the library outside, for linking external variables to it.
Click ok and you can now link external variables in your library pins; as shown in the figure.
Now, I have created two instances of the motor library and created two variables (M1 and M2) of data type – motor. And, it has been linked to start and stop pins of the library.
That means, whenever the variable – M1. Start turns on, the motor will turn on according to the logic written inside before; and stop when the variable – M1. Stop turns on.
The same logic will work for motor 2.
In this way, we saw how to create user-defined function blocks and libraries in this software.
If you liked this article, then please subscribe to our YouTube Channel for Electrical, Electronics, Instrumentation, PLC, and SCADA video tutorials.
You can also follow us on Facebook and Twitter to receive daily updates.
Read Next:
- UPS Working Principle
- Wiring in a PLC Control Panel
- Why 24 Volts DC Power Supply?
- Interposing Relay Panel Wiring
- Types of Cables in Industries