Real-Time Workshop User's Guide    

Executing Models in Real Time

A real-time program differs from a Simulink simulation in that the program must execute the model code synchronously with real time. Every calculation results in some computational delay. This means the sample intervals cannot be shortened or lengthened (as they can be in Simulink), which leads to less efficient execution.

Figure 7-5: Unused Time in Sample Interval

Sample interval t1 cannot be compressed to increase execution speed because by definition, sample times are clocked in real time.

Real-Time Workshop application programs are designed to circumvent this potential inefficiency by using a multitasking scheme. This technique defines tasks with different priorities to execute parts of the model code that have different sample rates.

See Multitasking and Pseudomultitasking for a description of how this works. It is important to understand that section before proceeding here.

Multitasking Operation

The use of multitasking can improve the efficiency of your program if the model is large and has many blocks executing at each rate. It can also degrade performance if your model is dominated by a single rate, and only a few blocks execute at a slower rate. In this situation, the overhead incurred in task switching can be greater than the time required to execute the slower blocks. It is more efficient to execute all blocks at the dominant rate.

If you have a model that can benefit from multitasking execution, you may need to modify your Simulink model for this scheme to generate correct results.

Singletasking Operation

Alternatively, you can run your real-time program in singletasking mode. Singletasking programs require longer sample intervals due to the inherent inefficiency of that mode of execution.


 Simulating Models with Simulink Sample Rate Transitions