- Signal storage reuse
- Reuse block outputs
- Enable local block outputs
- Eliminate superfluous local variables (expression folding)Please uncheck each of those settings if they are checked, and you should be able to see global variables for parameters replaced with local variables wherever possible with the updated parameter settings.In addition, I would like to confirm that you are talking about variables representing block parameter values, and not the signals feeding in and out of the blocks. Variables representing signals are almost always of type "extern", with rare instances as seen below:Run this command in MATLAB 2016b for documentation:>> web(fullfile(docroot, 'ecoder/ug/signals.html'))Here is a reference for a detailed explanation of how storage classes affect variables.Run this command in MATLAB 2016b for documentation:>> web(fullfile(docroot, 'ecoder/ug/parameters.html'))
Embedded Coder - Simulink.Parameter declaration
5 views (last 30 days)
Show older comments
MathWorks Support Team
on 20 Jan 2017
Edited: MathWorks Support Team
on 12 Apr 2023
When I generate autocode for the using the TI C2000 toolchain, all Simulink.Parameter variables in the model are declared as 'extern' in the model header file. I.E. if I have a variable x, when i generate code, the header file will have a line that says something like extern int x; No matter what datastorage method I use, the end result is that the variable is some kind of extern (Simulink Global puts the variable into a structure, and then the structure has an extern declaration).
Because we are using Model Based Development to create code for aerospace applications, any global declarations are not allowed. How do I get Simulink to generate code where Simulink.Parameter values are created inside the model's function (i.e. so the variables are not accessible by other functions).
Accepted Answer
MathWorks Support Team
on 12 Apr 2023
Edited: MathWorks Support Team
on 12 Apr 2023
My understanding of the issue is that in your Simulink model, all parameters are treated as extern variables when the code is generated for the model. You would like to get rid of extern variables and instead wish to see those parameters treated as local variables.
The way to make the variable local is to set the storage class to "auto". However, upon doing so, the Embedded Coder's optimization settings must be taken care to make sure that local variables are generated whenever possible. To do so, in the configuration parameters dialog box for the model (press CTRL + E in the model), go to "All Parameters" tab, and search for the following optimization settings for code generations:
0 Comments
More Answers (0)
See Also
Categories
Find more on Simulink Coder 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!