Main Content

Timer-Driven Task

This example shows how to use the Task Manager block in a simple system where a timer-driven task samples and modifies data generated from a random number source.

Task Manager and Software Application Model

The following model simulates a software application running on an ARM processor. A Task Manager block schedules the execution of the Timer Driven Subsystem, inside the Software Application Model Reference block. A Random Number block simulates an data source that the timer driven task samples.

The following model shows the Software Application model. This model contains the Timer-Driven Subsystem that executes based on the Timer Task events from the Task Manager block in the top-level model.

The Timer-Driven Task Subsystem, a Subsystem, samples a data value every 0.1 seconds from the Random Number block and applies the Algorithm. In this model, the algorithm outputs the negative scalar value of the sampled data value. The following model shows the Algorithm subsystem contained in the Timer-Driven Subsystem. The Inport block defines the 0.1 second sampling time for the Timer Driven Subsystem visible on the Software Application model when the Schedule rates parameter is enabled.

Simulation and Results

Click the Run button to build and run the model. When the model finishes running, open the Simulation Data Inspector to see the results of the simulation. Select the Timer_Task, original data, and processed data signals to see the effect of asynchronous task execution.

As shown in the Simulation Data Inspector, the running time of the Timer_Task varies at each instance. In some cases, the duration of the previous task execution delays the start of the next task execution. Additionally, the processed data from the task outputs at a the same time as the completion of the task execution, resulting in observed delay in the processed Data compared to the original data. As a result, despite the specified time step of 0.1 seconds, the start of execution now behaves as if the subsystem were executed on an SoC device processor with the associated real world processing limitations.