Jump to content
  • Sign in to follow this  

    Implement UDT in PLC Programming: User-Defined Data Type

       (0 reviews)

    xiangjinjiao

    In the previous article, we talked about what a UDT is, how to create User-Defined Data Types (UDT), and the advantages of using UDTs in your project. In this article, we will show one way to use UDT in your PLC programming.

    Contents:

    • Old tank simulator function block.
    • New tank simulation FB with UDT.
    • Calling the new tank simulation FB.
    • Adding a new tag to the UDT.
    • Conclusions.

    UDT in PLC Programming

    In our last few articles, we used the same tank simulator system to explain many concepts, like closed-loop control and PID controllers. In this article, we will use the same tank simulator to show how we can use the concept of UDTs in our programming.

    Old Tank Simulator Function Block

    In the old tank simulator system we defined some internal parameters for the sake of reusing the function block as many times as we wanted. See picture 1.

    113-1.gif

    picture 1. Tank simulator FB.

    As you see from the picture, in the function block interface we defined some inputs and some InOuts, these parameters should be provided when the FB is called.

    For example, if we called the FB to simulate tank 1 and called it again to represent tank 2, we need to provide the parameters for each tank to the related called function block. See picture 2.

    113-2.gif

    picture 2. Simulation of tank 1 and tank 2.

    You can see that for each FB call, we have to assign the related tags. For tank 1 simulation we should assign tags of tank 1 to the called FB. And the same for the tank 2 simulation.

    New tank simulation FB with UDT:

    Now, we want to use the UDT “Tank” that we defined in the last article to simulate our tanks. We will create a new simulation function block. See picture 3.

    113-3.gif

    picture 3. Add new tank simulation FB.

    The new simulation function block has the same logic as the old FB, but in this simulation function, we will use the defined UDT “Tank” as an InOut internal tag as you see from the picture.

    So instead of having your function block parameters declared in the different areas of the FB interface, now it will be just one tag that carries all needed information of the tank.

    Calling the new tank simulation FB:

    To call the new simulation function, we choose to call it inside a cyclic interrupt OB, to make sure the execution of the function block is not affected by the main logic OB1 cycle time as we explained with PIDs.

    So we need to first create a new cyclic interrupt OB. See picture 4.

    113-4.gif

    picture 4. Adding a cyclic interrupt to call tanks 3 and 4.

    You can choose the cyclic time as you see fit, in our case we set it to 3000 microseconds or 3 milliseconds.

    Now, you can drag and drop your “Tank Simulator with UDT” FB into your cyclic interrupt to call the FB. A call option window will appear, giving the FB data instance whatever name you like. See picture 5.

    113-5.gif

    Picture 5. Call your FB.

    After calling the FB, you know need to assign the parameters related to the tank you want to simulate. See picture 6.

    113-6.gif

    picture 6. Assign tank parameters to the FB call.

    Notice that you have only one parameter to fill for the function block. And it is the UDT tag that you have created. Which already contain all tank parameters that the function block needs.

    We want to simulate Tank_03 so we will assign the tag to the FB call. See picture 7.

    113-7.gif

    picture 7. Drag and drop your tag.

    The function block call for tank 3 looks simpler than the call of tank 1 with the old simulator FB without UDTs. See picture 8.

    113-8.gif

    picture 8. Tank 1 and tank 3 calling differences.

    Can you see the difference between the two tanks calls? You have to provide all the parameters of the function block in the case of without UDTs. imagine if you have to simulate 50 tanks with this simulator. It will be very boring and time-consuming to assign all these parameters, not to mention, to declare them first for each tank.

    But in the case of the simulator with UDTs, you can call as many as you want and it won’t take much time or effort. See picture 9.

    113-9.gif

    picture 9. Calling many other tanks.

    Now, imagine that you have to add a new variable to your simulation. For example, you want to add an Outflow Warning signal. With the old simulator function block without UDT, This will mean that you have to declare this new tag for each tank and you have to add it one by one to each time you call a tank.

    But with UDTs, you only need to update the UDT you created and add the new tag you want. See picture 10.

    113-10.gif

    picture 10. Adding a new tag to the UDT.

    When you make any changes to the UDT, you won’t even need to update the function call. Because the call parameter is the same, the changes were made inside the parameter itself. See picture 11.

    113-11.gif

    picture 11. No need to recall the FB.

    However, you still need to recompile your PLC project or at least the data block so the changes to the UDT can be updated. See picture 12.

    113-12.gif

    picture 12. Recompile to update the changes to the UDT.

    After you compile all the changes to the UDT will be automatically updated to all declared tags of this UDT. See picture 13.

    113-13.gif

    picture 13. All tags are now updated.

    Conclusion

    • You can use the UDTs in your project to make your programming faster and easier to follow.
    • Using UDTs will also make it easier to make changes to your functions and function blocks.
    Sign in to follow this  


    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

Apply for friendship links:WhatsApp or E-mail: admin@plchmis.com
×
×
  • Create New...