In this article, we will talk about the UDT or user-defined data types and how to use them for better and faster PLC project structure.
Contents:
TIA Portal platform and any other PLC programming software offers a wide range of different data types that you can use in your project, like, Booleans, Integers, Real, and some complicated types like Arrays and TimeOfDay. This helps you better structure your project and better utilize your PLC memory and processing areas.
A UDT is a complex user-defined data type, meaning you as a programmer have to define a UDT first and then use it in your PLC project. The UDT represents a structure made of several components of the same or different data types. You can change a PLC data type (UDT) centrally and use it repeatedly in the program code. All locations of use are updated automatically.
You don’t have to use UDTs in your project, however, it will give you many benefits when applying it in your project.
Following are some examples:
Picture 1. Defining tank2 tags.
Imagine if we had 10 or 50 tanks in our project, we would have to define the same tags for all the tanks which would be very difficult and time-consuming and it could lead to programming errors if there was any mix between tags of different tanks.
Using UDTs will ensure easier tags construction and faster programming as we will see following.
To create a new data type you just need to click the “PLC data types” and double-click on “Add new data type”. See picture 2.
picture 2. Create a new data type.
Once you click the “Add new data type” a new UDT will be created and the data view of your UDT will open.
Remember to give your UDT a proper name that will represent its purpose, in our case the Tank system. See picture 3.
picture 3. Rename your UDT.
Applying the concept to the previous tank simulation example:
Next, you start to add the tags you want to your UDT, in our case we will add all the related tank tags from our previous simulation project into the Tank UDT. See picture 4.
Picture 4. Add your tags to the UDT.
As you can see, we just copied the tags we used for our tank simulation project into our Tank UDT. And now we have a new data type that contains all related information of a tank system.
Now whenever we have a new tank in our PLC project we can just create a tag for that tank and give it the data type “Tank” and it will automatically have all the information needed for a tank system. See picture 5.
picture 5. Adding a new tank to our project.
You can see from the previous picture, that whenever you declare a new tag you can find and choose the data type “Tank“ for that tag. This time we declared a tag Tank_03 of data type “Tank”.
Once you declare Tank_03 you can see a small black arrow next to it, indicating that this tag has some information stored in, Once you click this arrow you will see all the tags defined inside the UDT “Tank”. See picture 6.
picture 6. Declare Tank 3 of data type Tank.
As you can see, Tank_03 has all the needed tags for a tank system.
Now, we will imagine that our process has 12 different tanks, we will just as easily create the tags for the rest of the tanks. See picture 7.
Picture 7. Imagine that we have 12 tanks.
As you can see, we created tags for 12 tanks and each one of them is of data type “Tank”.
Now, go back and imagine that you don’t have a UDT for the tank system, if you try to create the tags for 12 different tanks, you will need to re-declare all related tags for each tank individually 12 times. See picture 8.
picture 8. Creating all tags one by one.
All the tags you see in the previous picture are only for 3 tanks; imagine creating the same for another 9 tanks. Surely that will be very annoying.
Now, imagine that you need to add another tag, for example, you need to have a tag that will tell the alarm status of a tank. You will have to add this new tag for each tank. See picture 9.
picture 9. Adding new tag
As you can see, any time you need to add a new tag, you will have to declare it for each tank individually.
With UDTs, when you need to add a new tag, all you will do is go to your UDT data block and declare the new tag inside it. See picture 10.
picture 10. Adding new tags in UDTs.
Once you make any change in the UDT declared tags. The changes will be automatically updated everywhere using the same data type. However, you will need to recompile your UDT tags after each change. See picture 11.
picture 11. Compile to update changes.
As you can see, all tags defined as a Tank data type are now colored red to indicate that there were some changes done to the original UDT.
Once you compile your project or at least your Data block, the changes in the UDT will be automatically updated in all related tags. See picture 12.
Picture 12. Changes are updated automatically.
You can see that the new Alarm_status tag is now added to all tanks.
Download: User-Defined Data Type
If you liked this article, then please subscribe to our YouTube Channel for Instrumentation, Electrical, PLC, and SCADA video tutorials.
You can also follow us on Facebook and Twitter to receive daily updates.
Read Next:
In the PLC emergency stop example program, when the emergency button is pressed, the elevator…
This article is about controlling the double-acting pneumatic cylinder movement control with a timer circuit.
In this article, we will review the main responsibility scopes of the instrumentation and electrical…
Learn the daily alarm PLC program using real-time clock instruction as per the required timings…
A Real-Time Clock accurately tracks time from seconds to years and stores the data in…
Omron PLC logic for sorting the number of products and counting the number of products…
View Comments
It was extremally useful, thanks!