How to avoid Code Inspector warnings about If blocks connected to Constant blocks?

I have a model that I'm trying to update to pass all Code Inspector checks within Model Advisor, because I will be generating code from it. One check that I've not been able to resolve is under the "Check If blocks" section and reads as follows:
Warning: The following blocks are constant or have ports connected to Constant blocks or other blocks that are constant
An example is that we have an internal timer where the confirmation time is coming from a Constant block; the Constant block has a non-inf update rate and the parameter within it is tuneable. So when code is generated, it may actually change during execution but it fails the Code Inspector checks.
How can use tuneable parameters, in Constant blocks or otherwise, and avoid the error I described above?
Edit: this is with R2016, and we have standards that we should avoid placing parameters within masks as this can hide functionality.

Answers (1)

If you are using an internal timer, Simulink has a block named Clock, which provides the simulation time of the model. You may use it instead of a Constant block. Hope this helps.

4 Comments

I think even if I used the native Simulink Clock block (instead of our customer Timer utility) I would still be comparing it to a Constant block to evaluate whether or not a threshold has been reached. This would still result in a warning related to the use of a Constant with an If block.
Simply try an MATLAB Function that outputs a constant value. Simulink supports the usage of MATLAB Function. You can try this.
I will test this out - but I suspect I will lose the ability to tune the parameter as the model is running (using generated code). I will try and report back.
You can set the parameter you want to tune as an input and take it as an output in the function.

Sign in to comment.

Categories

Find more on Simulink Code Inspector in Help Center and File Exchange

Products

Asked:

on 18 Oct 2017

Commented:

on 24 Oct 2017

Community Treasure Hunt

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

Start Hunting!