Mask parameter value is ignored with HDL Counter word length
조회 수: 7 (최근 30일)
이전 댓글 표시
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
채택된 답변
Andy Bartlett
2023년 4월 11일
편집: Andy Bartlett
2023년 4월 11일
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개)
Jack
2023년 3월 30일
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:
- Open the mask editor for the referenced model.
- Click on the "View/Edit Model Parameters" button to open the "Model Explorer" window.
- In the "Model Explorer" window, locate the HDL Counter block and select it.
- In the "Properties" pane of the "Model Explorer" window, find the "Word length" parameter and click on the "..." button next to it.
- In the "Parameter Properties" window, set the "Data type" to "Inherit: auto".
- In the "Parameter Properties" window, set the "Value" to counter_word_length.
- 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:
- Open the mask editor for the referenced model.
- Select the mask parameter in the mask editor.
- In the "Properties" pane of the mask editor, find the "Tunable" parameter and set it to "false".
- 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
Jack
2023년 4월 2일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Author Block Masks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!