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

    frankiPL - 2017-02-04


    I need to calculate step value for some time period like this:

    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

  • frankiPL

    frankiPL - 2017-02-04

    Sorry newbie question
    Conversion Operator TIME_TO_REAL

    Best Regards

  • shooter

    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

    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.

    Β  Β  st1, st2: SysTime;
    Β  Β  diElapsedTimeUs: DINT;
    //Get starting time (in us)
    //Do something
    //Get stop time (in us)
    //Calculate elapsed time (in us)

Log in to post a comment.