- Simulink model file, s-function files, and any relevant files required to reproduce the issue.
- The precise steps needed to reproduce the issue.
Function-Call subsystems with S-Functions does not work in two differrent version matlab with same compiler
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Shivam Malviya
2023-1-10
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;
Regards,
Shivam Malviya
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!