Writing S-Functions Previous page   Next Page

Specifying Model Reference Sample Time Inheritance

If your S-function inherits its sample times from the blocks that drive it, it should specify whether it is safe to use the S-function in a submodel. It is safe only if the S-function's output does not depend on the inherited sample time. If the S-function's output does not depend on its inherited sample time, use the ssSetModelReferenceSampleTimeInheritanceRule macro to set the S-function's sample time inheritance rule to USE_DEFAULT_FOR_DISCRETE_INHERITANCE. Otherwise, set the rule to DISALLOW_SAMPLE_TIME_INHERITANCE. Specifying the inheritance rule allows Simulink to disallow sample-time inheritance for submodels that include S-functions whose outputs depend on their inherited sample time and thereby avoid inadvertent simulation errors.

If you are uncertain whether an existing S-function's output depends on its inherited sample time, check whether it invokes any of the following C macros:

or TLC functions:

If the S-function does not invoke any of these macros or functions, its output does not depend on its inherited sample time and hence it is safe to use in submodels that inherit their sample time.

Sample-Time Inheritance Rule Example

As an example of an S-function that precludes a submodel from inheriting its sample time, consider an S-function that has the following mdlOutputs method:

This output of this S-function is its inherited sample time, hence its output depends on its inherited sample time, and hence it is unsafe to use in a submodel. For this reason, this S-function should specify its model reference inheritence rule as follows:


Previous page  Synchronizing Multirate S-Function Blocks Work Vectors Next page

© 1994-2005 The MathWorks, Inc.