Mask parameter value is ignored with HDL Counter word length

Hello,
I developed a specialized counter to accept starting count and max count values through inputs. I've made this into a model so I can use model referencing. This seems to work fine.
However, one thing I'm missing is the ability to set the counter's word size independently in every instantiation. This is where a mask would seem to be the solution.
I added a mask with a single parameter: counter_word_length, and set the word length parameter in the HDL Counter to this variable. Now my counter has a mask.
I open the mask for the referenced model and set counter_word_length to 13 (default was 16). The output type of the counter does not change accordingly. It should be ufix13, but it stubbornly remains uint16. The Word length field in the HDL Counter mask shows the correct value of 13 in the indicator field at the right edge of the editable field. Yet still, the output type is uint16.
I have changed this field to "13" instead of the variable and everything works as expected. What am I doing wrong?
I can share the model and a system that exercises the model if the answer to this isn't obvious.
Thanks,
Charles

3 Comments

Attached is the model and a test bench system using it.
I started running into another problem as well when trying to use this model. I need to run in an accelerated mode, but I keep getting this message:
Model arguments can not be used in non-tunable expressions. Parameter 'OutDataTypeStr' of 'Prog_HDL_load_counter/Free-Running Counter/load_val' is non-tunable but refers to
variables (counter_word_length (model argument)).
This does not happen in the attached test bench, nor does it happen in the main system when running in Normal mode.
Thanks,
Charles
Still waiting for a response to my questions. Is there a way to make the mask parameter non-tuneable?

Sign in to comment.

 Accepted Answer

Model Reference is not compatible with what you are trying to do. As an alternative, consider creating a Simulink library and putting your counter in that library as a masked subsystem block, or use Subsystem Reference.
The reason Model Reference is not compatible is that reference models are always compiled fully independently of any parent models that are using a reference model. Standalone fully independent compile is a hugh advantage when working on large Model Based Design projects. Benefits include saving lots of time when starting the simulation of a parent model. Compiling a model locks down many things about a model including data types. So trying to change the data types in a child reference model based on a settings in a parent model is incompatible.
Linking to a subsystem does NOT have the independent compile behavior. The subsystem is compiled at the same time as the parent, so it has the opportunity to change things like data types based on mask parameters.
Minor tip: If a parameter will specify attributes of a parameter, then set that parameter to be NON-tunable in the mask editor. Data types are not allowed to change (i.e. be tuned) in the middle of a simulation.

1 Comment

Ok, I've tried this with a Subsystem Reference and it works great. I do plan to start a Simulink library, so I'll probably start with this function.
Thanks for the explanation. It makes sense, but I admit to still being confused by models, subsystems, systems, etc. and I definitely don't know what all the differences are. At any rate, this is a good solution for my purposes.
Charles

Sign in to comment.

More Answers (1)

Hello Charles,
Regarding your first question, it sounds like the HDL Counter block is not recognizing the updated value of the counter_word_length parameter from the mask. One possible reason for this could be that the counter_word_length parameter is not properly linked to the HDL Counter block.
To link the parameter to the block, you can try the following steps:
  1. Open the mask editor for the referenced model.
  2. Click on the "View/Edit Model Parameters" button to open the "Model Explorer" window.
  3. In the "Model Explorer" window, locate the HDL Counter block and select it.
  4. In the "Properties" pane of the "Model Explorer" window, find the "Word length" parameter and click on the "..." button next to it.
  5. In the "Parameter Properties" window, set the "Data type" to "Inherit: auto".
  6. In the "Parameter Properties" window, set the "Value" to counter_word_length.
  7. Click "OK" to close the "Parameter Properties" window.
This should properly link the counter_word_length parameter to the HDL Counter block and set its word length accordingly.
Regarding your second question, you can make the mask parameter non-tunable by setting its "Tunable" property to "false". To do this, follow these steps:
  1. Open the mask editor for the referenced model.
  2. Select the mask parameter in the mask editor.
  3. In the "Properties" pane of the mask editor, find the "Tunable" parameter and set it to "false".
  4. Save the model.
This should make the mask parameter non-tunable, so that its value cannot be changed during simulation.
I hope this helps! If you have any further questions, please don't hesitate to ask.

6 Comments

Ok, I think I've linked the parameter to the base HDL Counter.
In the mask editor, selecting the parameter gives me the property editor for that param as the right-most pane. There is an attribute "Tunable" present there, but it is set "on" and is not editable. How do I make this editable? There's no obvious way to do this.
Charles
This is actually quite a problem. I have just started making masks for subsystems and it seems most of the things I want to be configurable through a mask aren't allowed to be tunable. E.g., the RAM initial value for a Single Port RAM block. I haven't tried too many masks, but there doesn't appear to be a direct way to set the tunability on creation of the mask parameter.
BTW, I'm using R2023a.
Charles
If you want to make a parameter tunable through a mask in Simulink, you can try the following steps:
  1. Create a Simulink mask for the subsystem or block that you want to configure.
  2. Add a parameter to the mask by right-clicking on the mask and selecting "Add Parameter" from the context menu.
  3. In the "Parameter Properties" dialog box, set the "Data type" and "Value" fields as appropriate for your parameter.
  4. Check the "Tunable" checkbox to enable the parameter to be tuned during simulation.
  5. Click "OK" to save the parameter.
If you find that certain parameters are not tunable even after following these steps, it may be because they are not designed to be tunable by default. In that case, you can try the following workaround:
  1. Create a copy of the block that you want to configure and place it in your model.
  2. Double-click on the copied block to open its "Block Parameters" dialog box.
  3. Configure the parameters as desired.
  4. Right-click on the block and select "Create Mask" from the context menu to create a mask for the block.
  5. In the mask, add a parameter that corresponds to the parameter you configured in the "Block Parameters" dialog box.
  6. Check the "Tunable" checkbox to enable the parameter to be tuned during simulation.
  7. Save the mask.
With this workaround, you can expose the parameter you want to tune through the mask, even if it is not tunable by default. However, be aware that modifying the parameters of a block copy can affect the behavior of the original block, so use this method with caution.
I can't follow what you'r describing. It seems like we're talking about two different GUIs.
What do you mean "right-click on the mask"? Rtight-click on the mask editor window? Where? The only popup menu I get is from the middle pane, with Cut-Copy-Paste grayed out. The only way I can find to add parameters is through the Model Explorer.
I decided to follow the steps described in this link: https://www.mathworks.com/help/simulink/ug/create-and-reference-a-masked-model.html, literally creating the same model. I get to step 2 and have not even linked the mask params to the gain blocks and the two mask params show up with the Tunable attribute uneditable.
I apologize for the confusion. It seems like I may have misunderstood your original question.
Regarding your current question, it sounds like you are trying to create and use a masked model in Simulink. The obj.m_data.html code snippet you provided earlier does not seem to be relevant to this issue.
Regarding the issue with the mask parameters being uneditable, it is possible that the parameters have been marked as "locked" or "frozen". To check this, right-click on the parameter in the mask editor window and see if there is an option to unlock or unfreeze it. If not, you may need to modify the mask code to allow the parameters to be modified.
Please read my original first message in this thread and look at the two systems I posted to know what I'm asking. I have no idea what you're talking about with a "obj.m_data.html code snippet". It would be nice to have a knowledgable response to my original questions.
Here is a screen capture of the only Mask Editor window I know of. Right clicking on the parameter produces a "Cut-Copy-Paste" menu. Right clicking in the Property Editor does nothing.

Sign in to comment.

Products

Release

R2022b

Asked:

on 28 Mar 2023

Commented:

on 11 Apr 2023

Community Treasure Hunt

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

Start Hunting!