How To Create User Defined Types For Use In Ladder Logic


User Defined Types allow you to create your own structured tags. So what! I mean really, what’s the big deal?

For starters structures allow you to create a more organized program with descriptive tag names which are intelligently grouped. User Defined Types, when organized properly, take less processor memory.  Less memory means faster execution; this gets important when things like redundancy and scan time become critical. UDT’s allow code to be more portable, less prone to syntax errors, more readable as well as easier to modify.

Before creating a structured data type let’s define what a structure actually is. A User Defined Type or UDT is a structured type which is created by you. Pretty technical huh? The Structure is what needs to be broken down. A structure is simply a collection of tags organized into a group and addressed by element.

For example suppose you have a UDT or Structure named FAMILY. The FAMILY Structure has the following elements: Father, Mother, Sister, and Brother. All of the elements are type STRING, they hold the names of the family members. Rather than creating different tags for each family member you can create a UDT named FAMILY and then use instances of the FAMILY Structure for each family.

For example suppose there are two different families, the Jones and the Smiths. Each family consists of a Mother, a Father and siblings. The tags would look something like this if a Structure is not implemented:

                 TAG                                                       TAG                                       TYPE___

                Jones_Father                                    Smith_Father                   STRING
                Jones_Mother                                  Smith_Mother                  STRING
                Jones_Daughter                              Smith_Daughter             STRING
                Jones_Son                                          Smith_Son                         STRING

Here is what the tags look like when a User Defined Type, or structure is implemented:

                 TAG        ELEMENTS                         TAG     ELEMENTS            TYPE___

                 Jones                                                   Smith                                   FAMILY
                               .Father                                                 .Father                STRING
                               .Mother                                               .Mother               STRING
                               .Daughter                                           .Daughter          STRING
                               .Son                                                       .Son                      STRING

What’s the difference? One has underscores and the other has dots separating the two, big deal.

First of all, in order to create the tags in example one, Eight individual tags have to be created. Not only does this take more time it’s easy to make a mistake such as Simth_Father rather than Smith_Father. In the second example only two tags were created. If the tag name is incorrect such as Simth the entire family would be incorrect. Which mistake is easier to spot?

        Simth.Father                                                      Simth_Father
        Simth.Mother                                                    Smith_Mother
        Simth.Daughter                                                Smith_Daughter
        Simth.Son                                                            Smith_Son

The mistake on the right leaves the Smiths without a dad, while the one on the left is an entire family with a weird name, but at least it has a dad. One mistake is a typo while the other alienates the Father tag.

Let’s suppose there is more than one Daughter or Son. Rather than creating new tags for the individual siblings one could simply add elements to the structure, or even an array of elements. The point is you do not have to create more tags. Whatever is changed in the structure gets implemented to all instances of the UDT, in this case both families. This becomes a big deal the more the structure is used. What if you have a thousand families and need to add one element for each member, say age. Would you rather create thousands of tags or just a few elements to a Structure?

To create a User Defined Type follow these simple instructions:

From the Controller Organizer locate the “Data Types” folder. Next drill down to the “User-Defined folder” and Highlight the User-Defined name and right click it. Select “New Data Type… “from the pop-up window.

New Data Type

A new Data Type window will appear. Give the Data Type a name. As a general rule to be consistent, use all uppercase letters for the name.
UDT Element Window

If a description is added it will appear on all elements of the Data Type along with individual element descriptions. As with all descriptions they are not required but much appreciated. The description field describes the data type, not its individual members; there is a separate area to enter that data.

Each row defines individual members of the data type. Choose a Name, Data Type, Description, and depending on the software version you are using an External Access. The External Access is the permission level peripheral programs have to the data, such as HMI’s.

Lastly the members in the Structure need to be optimized to use the least amount of memory as possible. Sounds complicated right? Not really look at the Move Up and Move Down buttons. By highlighting one or more members or rows and pressing the Move Up or Move down buttons you can rearrange where the members are in relation to each other.

Follow this rule when creating UDT’s. Group like data types together.

BOOL’s are together, INT’s are together, DINTS are together, TIMER’s are together. For example if you are making a UDT with two Boolean members and one DINT one organization method takes more memory than the other:

ELEMENT             8 Bytes                 TYPE

Member_One                                          BOOL                       
Member_Two                                         BOOL                       
Member_Three                                      DINT        

ELEMENT             12 Bytes               TYPE

Member_One                                          BOOL
Member_Two                                        DINT
Member_Three                                     BOOL

 Below is an example of two Structures with the same elements however one uses 4 bytes while the other uses 8 bytes.

UDT With Elements 4 bytesUDT With Elements 8 bytes


After you have created a User Defined Type you can then create a new tag using your new data type and use it anywhere in your ladder logic program.