Functions
In ST, you can use a function call as an operand.
Example:
nResult := F_Add(7,5) + 3;
See also:
TIME() Function
This function returns a value of data type TIME.
The TIME() function does not represent an absolute reference point, but it can be used for relative time measurements by calculating the difference between at least two TIME() return values.
Sample in ST:
The following example contains a TON block (fbTimer), for which a time of 5 seconds is applied (tTimerValue), and which is started at the start of the program. The rising edge of the timer activation is detected by an R_TRIG block (fbTrigger), whereupon the return value of the TIME() function is buffered for the first time (tTimeReturn1). When the time interval of the timer has elapsed, a second return value of the TIME() function is buffered (tTimeReturn2). The relative time between the respective TIME() calls is calculated via the between at least the two stored TIME() return values (tDifference). In this case the time between timer start and timer end is calculated as 5 seconds.
PROGRAM MAIN
VAR
bStart : BOOL := TRUE;
fbTimer : TON;
tTimerValue : TIME := T#5S;
fbTrigger : R_TRIG;
tTimeReturn1 : TIME;
tTimeReturn2 : TIME;
tDifference : TIME;
END_VAR
//================================================
fbTimer(IN := bStart, PT := tTimerValue);
fbTrigger(CLK := fbTimer.IN);
IF fbTrigger.Q THEN
tTimeReturn1 := TIME();
END_IF
IF fbTimer.Q THEN
bStart := FALSE;
tTimeReturn2 := TIME();
tDifference := tTimeReturn2 - tTimeReturn1; // The difference will be T#5s
END_IF