You can use TIME
constants to operate the standard timer modules. The constant has a size of 32 bits
and a resolution in milliseconds.
In addition, the time constant LTIME
is available as a time basis for high-resolution timers. The LTIME
constant has a dimension of 64 bits and 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 time units must not be changed. However, it is not required to specify all units. It is permitted to specify the units in uppercase.
Time units
-
D | d
: Days -
H | h
: Hours -
M | m
: Minutes -
s | s
: Seconds -
MS | ms
: Milliseconds
Examples
Correct time constants of an ST assignment
VAR timLength : TIME := T#14ms; timLength1 : TIME := T#100s12ms; // Overflow in the highest unit is allowed. timLength2 : TIME := T#12h34m15s; timCompare : TIME; xIsOK: BOOL; timLongest := T#49D17H2M47S295MS; // 4294967295 END_VAR IF timLength < T#15MS THEN IF timCompare < timLength1 THEN xIsOK := TRUE; END_IF; END_IF
|
Overflow at a lower position |
|
Time marker |
|
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 units for LTIME
constants as for TIME
constants. You can also specify microseconds and nanoseconds because the specified
time is calculated in higher time resolution. LTIME
literals are treated internally as data type LWORD
and therefore the value resolved in nanoseconds.
Additional time units
-
US | us
: Microseconds -
NS | ns
: Nanoseconds
Examples of correct usage of an ST assignment:
PROGRAM PLC_PRG VAR ltimLength := LTIME#1000d15h23m12s34ms2us44ns; ltimLength1 := LTIME#3445343m3424732874823ns; END_VAR