User`s guide
Single- Versus Multitasking Environments
7-9
Simulating Models with Simulink
Before Simulink simulates a model, it orders all of the blocks based upon their
topological dependencies. This includes expanding subsystems into the
individual blocks they contain and flattening the entire model into a single list.
Once this step is complete, each block is executed in order.
The key to this process is the proper ordering of blocks. Any block whose output
is directly dependent on its input (i.e., any block with direct feedthrough)
cannot execute until the block driving its input has executed.
Some blocks set their outputs based on values acquired in a previous time step
or from initial conditions specified as a block parameter. The output of such a
blockisdeterminedbyavaluestoredinmemory,whichcanbeupdated
independently of its input. During simulation, all necessary computations are
performed prior to advancing the variable corresponding to time. In essence,
this results in all computations occurring instantaneously (i.e., no
computational delay).
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
sample times must stay in sync with 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.
t0
t1
t2
Time