Why does Stateflow not retrieve the correct value of a variable defined in C-code and updated in a reference model?

4 views (last 30 days)
I have created two similar Simulink models structured in the following way:
  • Each model calls a (different) reference model, which contains a Stateflow chart which calls (very simple) C-code to write to a variable. The value of the variable is then returned to the main model and displayed on a Scope.
  • The variable is also accessed by the main model via a Stateflow chart and displayed on the same Scope.
The values shown on the Scope of the first model (when output by the reference model and retrieved by the main model) are the same.
For the second model, however, the value retrieved by the main model is always zero. Why is that?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 16 Apr 2019
The issue is related to the fact that custom code data are only shared across model references if the custom code specifications are exactly the same. Each unique custom code specification is compiled separately, thus their memory is not shared.
Please make sure that the custom mode data defined in 'Configuration Parameters > Simulation Target' is the same for both the main and reference models.
In general, the easiest way to ensure the same custom code specification is to use the same configuration reference across the top and reference models. For more details on this, please refer to the following documentation page:

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!