Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

How do I convert an INT variable to a TIME variable?

davidspall
2011-03-28
2011-03-30
  • davidspall - 2011-03-28

    Is there a CoDeSys function to convert an integer value to a time value? i.e. I need to set a timer interval in seconds to a specific integer value received over CAN

     
  • JAPIB

    JAPIB - 2011-03-28

    Hello
    There are a lot of conversion operators if you press F2.

    Just a small example, in ST :

    VAR
    Val:INT;
    Mytime:TIME;
    END_VAR


    Program :
    MyTime:=INT_TO_TIME(Val);


    After running the program :
    For Val=100 ==> MyTime=T#100ms
    For Val=1000 ==>MyTime=T#1s 0ms

    Hoping to be helpful

     
  • shooter - 2011-03-29

    or have a look at w www.oscat.de w

    and yes i know if you do INT_TO_TIME is good.
    keep in mind the max.
    if needed more use a INT_TO_REAL then multiply it and make a convert to time by REAL_TO_TIME
    dependiong of version the rounding is false. but it works

     
  • davidspall - 2011-03-30

    Thanks Guys.
    I did find a way of making the conversion via pointers just after I posted. However the INT_TO.. conversion is much neater.

     
  • Rolf-Geisler - 2011-03-30

    One more hint: DINT_TO_TIME converts a double integer into the time format.
    As in INT_TO_TIME, "100" will be converted into 100 ms. However, the DINT range is much wider. 2,147,483,647 milliseconds are equal to 596 and a half hours. Is that enough?

     

Log in to post a comment.