struct memeber can not be Simulink.Parameter?

12 visualizaciones (últimos 30 días)
dayu lai
dayu lai el 29 de Jul. de 2021
Respondida: Shivam Malviya el 13 de Sept. de 2024
hi,
I am using HDL Coder to generate RTL code from simulink.
While I want some signal internal a simulink to be tunable, which names 'bp' for example. So I wrote following code:
bp = Simulink.Parameter;
bp.Value = [0;0;0];
bp.CoderInfo.StorageClass = 'ExportedGlobal';
Then the bp signal will appeared as a input port in RTL.
However, if I wrote like this:
reg.bp = Simulink.Parameter;
reg.bp.Value = [0;0;0];
reg.bp.CoderInfo.StorageClass = 'ExportedGlobal';
While generate RTL, it comes out error:
Invalid setting in '<some_block>' for parameter 'Value'.
error using slhdlcoder.SimulinkConnection/initModel
Expression 'reg.bp' for block '<some_block>' returns a Simulink.Parameter object that has property values that need to be evaluated. This object should be instantiated in a workspace and referenced by name in Simulink
So it seems struct member can not be simulink parameter?
  1 comentario
Parker
Parker el 11 de Sept. de 2024
I hope the Mathworks team will revisit this question and give an explanation for why this is not allowed. I have run into the same thing, where our team would like to store our parameters in a structure and use them in constant and gain blocks in our model, but Mathworks appears to have disallowed this starting with MATLAB r14sp3, per this older question

Iniciar sesión para comentar.

Respuesta aceptada

Shivam Malviya
Shivam Malviya el 13 de Sept. de 2024
Hi,
It appears that during the RTL code generation for the attached model, you are encountering the mentioned error due to the use of a struct variable with a field that is a Simulink.Parameter. In your use case, struct variables are necessary to bundle all the global tunable parameters together.
The current initialization of the `reg` variable is causing Simulink model compilation failure, which leads to an error during RTL code generation. To resolve this issue, please follow these steps:
  • Instead of setting the field as a Simulink.Parameter, set the top-level struct as a Simulink.Parameter.
  • Ensure that the appropriate bus object is set for the struct object of type Simulink.Parameter.
Below is the updated demo_param.m script, which correctly initializes the reg variable:
% Initialize the required value
thr_val = [5;6;7];
reg_val = struct('thr', thr_val);
% Create appropriate bus object
Simulink.Bus.createObject(reg_val);
regType = slBus1;
clear slBus1
% Create the Simulink.Parameter object
reg = Simulink.Parameter(reg_val);
reg.DataType = 'Bus: regType';
reg.CoderInfo.StorageClass = 'ExportedGlobal';
% Set required variables
DT_cnt = fixdt(0,8,0);
ts = 0.1;
However, input ports won't get generated in the RTL code for this scenario involving struct as a Simulink.Parameter.
For more details, please refer to the following documentation pages:
Best Regards,
Shivam Malviya

Más respuestas (2)

Kiran Kintali
Kiran Kintali el 1 de Ag. de 2021
Can you share a sample model?
  2 comentarios
dayu lai
dayu lai el 5 de Ag. de 2021
Hi, I use the same demo in other question
The demo above can generate RTL successfully. However, if I change the parameter of constant before comparator into structure memeber. The compile of MDL is fail.
See the attached png for detail.
In reality, there will be a lot of tunable value in my design. I just want them to be members of structure, like reg.tunable_value0, reg.tunable_value1 and etc. Otherwise my workspace would be full filled with the global tunable value.
How I can do it?
Parker
Parker el 11 de Sept. de 2024
I would love for an explanation from Mathworks about why this method of storing parameters is not allowed by Simulink

Iniciar sesión para comentar.


Kiran Kintali
Kiran Kintali el 11 de Sept. de 2024

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by