How do I create a sample time independent S-function block from a subsystem in Simulink Coder 8.4 (R2013a)?
3 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Edited: MathWorks Support Team
on 30 Sep 2015
I am generating an S-function block from a subsystem by right-clicking on the subsystem block and selecting "C/C++ Code > Generate S-Function...". I notice that the generated S-function code has the sample times hardcoded in it. So when I try to use this new block in different models, they fail to run. I would like to know how I can make S-function block independent of the sample time.
Accepted Answer
MathWorks Support Team
on 30 Sep 2015
It is mentioned in the help documentation under "Simulink Coder > Customization > Block Authoring > S-Functions > Create S-Function Blocks from a Subsystem" that when creating an S-Function Block from a Subsystem, the block will have the sample times hard-wired. However, if the model has no dependence on the sample time, then you can generate an S-function which is independent of the sample time. The section under "Sample Time Propagation in Generated S-Functions" mentions the conditions that govern sample time propagation for S-functions. Also take a look at the referenced pages "Inherit Sample Times".
The sample model, sampleModel_R2013a.slx, illustrates this behavior. The model is independent of sample time and the "Periodic sample time constraint" property (Configuration Parameters > Solver > Tasking and sample time options) is set to "Ensure sample time independent". Now the S-function block generated will be sample time independent. You will also notice in the generated code, SourceSubsys_sf.c, that mdlInitializeSampleTimes() specifies ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);
0 Comments
More Answers (0)
See Also
Categories
Find more on Subsystems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!