Products & Services Solutions Academia Support User Community Company

Learn more about Real-Time Workshop   

Writing S-Functions That Specify Sample Time Inheritance Rules

For the Simulink engine to accurately determine whether a model can inherit a sample time, the S-functions in the model need to specify how they use sample times. You can specify this information by calling the macro ssSetModelReferenceSampleTimeInheritanceRule from mdlInitializeSizes or mdlSetWorkWidths. To use this macro:

  1. Check whether the S-function calls any of the following macros:

    • ssGetSampleTime

    • ssGetInputPortSampleTime

    • ssGetOutputPortSampleTime

    • ssGetInputPortOffsetTime

    • ssGetOutputPortOffsetTime

    • ssGetSampleTimePtr

    • ssGetInputPortSampleTimeIndex

    • ssGetOutputPortSampleTimeIndex

    • ssGetSampleTimeTaskID

    • ssGetSampleTimeTaskIDPtr

  2. Check for the following in your S-function TLC code:

    • LibBlockSampleTime

    • CompiledModel.SampleTime

    • LibBlockInputSignalSampleTime

    • LibBlockInputSignalOffsetTime

    • LibBlockOutputSignalSampleTime

    • LibBlockOutputSignalOffsetTime

  3. Depending on your search results, use ssSetModelReferenceSampleTimeInheritanceRule as indicated in the following table.

    If...Use...
    None of the macros or functions are present, the S-function does not preclude the model from inheriting a sample time.
    ssSetModelReferenceSampleTimeInheritanceRule
        (S, USE_DEFAULT_FOR_DISCRETE_INHERITANCE)
    

    Any of the macros or functions are used for

    • Throwing errors if sample time is inherited, continuous, or constant

    • Checking ssIsSampleHit

    • Checking whether sample time is inherited in either mdlSetInputPortSampleTime or mdlSetOutputPortSampleTime before setting

    ssSetModelReferenceSampleTimeInheritanceRule...
    (S,USE_DEFAULT_FOR_DISCRETE_INHERITANCE)
    
    The S-function uses its sample time for computing parameters, outputs, and so on
    ssSetModelReferenceSampleTimeInheritanceRule
    (S, DISALLOW_SAMPLE_TIME_INHERITANCE)
    

You can use settings on the Diagnostics/Solver pane of the Configuration Parameters dialog box or Model Explorer to control how the Simulink engine responds when it encounters S-functions that have unspecified sample time inheritance rules. Toggle the Unspecified inheritability of sample time diagnostic to none, warning, or error. The default is warning.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS