Output the time since the model started (absolute), or output the time since the last time the block executed (relative).
None (Main library). (See Section 2.3, “Licensed Features”.)
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.
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.
At time C, the ptm_SimulinkTime block sets time outport value to 5 milliseconds.
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.
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:
At time A, the ptm_SimulinkTime block sets time outport value to 0 milliseconds.
At time B, the ptm_SimulinkTime block sets time outport value to 0 milliseconds.
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.
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.
The type of outport time is an unsigned 32-bit integer, which limits the range of time this block can represent.
Resolution | Maximum duration |
---|---|
Microseconds | approx. 71 minutes |
Milliseconds | approx. 49 days |
Seconds | approx. 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.