Creating Function Blocks and UDT's - Part 2: User Defined Tags (UDT's)

Creating Function Blocks and UDT's - Part 2: User Defined Tags (UDT's)

INTRO

Welcome back to this two-part series on Function Blocks and UDT's. I hope that you gained some useful knowledge when it comes to Function Blocks. If you missed my previous article on Function Blocks and would like to understand them in more depth then I encourage you to look for Part 1 where I went into detail on what a Function Block is, why would we use a Function Block, and how to create a Function Block. For this article, lets jump into User Defined Tags, otherwise known as UDT's.

User Defined Tags (UDT's)

The UDT. Have you heard of this term before? Have you seen UDT's in action or perhaps created one yourself? If so, then you understand how efficient they are when developing programs! For those who are not familiar with a UDT well not to fear. By the time your finished reading this article you will be on your way to creating your own UTD's, and just like I mentioned in Part 1, my examples will be shown using the OMRON Sysmac Studio development software. You may be using another platform such as Rockwell but that's OK, the theory is the same no matter the flavor of software. Another note to make is in OMRON a UDT is referred to as a STRUCTURE. So, depending on what platform you are using you will hear it as a UDT, or for OMRON a STRUCTURE. For this article I will refer to it as a UDT.

So again, let's ask ourselves, what is a UDT? Well quite simply a UDT is a user created data type. That data type will then have "members", or sometimes referred to as "children" within itself. For example, if we stay with the theme of using VFD's as an example as we used in Part 1 (Function Blocks), then we could create a UDT called "VFD_UDT". In the image below you can see that I have created a UDT (or STRUCTURE in OMRON). That UDT has MEMBERS, or children if you prefer, that would be common to a VFD application.

No alt text provided for this image

Ok James that's great but how and why would I create one??? Glad you asked because next I am going to cover just that. First let's look at how we create a UDT.

Creating a UDT is very simple however one of the first things we must ask ourselves is do I need to create a UDT, and what members do I need within the UDT? Let's answer the first question of do I need to create a UDT.

UDT's are created and used when you are going to have multiple pieces of equipment such as multiple pumps, valves, or even conveyors. If you look at our variable example from Part 1 we had 3 VFD's all with common attributes. As you can see this resulted in a lot of variables that yet again would add to the time required to develop your program. So, if you find yourself in this situation then the answer to "Do I need to create a UDT"? is a big YES!!

No alt text provided for this image

Let me show you how to turn our exhaustive Global Variable list into a small list of only 3 variables!

Before you create a UDT you must first determine what common attributes will you have for your equipment. For example, will all pumps have the ability to monitor over temperature conditions? Will all valves have the ability to send an analog signal back to the PLC or is it just a digital signal for Opened or Closed? If you're not sure of all your attributes that you will need yet well that's OK!! With UDT's, you can add or remove members at any time you wish. In fact, you can have more members than you need. Just because your valve does not have analog feedback, does not mean you have to remove it from your UDT. It can reside in the UDT for future valves that do have an analog feedback feature!!

So now that we have answered whether we need a UDT or not, and have determined what members we will need, in our case we will use the members in our existing variable table. Let's discuss how to create one.

Creating a User Defined Tags (UDT's)

The first step in creating a UDT is to expand the Data folder which is located in the Multiview Explorer of Sysmac Studio and then double click on "Data Types".

No alt text provided for this image

Once you have doubled clicked on Data Types you will see a screen that looks like the one in the image below. This is where we will name our data type as well as add members to the data type.

No alt text provided for this image

To add a new data type in OMRON simply click the greyed-out text that says "Empty. Click here to add item."

No alt text provided for this image

Once you click on this area you will then need to enter a name that you would like to call you UDT. For our example I will simply name it VFD_DT. As a note, if your project already has UDT's (structures) then you will not see the greyed-out text. TO add a new UDT to your project you simply would just Right Click in the same area and select Create New Data Type.

No alt text provided for this image

Once you have created a new data type, you now will need to add members. This is where you will add members such as Start, Stop, Frequency Set Point, and Fault to name a few.

For my example I am going to add the following members. Make note of the Base Type when adding your members.

  • Start : Bool
  • Stop : Bool
  • Frequency_SP : INT
  • Alarm_Reset : Bool
  • Run_FB : Bool
  • Run_Output : Bool
  • Alarm_Output : Bool
  • Runtime : Time
  • Frequency_Actual : INT

It is also good practice to add comments to each of your member no matter how obvious they are. Once you have all your members created you should have something that is like my example as seen in the image below.

No alt text provided for this image

Congratulations!!!! You have created a UDT. Now let's finish up by demonstrating how this UDT can be used to replace our huge global variable list.

Using Our User Defined Tags (UDT's) in the Global Variable List

If you refer back to the beginning you could see that we had 3 VFD's, each with their own attributes. This list was HUGE! Now that we have created a UDT, we can easily reduce this list down to just 3 variables all while still being able to keep the attributes for each VFD!! Let me show you how.

The first step is to create your 3 VFD's with a unique tag. Be sure to create these in the Global Variables Section in Sysmac Studio. For my example I will create the following:

  • VFD1
  • VFD2
  • VFD3

Be sure to change the Data Type for each VFD to whatever you called your UDT. In my example I called my UDT "VFD_DT". Once you have done this you should have something like my example below.

No alt text provided for this image

Now unfortunately OMRON does not have the option to expand your new tag when it is set as a UDT data type. If you want to see the members of your new global variable within the global variables section of SYSMAC Studio you can simply click in the Comments section and expand the comments as seen below.

No alt text provided for this image

When you're in the programming environment you can now access your members of the UDT very easily. As an example, when I add a Normally Open contact to a rung and add the tag VFD1, we will be able to access the members once we add a period after the tag VFD1. In my image below you can see all the members associated with VFD1. The same would apply to VFD2 and VFD3.

No alt text provided for this image

Once you select the member you want to assign you will end up with the following.

No alt text provided for this image

That's it to making UDT's in SYSMAC STUDIO!!! You now can see how creating a UDT and assigning a Global Variable to that UDT greatly reduces your Global Variable list and programming time.

I hope you enjoyed this 2-part series and is so please comment and share with others. Be sure to look for a video version of this article on my YouTube channel called Scorpion Controls. Also be sure to look out for my next article where I will show you how to use these UDT's in a program and with a Function Block

James Ashton M.E., C.Tech

?2021

Freek-Jan Vernhout

Student HBO Industri?le Automatisering 4de jaar

2 年

Dear James, Great tutorial! Realy clear and very easy to follow. I however have have a issue with connecting the UDT to a Functionblock. I have a variable defined in the functionblock that is being used as: IN/OUT. And the data type is the UDT. But I get the error: "Failed to write. Check if the variable or memory area is allowed to write." My question is: Is it possible to use a UDT as IN/OUT in a functioblock or is it simply not possible? Kind regards, Freek-Jan Vernhout

回复

要查看或添加评论,请登录

James A.的更多文章

社区洞察

其他会员也浏览了