The sample times of a Model block are the sample times of the model that it references. If the referenced model must run at specific rates, the model specifies the required rates. Otherwise, the referenced model inherits its sample time from the parent model.
Placing a Model block in a triggered, function call, or iterator subsystem relies on the ability to inherit sample times. Also, allowing a Model block to inherit sample time maximizes its reuse potential. For example, a model can fix the data types and dimensions of all its input and output signals. You could reuse the model with different sample times (for example, discrete at 0.1 or discrete at 0.2, triggered).
A referenced model inherits its sample time if the model:
Does not have any continuous states
Specifies a fixed-step solver and the Fixed-step
Contains no blocks that specify sample times (other than inherited or constant)
Does not contain any S-functions that use their specific sample time internally
Has only one sample time (not counting constant and triggered sample time) after sample time propagation
Does not contain any blocks, including Stateflow® charts, that use absolute time, as listed in Blocks That Depend on Absolute Time
Does not contain any blocks whose outputs depend on inherited sample time, as listed in Blocks Whose Outputs Depend on Inherited Sample Time.
You can use a referenced model that inherits its sample time anywhere in a parent model. By contrast, you cannot use a referenced model that has intrinsic sample times in a triggered, function call, or iterator subsystem. To avoid rate transition errors, ensure that blocks connected to a referenced model with intrinsic samples times operate at the same rates as the referenced model.
A continuous sample time cannot be propagated to a Model block that is sample-time independent.
For more information, see Blocks Whose Outputs Depend on Inherited Sample Time.
To determine whether a referenced model can inherit its sample time, set the
Periodic sample time constraint configuration parameter to
Ensure sample time independent. If the model is
unable to inherit sample times, this setting causes Simulink® to display an error message when building the model. See Periodic sample time constraint for more about this option.
To determine the intrinsic sample time of a referenced model, or the fastest intrinsic sample time for multirate referenced models:
Update the model that references the model
Select a Model block within the parent model
Enter the following at the MATLAB® command line:
The following Simulink blocks depend on absolute time, and therefore preclude a referenced model from inheriting sample time:
Backlash (only when the model uses a variable-step solver and the block uses a continuous sample time)
Discrete-Time Integrator (only when used in triggered subsystems)
Sine Wave (only when the
Sine type parameter is
stateflow (when the chart uses
absolute-time temporal logic, or the reserved word
To Workspace (only when logging to
Some blocks other than Simulink blocks depend on absolute time. See the documentation for the blocksets that you use.
Using a block whose output depends on an inherited sample time in a referenced model
can cause simulation to produce unexpected or erroneous results. When building a
referenced model that does not need a specified rate, Simulink checks for blocks whose outputs are functions of the inherited sample
time. This checking includes examining S-Function blocks. If Simulink finds any such blocks, it specifies a default sample time. If you have set
the Configuration Parameters > Solver > Periodic sample time constraint to
Ensure sample time
independent,Simulink displays an error. See Periodic sample time constraint for more about this option.
The outputs of the following built-in blocks depend on inherited sample time. The outputs of these blocks preclude a referenced model from inheriting its sample time from the parent model:
Simulink assumes that the output of an S-function does not depend on inherited sample time unless the S-function explicitly declares the contrary. See Sample Times for information on how to create S-functions that declare whether their output depends on their inherited sample time.
In referenced models that inherit their sample time, avoid S-functions in referenced models that fail to declare whether output depends on inherited sample time. Excluding those kinds of S-functions helps to avoid simulation errors. By default, Simulink warns you if your model contains such blocks when you update or simulate the model. See Unspecified inheritability of sample time for details.
Use consistent sample time rates to promote the reliable use of a model referenced by another model. Make the rates of root Inport and Outport blocks in a referenced model consistent with the rates of blocks reading from and writing to those blocks. Simulink generates an error when there are sample time mismatches between:
The sample times of root Inport blocks and the sample times of blocks to which the Inport block inputs.
The sample times of root Outport blocks and the sample times of blocks that input to the Outport block.
To address an error that flags a sample time inconsistency in a referenced model, you can use one of these approaches.
|Root Inport or Output Block Sample Time is Different From||Possible Solution|
All the blocks to which it connects, and those blocks all have the same sample time as each other
Set the sample time of the Inport or Outport block so that it matches the sample time of the block to which it connects.
One or more blocks and the same as one or more blocks
For blocks that do not match the Inport or Outport block, insert Rate Transition blocks on the signal that connects to the Inport or Outport block.