Why is the "Remove internal data zero initialization" option removed when the code generation interface is specified to a C++ class?

14 views (last 30 days)
I am attempting to code a simulink model using a C++ class as the code interface package. I have so far been able to generate the code, compile, and test it, however I have noticed some runtime issues.
I am using low pass filters in my model and noticed that early on in the program's execution the initial state of the internal delay blocks are not zero. Instead, they start with a random number associated with whatever was in memory at that time. I attempted to de-select the "Remove internal data zero initialization" option in the configuration parameters window to set their initial state to zero, however this option is greyed out.
Interestingly, if I change the initial state of the delay blocks to something non-zero, this creates initialization code which sets that value. This seems like an uneccessary limitation, as I cannot guarantee that the initial value of the variables is zero. Is there any work around to this which does not involve modifying the generated code?

Answers (1)

Jasvin
Jasvin on 9 Mar 2023
Edited: Jasvin on 9 Mar 2023
Unfortunately, if the "Remove internal data zero initialization" option is greyed out in the Simulink configuration parameters window, it means that this option is not available for your current configuration. This may be because you are using a C++ class as the code interface package, as certain options may not be compatible with this type of setup.
And there doesn't seem to be any workaround for this other than modifying the generated code to either add an initialization step or explicitly initialize the delay block.
  1 Comment
SB
SB on 9 Mar 2023
Thank you for your response. I am using a C++ class as the code interface package.
When I explicitly initialize the delay block to a non-zero value, that initialization becomes generated in the initialize() function. However, explicitly initializing the delay block to 0 becomes optimized out of the generated code. I am unsure how the latter is incompatible with a class interface.

Sign in to comment.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!