Contents

mdlZeroCrossings

Update zero-crossing vector

Required

No

Languages

C, C++

Syntax

#define MDL_ZERO_CROSSINGS
void mdlZeroCrossings(SimStruct *S)

Arguments

S

SimStruct representing an S-Function block.

Description

An S-function needs to provide this optional method only if it does zero-crossing detection. Implementing zero-crossing detection typically requires using the zero-crossing and mode work vectors to determine when a zero crossing occurs and how the S-function's outputs should respond to this event. The mdlZeroCrossings method should update the S-function's zero-crossing vector, using ssGetNonsampledZCs.

You can use the optional mdlZeroCrossings routine when your S-function has registered the CONTINUOUS_SAMPLE_TIME and has nonsampled zero crossings (ssGetNumNonsampledZCs(S) > 0). The mdlZeroCrossings routine is used to provide the Simulink® engine with signals that are to be tracked for zero crossings. These are typically

  • Continuous signals entering the S-function

  • Internally generated signals that cross zero when a discontinuity would normally occur in mdlOutputs

Thus, the zero-crossing signals are used to locate the discontinuities and end the current time step at the point of the zero crossing. To provide the engine with zero-crossing signals, mdlZeroCrossings updates the ssGetNonsampleZCs(S) vector.

Example

For an example, see sfun_zc_sat.csfun_zc_sat.c. A detailed description of this example can be found in Zero Crossings.

Was this topic helpful?