5.1.112. Time (Simulink) (ptm_SimulinkTime)

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

5.1.112.1. Supported targets

All targets

5.1.112.2. Required license

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

5.1.112.3. Description

Output the current Simulink task time (absolute), or output the time since the last time the block executed (relative). Time is tracked using Simulink's task timers for both host simulation and target execution.

This block reads the time from the Simulink's task timers. Simulink task timers track the time each task should run at the resolution of the quickest model rate. For instance, if there were two model rates, 5ms and 10ms, then the resolution of the Simulink task timer for each model rate would be 5ms. The block converts these timers to microsecond, millisecond or second resolution, as required by parameter Time base. When the block is iterated, the time outport is the timer for the current model rate task.

The ptm_SimulinkTime block can be configured to provide an absolute time or a relative time. The absolute option is the Simulink task time at which the block is iterated since the start of the model (after power on, or reset). The relative option is the Simulink task time since the block was last iterated, or if the block has never iterated before, the Simulink task 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_SimulinkTime block configured for absolute time. The block is iterated at times A, C and D.

Figure 5.18. Example time-line to explain the ptm_SimulinkTime block

Example time-line to explain the ptm_SimulinkTime block

  1. At time A, the ptm_SimulinkTime block sets time outport value to 0 milliseconds (the time since the model started). Note that the time matches the start of the model rate task and not the current time. If the current time is required then see the ptm_RealTime block.

  2. At time C, the ptm_SimulinkTime block sets time outport value to 5 milliseconds.

  3. At time D, the ptm_SimulinkTime block sets time outport value to 10 milliseconds.

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

  1. At time B, the ptm_SimulinkTime block sets time outport value to 0 milliseconds (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_SimulinkTime block sets time outport value to 10 milliseconds.

In the last example at time B, the 10ms Simulink task timer is zero rather 0.5 milliseconds. The Simulink task timer is zero because Simulink would like to start both the 5ms and 10ms model rate tasks at the same time, time zero. Because the ECU's operating system runs the quickest rate task first, the 10ms model rate task starts after the 5ms model rate task has completed.

If the 10ms model rate task were to take longer and the 5ms model rate task ran more quickly, for example, every 2ms, then the task sequence over time looks different:

  1. At time A, the ptm_SimulinkTime block sets time outport value to 0 milliseconds.

  2. At time B, the ptm_SimulinkTime block sets time outport value to 0 milliseconds.

  3. At time C, even though the 10ms task has not yet completed, the 2ms model rate task ran and Simulink updated timer for that task. The ptm_SimulinkTime block therefore sets time outport value to 2 milliseconds.

  4. At time D, the 10ms model rate task has not yet completed and the Simulink task timer remains at zero. The ptm_SimulinkTime block therefore sets time outport value to 0 milliseconds.

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.

Simulink may generate code to maintain its task timers using a type which cannot represent the full range of the outport time. In this case, the Simulink task timers may saturate rather than wrap around due to the modulo. Again, it is up to the application to address this condition.

For more information about Simulink's task timers see the MathWorks' documentation for RTW.

5.1.112.4. Inports

None.

5.1.112.5. Outports

  • time

    The current simulink task time, 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.112.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

5.1.112.7. Notes

None.