I would like to measure the execution time of a structured text (ST) program. The task associated with the program is running at 10 ms.
How do I measure execution time?
I would like to measure the execution time of a structured text (ST) program. The task associated with the program is running at 10 ms.
How do I measure execution time?
You can use free TwinCAT library Tc2_Utilities
that has a function block Profiler
.
The "Profiler" function block can be used to allow the execution time of PLC code to be measured.
The Infosys page has an example code also:
VAR
Profiler1 : PROFILER;
END_VAR
Profiler1(START := TRUE, RESET := TRUE);
//Do something here
Profiler1(START := FALSE);
//Now Profiler1.Data has the execution time
Of course, you can use Profiler but just for demonstration purpose you can measure execution time like this.
PROGRAM PLC_PRG
VAR
tStart: TIME; (* Time program start *)
tWork : TIME; (* Execution time *)
END_VAR
(* First line of main program *)
tStart := TIME();
// Your program here
(* Last line of your program *)
tWork := TIME() - tStart;
END_PROGRAM