Generate ST code from a look-up table with CONSTANT attribute
6 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I am using the 'Direct Lookup Table (n-D)' block in Simulink to load a matrix and extract the values given a row and a column number as inputs.
The Simulink setup is shown in the attached figure "lookup-table.png".
With this setup a PLC function block in structured text is generated from MATLAB/Simulink and everything is working as expected. However, the look-up table is defined within the function block as "VAR". I would like, if possible, to define it as "VAR_CONSTANT" instead. I have tried setting the in the lookup table attribute "StorageClass" type to "Const" but that has not worked.
Any idea/suggestion on how to store this table as "VAR_CONSTANT"?
Thanks in advance.
0 件のコメント
採用された回答
Desiree
2025 年 5 月 22 日
Hello Adrian,
Simulink PLC Coder does support CONSTANT attribute only in the context of VAR_GLOBAL, not as VAR_CONSTANT.
You can try postprocessing to change VAR to VAR_CONSTANT, but the question would be what is the exact requirement to have CONSTANT attribute for this VAR? Can you clarify?
Postprocessing can be achieved over a callback, see https://www.mathworks.com/help/plccoder/ug/generate-custom-code-by-using-ide-specific-callback-functions.html
4 件のコメント
Desiree
2025 年 6 月 3 日
Hi Adrian,
we do not support VAR_GLOBAL CONSTANT for the generic targets "Generic" and "PLCopen XML". However you can activate it by adding path to the custom generic target:
addpath([matlabroot '\toolbox\plccoder\plugins\generic'])
savepath
plccoderpref('plctargetidepaths','default')
Then restart the MATLAB session.
Which IDE are you generating code for though? It might make more sense to directly generate for this IDE if it is supported. If not you could try following this workflow to adapt the code to you target IDE:
Hope this helps.
Best regards,
Desiree
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Simulink PLC Coder についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!