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

10 次查看(过去 30 天)
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?

回答(1 个)

Jasvin
Jasvin 2023-3-9
编辑:Jasvin 2023-3-9
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 个评论
SB
SB 2023-3-9
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by