Stopwatch

PLCopen motion icon Pipe Network motion icon

 Function Block - Measures the elapsed time between two events and gathers basic statistics when measurements are repeated.

  • When tuning the performance of an application, Stopwatch can be used to measure the execution time of a program, subprogram, UDFB, loops, or individual functions or function blocks.
  • StopWatch does not set outputs when passed the STOPWATCH_START action.
    • This is to allow users to observe the last collected values when observing values via the KAS-IDE.
  • StopWatch generates undefined values if called with a STOPWATCH_STOP is prior to being called with a STOPWATCH_START action.

Inputs

Input

Data Type

See Data Types.

Range

Unit

Default

Description

Action

INT

Enumerated

N/A

No default

The stopwatch action to perform:

Uses one of these enumeration values:

Value

Description

STOPWATCH_START

Start the measurement of a time interval.

STOPWATCH_STOP

Stop the measurement of a time interval.

STOPWATCH_RESET

  • Removes all information about previous measurements.
  • Resets the statistical information.

Outputs

Output

Data Type

See Data Types.

Range

Unit

Description

Value

LREAL

≥ 0 (zero)

Microseconds

  • The last measured elapsed time measurement, set when a STOPWATCH_STOP action is used.
  • A STOPWATCH_RESET action sets Value to 0 (zero).

Count

LREAL

≥ 0 (zero)

N/A

  • The number of elapsed time measurements gathered.
  • A STOPWATCH_RESET action sets Count to 0 (zero).

MinVal

LREAL

≥ 0 (zero)

Microseconds

  • The minimum of gathered elapsed time measurements.
  • A STOPWATCH_RESET action sets MinVal to 0 (zero).

MaxVal

LREAL

≥ 0 (zero)

Microseconds

  • The maximum of gathered elapsed time measurements.
  • A STOPWATCH_RESET action sets MaxVal to 0 (zero).

Mean

LREAL

≥ 0 (zero)

Microseconds

  • The mean value of gathered elapsed time measurements.
  • A STOPWATCH_RESET action sets Mean to 0 (zero).

StdDev

LREAL

≥ 0 (zero)

Microseconds

  • The standard deviation of gathered elapsed time measurements.
  • If less than 2 measurements have been gathered, then StdDev is set to zero.
  • A STOPWATCH_RESET action sets StdDev to 0 (zero).

FBD Language Example

FFLD Language Example

IL Language Example

Not available.

ST Language Example

Inst_Stopwatch(STOPWATCH_START);
// The body of a program Inst_Stopwatch(STOPWATCH_STOP); mean_program_time_us := Inst_Stopwatch.Mean; // microseconds

See Also