TIME/LTIME constants

You can use TIME constants to handle the standard timer modules. The constant has a size of 32 bits and thus a resolution in milliseconds.

In addition, the time constant LTIME is available as a time base for high-resolution timers. The LTIME constant has a size of 64 bits and thus a resolution in nanoseconds.

TIME constant

Syntax:

<time keyword> # <length of time>  
<time keyword>   : TIME | time | T | t
<length of time> : ( <number of days>d )? ( <number of hours>h )? ( <number of minutes>m )? ( <number of seconds>s )? (<number of milliseconds>ms)?    // ( ...)? Optional

The order of the time units must not be changed. It is not necessary to use all units.

Time units:

Examples: Correct time constants in an ST assignment

VAR
    tLength0 : TIME := T#14ms;
    tLength1 : TIME := T#100s12ms;      // Overflow in the highest unit is allowed.
    tLength2 : TIME := T#12h34m15s;
    tCompare : TIME;
    bOK      : BOOL;
    tLongest := T#49D17H2M47S295MS;    // 4294967295
END_VAR
IF tLength < T#15MS THEN
    IF tCompare < tLength1 THEN
        bOK := TRUE;
    END_IF;
END_IF

Examples: Incorrect use of time constants

tIncorrect1 := t#5m68s;

Overflow at a lower position

tIncorrect2 := 15ms;

Time identifier T# missing

tIncorrect3 := t#4ms13d;

Incorrect order of time units

LTIME constant

Syntax:

<long time keyword> # <length of high resolution time>  
<long time keyword>              : LTIME | ltime 
<length of high resolution time> : <length of time> ( <number of microseconds>us )? ( <number of nanoseconds>ns )?    // ( ...)? Optional

You can use the same time units for LTIME constants as for TIME constants. Additionally, you can specify microseconds and nanoseconds, since the time specification is calculated in higher temporal resolution. Internally LTIME literals are treated like the data type LWORD and therefore the value is resolved in nanoseconds.

Additional time units:

Examples: Correct time constants in an ST assignment

VAR
    tLength0 : TIME := LTIME#1000d15h23m12s34ms2us44ns;
    tLength1 : TIME := LTIME#3445343m3424732874823ns;
END_VAR