日本語 English

How to Get Elapsed Time

Overview

Introduces how to measure ON time, for example when you want to know how long a bit is ON.
This method can also be applied to measure takt time and so on

Equipment cycle times are generally measured with the system clock, and for finer measurements such as function processing time, a free-running counter can be used.

How to measure bit ON time and takt time

Ladder logic

On the rising edge of SW001, the current time is saved in StartTime.
Then, on the falling edge of SW001, the current time is put in EndTime, and the SUB_DT_DT() instruction subtracts StartTime from EndTime and saves it in ElapsedTime.

Measuring time with the system clock
Measuring time with the system clock

ElapsedTime is saved as a Time type, so to convert it to a numeric type, use the TimeToNanoSec() instruction.

ST

As in the ladder, save the current time in StartTime before processing starts, and at the end of processing measure the elapsed time as the difference between the current time and StartTime.

StartTime := GetTime();

//Write the processing here

ElapsedTime:=SUB_DT_DT(GetTime(),StartTime);
MaxScan:=(LINT_TO_UDINT(TimeToNanoSec(ElapsedTime)/1000));	//Convert to microseconds
	

How to measure elapsed time more finely within a scan

Measures program processing time (elapsed time) in microseconds

Measuring time with the ElapsedSeconds function
Measuring time with the ElapsedSeconds function

Symbols

ElapsedSecondsFunc
Input
StartMicroSecCnt
Free-running counter value at the start of measurement
Output
out
Measured time (seconds) (LREAL)

FAQ

Can a PLC measure how long a bit is ON?

Yes, using the GetTime() function and the SUB_DT_DT() instruction.

Can takt time be measured?

Yes, from the difference between the start and end times.

Can processing time be obtained in microseconds?

Yes, by using a free-running counter.

Download

Comments