Documentation

Inherit Sample Times

How Sample-Time Inheritance Works for Model Blocks

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. Additionally, 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).

Conditions for Inheriting Sample Times

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 size is auto

  • 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.

For more information, see Blocks Whose Outputs Depend on Inherited Sample Time.

Determining Sample Time of a Referenced Model

To determine whether a referenced model can inherit its sample time, set the Periodic sample time constraint on the Solver configuration parameters dialog pane 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:

  1. Update the model that references the model

  2. Select a Model block within the parent model

  3. Enter the following at the MATLAB® command line:

    get_param(gcb, 'CompiledSampleTime')

Blocks That Depend on Absolute Time

The following Simulink blocks depend on absolute time, and therefore preclude a referenced model from inheriting sample time:

Some blocks other than Simulink blocks depend on absolute time. See the documentation for the blocksets that you use.

Blocks Whose Outputs Depend on Inherited Sample Time

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. Simulink displays an error if you have set the Configuration Parameters > Solver > Periodic sample time constraint to Ensure sample time independent. 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.

Was this topic helpful?