Writing S-Functions | ![]() ![]() |
Specify the sample rates at which this S-function operates.
Syntax
Arguments
S
SimStruct representing an S-Function block.
Description
This method should specify the sample time and offset time for each sample rate at which this S-function operates via the following paired macros
where sampleTimeIndex
runs from 0
to one less than the number of sample times specified in mdlInitializeSizes via ssSetNumSampleTimes.
If the S-function operates at one or more sample rates, this method can specify any of the following sample time and offset values for a given sample time:
[CONTINUOUS_SAMPLE_TIME, 0.0]
[CONTINUOUS_SAMPLE_TIME, FIXED_IN_MINOR_STEP_OFFSET]
[discrete_sample_period, offset]
[VARIABLE_SAMPLE_TIME, 0.0]
The uppercase values are macros defined in simstruc.h
.
If the S-function operates at one rate, this method can alternatively set the sample time to one of the following sample/offset time pairs.
[INHERITED_SAMPLE_TIME, 0.0]
[INHERITED_SAMPLE_TIME, FIXED_IN_MINOR_STEP_OFFSET]
If the number of sample times is 0, Simulink assumes that the S-function inherits its sample time from the block to which it is connected, i.e., that the sample time is
This method can therefore return without doing anything.
Use the following guidelines when specifying sample times.
Note that VARIABLE_SAMPLE_TIME
requires a variable-step solver.
ssSetOptions
to set the SS_OPTION_DISALLOW_CONSTANT_SAMPLE_TIME
simulation option in mdlInitializeSizes
mdlSetWorkWidths
:
to discrete blocks residing in triggered subsystems.
If this function has no intrinsic sample time, it should set its sample time to inherited according to the following guidelines:
The S-function should use the ssIsSampleHit or ssIsContinuousTask macros to check for a sample hit during execution (in mdlOutputs or mdlUpdate). For example, if the block's first sample time is continuous, the function can use the following code fragment to check for a sample hit.
If the function wants to determine whether the third (discrete) task has a hit, it can use the following code fragment.
Languages
See Also
mdlSetInputPortSampleTime, mdlSetOutputPortSampleTime
![]() | mdlInitializeConditions | mdlInitializeSizes | ![]() |