Tunability of sample time in code (embedded coder)

12 Ansichten (letzte 30 Tage)
mbenz
mbenz am 19 Jan. 2018
Kommentiert: mbenz am 6 Mär. 2019
I am trying to have models to be completely free of hard coded sample rate.
Right now, these models are used in both Simulation and to generate code (embedded coder). However, the sample time is hard-coded in the solver options. The models extensively uses S-functions blocks for which one of the inputs is the sample time. I am feeding that input using a probe block to get the sample time.
Is there an easy way to:
- when generating code, to not have any hard-coded sample time in the generated code
- Be able to perform simulation
- Be able to see sample time mismatch using the display sample time option (I am specifically concerned about mismatch between model sample time and the one being fed to the S-function sample time input)
- Only have to change the sample time in a single location for model and a single location for code (for e.g. by using an extern variable or as one of the inputs to the model).
- Solution should work for multi-rate models
- Support variable sample time during execution (was hoping to use Simulink.Parameter with a storage class set to ImportedExtern).

Akzeptierte Antwort

mbenz
mbenz am 23 Jan. 2018
Bearbeitet: mbenz am 25 Jan. 2018
This solution seems to work:
- defined sample time as a Simulink Parameter object with a storage class as imported extern. This enables to have the sample time defined in the code (non Simulink generated code)
- use the parameter object in models where required (blocks and solver options). For example, in a constant blocks value field and sample time fields (in order to accurately see the sample time propagation in models)
- make sure that the diagnostic loss of tunability is not set to error
  2 Kommentare
Paul Guenette
Paul Guenette am 5 Mär. 2019
Bearbeitet: Paul Guenette am 5 Mär. 2019
When i'm using this method and I input my parameter into the SampleTime flield of a block, I get an error "Parameter 'SampleTime' of <block> is non-tunable but refers to tunable variables". Any ideas?
Specifically, this is a DiscreteIntegrator block I'm trying to use.
mbenz
mbenz am 6 Mär. 2019
Hi Paul,
You have to change the diagnostic 'Detect loss of tunability' to something else than error.
Unfortunately, this doesn't guarantee you that the coder will not inline the value of the Simulink.Parameter.
For your case, with the Simulink shipped DiscreteIntegrator block, the value of the Simulink.Parameter will be inlined. If you have your own implementation of the integrator, you should be able to make it work.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by