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

WORD to TIME (DWORD)

Rob
2019-10-02
2019-10-03
  • Rob - 2019-10-02

    Hi there,
    I'm struggling with a beginner-issue here...
    I'm creating an FB to log running times of actuator devices.
    My approach is to place instances of these FB's (PulseToTime FB) in a task to be executed on a time basis of one minute. Every input signal's pulse goes to one CTU for totalizing minutes. A second CTU totalize hours.
    The output for this "PulseToTime" FB should return a TIME type variable for the totalized device's running time.
    I'd like to add the .CV values (WORD types) from both CTUs (the CTU for minutes and the CTU for hours) and then convert the result to a TIME type variable showing only hours and minutes, for example, T#1h20m...
    How can I perform this add and convert operation?

     
  • Anonymous - 2019-10-02

    Originally created by: ph0010421

    The TIME datatype is actually in ms, so if you multiply the minutes CV by 60000, and the hours CV by 360000 and add them together, you'll have the total ms.
    You'll end up with some big numbers, so change from a WORD to a UDINT.

    Add these values together, then use UDINT_TO_TIME function.

     
  • Rob - 2019-10-02

    ph0010421 hat geschrieben:
    The TIME datatype is actually in ms, so if you multiply the minutes CV by 60000, and the hours CV by 360000 and add them together, you'll have the total ms.
    You'll end up with some big numbers, so change from a WORD to a UDINT.
    Add these values together, then use UDINT_TO_TIME function.

    Thanks for the hint ph0010421!
    Tomorrow I will test something like this...

    pFB_CurrentRunTime:= UDINT_TO_TIME ((100060WORD_TO_UDINT(FB_Minute_Pulses.CV))) + ((10006060*WORD_TO_UDINT(FB_Hour_Pulses.CV)));

     
  • Anonymous - 2019-10-03

    Originally created by: ph0010421

    Yup

     

Log in to post a comment.