Back to tutorials
Intermediate

User Defined Data Type [UDT] Tutorial - Explanation, Usage, Examples & Custom Definition in RSLogix 5000

By
Vladimir Romanov
|
February 15, 2019
Table of Contents

Introduction

User Defined Data Types or UDTs are commonly used in Programmable Logic Controller Programming in order to group data and maximize code reusability. This structure allows the user to combine any of the existing data types into a package which can be reapplied multiple types across the program, be exported and imported into other structures.

In this post, we will be looking at why we’d want to use UDTs, how to set them up in RSLogix 5000 and a practical example of their usage.

When to use a User Defined Data Type (UDT)

User Defined Datatypes consume space on a controller. Therefore, you need to think strategically before combining your data in this manner. From a practical sense, this means that you don’t want to include too much data which will not be used in your program. It is also important to make sure that the application for which you’re using this data will actually need all those placeholders.

To illustrate the above principle with an example, let’s consider a simple pump system. This system consists of inputs, outputs & operational tags. Critical inputs could be “start”, “stop”, “fault reset”. Outputs we’d like to know about the system are “Status”, “Faulted”, “Running”, “Speed”, etc. Internal operation tags could be anything which will be used in programming the structure of the system. Using the bits we’ve covered above along with a few extra ones for programming the internal operation makes a lot of sense. We can define a UDT which will contain BOOLs, INTs, REALs as well as several arrays of undefined tags to accommodate the operational data.

An improper way to use a UDT would be to utilize it for a system which is extremely large such as an entire plant. Although you may get away with defining it as such, you will never be able to reapply such a UDT as opposed to our pump system above. It can be exported and imported into the next program which will use the UDT. It’s also not advised to apply a UDT for an entire machine even if it will be built multiple times. In fact, try to restrict UDT usage to small systems which exist in any field: motors, pumps, conveyors, tanks, boilers, etc.

Creating a UDT in RSLogix & Studio 5000

UDTs are defined within the “Data Types” folder of the Controller Organizer. This section is also used to identify the other data types typically used within Allen Bradley logic & controllers. Examples include Strings, Timers, EN2T structures & much more. As the name would suggest, User Defined Datatypes need to be created within the “User-Defined” folder.

To create a new User Defined Datatype, right click the folder and select “New Data Type…” (As shown in the image below).

User Defined Datatype UDT Tutorial - Explanation, Usage Examples & Custom Definition in RSLogix 5000

A new window will open and allow the user to define the specific tags used within the UDT. Here, you can customize your set of data and define the different data types as well as give them a description. The example below displays a simple implementation of a UDT used for a motor based system. It’s constructed from the inputs & outputs we discussed above as well as several utility arrays. Keep in mind that you may use any data types as well as arrays of them within the UDT. In fact, you can even “nest” a UDT within another. As you build one for yourself, you’ll realize how useful they are.

User Defined Datatype UDT Tutorial - Explanation, Usage Examples & Custom Definition in Studio 5000

Utilizing the UDT in RSLogix & Studio 5000

After completing the definition of the UDT and applying the structure, it will be saved within the program. From this point on, you may use it within your code. You may also choose to Export & Import it into another project. A common practice is to create new UDT structures within an offline file and to import them into a running program.

Just like you would define the type of a new tag to be a “BOOL”, you can choose for it to be the type of “UDT_xxx” where UDT_xxx is the name of the UDT you defined above. Do note that it’s my personal preference to add the “UDT_” prefix to each UDT; it’s not mandatory. By creating a tag which is specified as the UDT, the software will place the tag as well as the associated structure into the memory. This will allow you to create & identify tags based on this structure.

Using the same example from above, this translates to us being able to create a “Motor1” structure which will contain all the data types we’ve specified. In ladder logic, a basic example of this equates to a program which is entirely based around this structure. There are several advantages to this practice: we have a single structure for all the tags required to create a motor based system & we can easily reapply this system within the same or a different controller. From a re-usability standpoint, you should strive to contain your code within UDT in order to re-use it for other applications.

User Defined Datatype UDT Tutorial - Explanation, Examples & Custom Definition in RSLogix 5000

Conclusion

User Defined Datatypes are extremely powerful. They allow the user to create re-usable pieces of code which contain a logical implementation of a subsystem. By encapsulating your code within such structures, you’re allowing yourself to easily re-utilize the code & to be able to migrate it between multiple controllers.

The user may specify a combination of different data types to be contained within the custom structure. This includes simple ones such as BOOL, INT, Timer as well as more complex ones such as CONTROL structures and even other UDTs. Once defined, the user is able to create tags based on this structure within the same controller.

It’s possible to miss-use a UDT. You should avoid using them for large systems which aren’t going to be reapplied anywhere else. Furthermore, it’s best to define the systems as self-contained. In other words, you should only define the tags which are needed by the program. Defining tags which aren’t going to be used will waste memory on the controller.

Video Tutorial

Back to tutorials

Related Tutorials

Intermediate

PLC Programming Example Project - Batching Tank Ladder Logic PLC and HMI Tutorial

Generally speaking, there are two types of processes in manufacturing: discrete and analog. A discrete process is a manufacturing methodology that will produce separate widgets. In other words, a production line may output one item, two items, three items, etc. An analog production process is where the plant will create a quantity of product that is quantifiable by weight. Examples include the production of beverages, sauces, raw ingredients, etc. Although it is possible to design a flow that will continuously output the product, such production is often managed in batches. It is important to note that although batches are considered to be analog or continuous flow, most of them end up being packaged for consumption which converts them into a discrete manufacturing process.

September 14, 2020
|
By
Vladimir Romanov
PLC Programming Career

PLC Programming Certification - Complete Guide

You may choose to pursue a traditional college degree, learn through online tutorials, or take a course that will issue a plc programming certification upon completion. However, what is the best option, and what are the best PLC programming certifications?

August 6, 2020
|
By
Vladimir Romanov
Beginner

Opto 22 groov RIO Getting Started

The groov RIO module from Opto 22 has been released only a few months ago. The groov RIO is a feature packed piece of hardware that is easy to install, configure and deploy for many different field applications. The module comes pre-loaded with an array of software tools used across the industry and is ready to hit the floor running out of the box. Furthermore, the module is equipped with user configurable input and output nodes that have the capability unlike anything else on the market.

August 2, 2020
|
By
Vladimir Romanov