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

Convert TIME to REAL

frankiPL
2017-02-04
2017-02-13
  • frankiPL - 2017-02-04

    Hi,

    I need to calculate step value for some time period like this:
    bStep=(targetLevel-currentLevel)/(timePeriod/t#10ms)

    targetLevel,currLevel,bStep - REAL
    timePeriod - TIME

    my TON1 has PT:=t#10ms and when TON1.Q I need to add bStep to bValue

    Now I have Type mismatch in division so I think I need to convert TIME to REAL, or TIME to INT and INT to REAL
    Is it possible?

    Best Regards
    Marek

     
  • frankiPL - 2017-02-04

    Sorry newbie question
    Conversion Operator TIME_TO_REAL

    Best Regards
    Marek

     
  • shooter - 2017-02-04

    because the scantime is a problem, check if you can get the needed precision.
    maybe you need the clocktime to get enough accuracy of the step.

    another way to get correct results, is by adding the step/time in a way like an x/y line can be computed.

     
  • Kim - 2017-02-13

    You can make use of the SysTime library, get the starting time in st1 and the stop time in st2, then calculate the elapsed time inbetween. It can be within a cycle or several cycles later, it doesn't matter.

    VAR
    Β  Β  st1, st2: SysTime;
    Β  Β  diElapsedTimeUs: DINT;
    END_VAR
    
    //Get starting time (in us)
    SysTimeGetUs(pUsTime:=st1);
    //Do something
    //Get stop time (in us)
    SysTimeGetUs(pUsTime:=st2);
    //Calculate elapsed time (in us)
    diElapsedTimeUs:=ANY_TO_DINT(st2-st1);
    
     

Log in to post a comment.