Documentation

mdlGetTimeOfNextVarHit

Specify time of the next sample time hit

Required

No

Languages

C, C++

Syntax

#define MDL_GET_TIME_OF_NEXT_VAR_HIT
void mdlGetTimeOfNextVarHit(SimStruct *S)

Arguments

S

SimStruct representing an S-Function block.

Description

The Simulink® engine invokes this optional method at a major time step when the variable sample time registered by this S-function has a hit. This method is used by the Simulink engine to determine the time of the next sample hit for variable sample time. The S-function should set this next sample hit using ssSetTNext macro in this method. The time of the next hit must be greater than the current simulation time as returned by ssGetT. The S-function must implement mdlGetTimeOfNextVarHit if it operates at a variable sample time.

For Level-2 MATLAB® S-functions, use a sample time of -2 to specify a variable sample time. The S-function's output method should then update the NextTimeHit property of the instance of the Simulink.MSFcnRunTimeBlock class representing the S-Function block to set the time of the next sample time hit. See /msfcn_vs.m for an example.

For Level-1 MATLAB S-functions, a flag of 4 is passed to the S-function when the next sample time hit needs to be calculated.

    Note   The time of the next hit can be a function of the input signals.

Example

  static void mdlGetTimeOfNextVarHit(SimStruct *S)
  {
    time_T offset = getOffset();
  	time_T timeOfNextHit = ssGetT(S) + offset;
  	ssSetTNext(S, timeOfNextHit);
  }

Introduced before R2006a

Was this topic helpful?