Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

mdlInitializeSampleTimes - Specify the sample rates at which this S-function operates

Required

Yes

C Syntax

#define MDL_INITIALIZE_SAMPLE_TIMES
void mdlInitializeSampleTimes(SimStruct *S)

C 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

ssSetSampleTime(S, sampleTimeIndex, sample_time)
ssSetOffsetTime(S, offsetTimeIndex, offset_time)

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:

The uppercase values are macros defined in simstruc_types.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.

If the number of sample times is 0, the Simulink engine assumes that the S-function inherits its sample time from the block to which it is connected, i.e., that the sample time is

[INHERITED_SAMPLE_TIME,  0.0]

This method can therefore return without doing anything.

Use the following guidelines when specifying sample times.

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 (ssIsContinuousTask(S,tid)) {
}

If the function wants to determine whether the third (discrete) task has a hit, it can use the following code fragment.

if (ssIsSampleHit(S,2,tid) {
}

Languages

C, C++

See Also

mdlSetInputPortSampleTime, mdlSetOutputPortSampleTime

  


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