How do I make sure Simulink Constants are coded as #define?

12 views (last 30 days)
If I have a constant in the Simulink model, this ends up being defined in a structure which then ends up in RAM.
This results in really inefficient software as data needs to be loaded from ROM to RAM at startup and the compiled code has to load the same data from RAM. As the data is constant this also blocks the compiler from producong the most efficient code.
These constants should either be directly coded in the C code or #define
I can't find any settings that make this do what I need.

Accepted Answer

Sebastian Castro
Sebastian Castro on 20 Mar 2015

More Answers (2)

David
David on 23 Mar 2015
Hi Sebastian,
Thanks that has worked, in fact I only need to enable the inline parameters to make sure the #defines are generated although adding them as named constants would be better practice.
This may be a rhetorical question, but how did you know where to find the answer? I searched a lot on Friday for this and couldn't find it. I also now just did a test search with the terms "#define" and "constant" both of which appear in that linked page, but the page doesn't come up in the search results!
Dave
  1 Comment
Sebastian Castro
Sebastian Castro on 23 Mar 2015
First off, glad the answer helped! Secondly -- yes, this page wasn't too straightforward to find.
I went into the MATLAB help and searched for "#define preprocessor". Then, I filtered my results to only look at Embedded Coder. Filtering by product generally helps remove the "noise" from my searches.
- Sebastian

Sign in to comment.


David
David on 23 Mar 2015
So it turns out that enabling the inline parameters has the unexpected side affect of eliminating one of my code blocks which is required in my code.
The code block in question has no output which comes back into the model, but it's a real embedded block tha toggles a pin on my HW.
I can sort of understand that it could be eliminated due to it not reurning and data to the rest of the model, but why does this effect only occur when changing the inline parameters setting and how do I stop it from being eliminated?

Community Treasure Hunt

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

Start Hunting!