5.1.111. Time (real) (ptm_RealTime)

Output the time since the model started (absolute), or output the time since the last time the block executed (relative).

5.1.111.1. Supported targets

All targets

5.1.111.2. Required license

None (Main library). (See Section 2.3, “Licensed Features”.)

5.1.111.3. Description

Output the current time (absolute), or output the time since the last time the block executed (relative). Time is tracked in two ways: for host simulation — using Simulink's task timing; and for target execution — using the ECU's operating system timers.

When run under simulation, this block has the same behaviour as the Simulink Time block, see Section 5.1.112, “Time (Simulink) (ptm_SimulinkTime)”.

When run on target, this block reads the time from the ECU's operating system. The ECU's operating system utilises a high resolution timer to provide microsecond, millisecond and second results, any of which can be selected as the block output using the drop-down option. When the block is iterated, the time outport is the latest reading from the high resolution timer.

The ptm_RealTime block can be configured to provide an absolute time or a relative time. The absolute time is the time at which the block is iterated since the start of the model (after power on, or reset). The relative time is time since the block was last iterated, or if the block has never iterated before, the time since the start of the model.

To understand the absolute time configuration, consider a simple model with two model rates, 5ms and 10ms. The 5ms model rate contains a ptm_RealTime block configured for absolute time, and to work in microseconds. The block is iterated at times A, C and D.

Figure 5.17. Example time-line to explain the ptm_RealTime block

Example time-line to explain the ptm_RealTime block

  1. At time A, the ptm_RealTime block sets time outport value to around 250 microseconds (the time since the model started).

  2. At time C, the ptm_RealTime block sets time outport value to around 5250 microseconds.

  3. At time D, the ptm_RealTime block sets time outport value to around 10250 microseconds.

And to understand the relative time configuration, consider the same model where the 10ms model rate contains a ptm_RealTime block configured for relative time. The block is iterated at times B and E.

  1. At time B, the ptm_RealTime block sets time outport value to around 1330 microseconds (the time since the model started as there has been no iteration of the block prior to time B).

  2. At time E, the ptm_RealTime block sets time outport value to around 10000 microseconds, being the difference between time E and B. The precise value will vary depending on the influence of higher-priority tasks and interrupt work.

The description above uses the term “around x milliseconds” because of task jitter. Task jitter occurs when the length of time a task takes to complete varies each time the task runs. As an example, consider a task that has some logic implemented by the auto-coder as an if-else statement. If in different iterations of the model task different parts of the if-else statement run, and if the processing which occurs for those parts differs, then each part will take a different amount of time to complete and the overall task duration will vary. If the ptm_RealTime block occurs after the if-else logic then the time output by the block will vary.

Warning

The type of outport time is an unsigned 32-bit integer, which limits the range of time this block can represent.

ResolutionMaximum duration
Microsecondsapprox. 71 minutes
Millisecondsapprox. 49 days
Secondsapprox. 136 years

The value for both absolute and relative time are provided modulo 232. It is up to the application to take care of the wrap around caused by the modulo.

5.1.111.4. Inports

None.

5.1.111.5. Outports

  • time

    The current real-time taken from the ECU's operating system timer, as either an absolute time since the model started, or as a relative time since the last time the block was iterated (or the start of the model if the block has not been iterated before).

    Range: [0, inf] modulo 232, seconds, milliseconds, or microseconds

5.1.111.6. Mask parameters

  • Time base

    The resolution and units of the outport time, as seconds, milliseconds or microseconds.

  • Output mode

    Whether the value of outport time is absolute or relative.

  • Sample time

    The periodicity of the block execution.

    Range: [0.001, 3600] seconds

    Value type:Real
    Calibratable:No

5.1.111.7. Notes

None.