Function-Call subsystems with S-Functions does not work in two differrent version matlab with same compiler

3 views (last 30 days)
I tried to implement function-call subsystem with S-Function, block can work with matlab version 2019B, but it did not work with matlab version 2021A.
Two version matlab (2019B and 2021A) using same compiler
  • Matlab version:
  • Compiler:
Configure function-call subsystem with S-Function:
  • In mdlInitializeSizes, set the data type of the S-function output port and configure block properties:
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
if (!ssSetNumInputPorts(S, 0)) return;
if (!ssSetNumOutputPorts(S,1)) return;
ssSetOutputPortWidth(S, 0, 1);
/* All output elements are function-call, so we can set the data type of the
* entire port to be function-call. */
ssSetOutputPortDataType(S, 0, SS_FCN_CALL);
ssSetNumSampleTimes( S, 1);
ssSetNumRWork( S, 0);
ssSetNumIWork( S, 0);
ssSetNumPWork( S, 0);
ssSetNumModes( S, 0);
ssSetNumNonsampledZCs( S, 0);
/* specify the sim state compliance to be same as a built-in block */
ssSetOperatingPointCompliance(S, USE_CUSTOM_OPERATING_POINT);
ssSetOptions(S, SS_OPTION_USE_TLC_WITH_ACCELERATOR |
SS_OPTION_CALL_TERMINATE_ON_EXIT |
SS_OPTION_CAN_BE_CALLED_CONDITIONALLY |
SS_OPTION_EXCEPTION_FREE_CODE |
SS_OPTION_ASYNCHRONOUS_INTERRUPT |
SS_OPTION_SFUNCTION_INLINED_FOR_RTW |
SS_OPTION_DISALLOW_CONSTANT_SAMPLE_TIME);
/* Set model reference supported & sample time inheritance rule in model reference of S-function */
ssSetModelReferenceNormalModeSupport(S, MDL_START_AND_MDL_PROCESS_PARAMS_OK);
ssSetModelReferenceSampleTimeInheritanceRule(S, USE_DEFAULT_FOR_DISCRETE_INHERITANCE);
  • In mdlInitializeSampleTimes, specify that an output port is issuing a function call and set sample time:
ssSetSampleTime(S, 0, -1.0);
ssSetOffsetTime(S, 0, 0.0);
ssSetCallSystemOutput(S,0); /* call on first element */
  • In mdlStart, init value for userData
UserDataType* userData = ssGetUserData(S);
userData->condition = 0U;
  • Execute the subsystem in mdlOutputs, execute the subsystem:
UserDataType* userData = ssGetUserData(S);
mexPrintf("--------------------------\n");
if (ssIsMajorTimeStep(S) == true) {
userData->condition = userData->condition + 1U;
mexPrintf("current time %2.20f\n", ssGetT(S));
mexPrintf("userData->condition %u\n", userData->condition);
if ((userData->condition % 10) == 0U) {
ssCallSystemWithTid(S, 0, tid);
mexPrintf("calling\n");
}
}
  • In mdlTerminate, free userData
UserDataType* userData = ssGetUserData(S);
/* Free memory for user data */
free(userData)
The model:
The result and log when I run moel in two matlab version:
Why are these different phenomenon on two matlab version?
Can anyone answer my questions? Thanks in advance
  2 Comments
Shivam Malviya
Shivam Malviya on 10 Jan 2023
Hi Hoa,
I understand that a Simulink model produces different outputs when run on different MATLAB versions.
Can you share the following information to understand the query better;
  1. Simulink model file, s-function files, and any relevant files required to reproduce the issue.
  2. The precise steps needed to reproduce the issue.
Regards,
Shivam Malviya
Hoa Dang
Hoa Dang on 13 Jan 2023
Hi Shivam,
Thanks for your answer,
  1. I add model information in attached file
  2. About procedure of the issue, you can mex the s-funtion file and run model in attached file
  • I using an example function-call subsystem model of matlab and replace sfun_fcncall block with my s-function
  • And change configuration "Solver" to "Fixed-step" only

Sign in to comment.

Answers (0)

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!