Generate ST code from a look-up table with CONSTANT attribute

6 ビュー (過去 30 日間)
Adrian
Adrian 2025 年 5 月 16 日
コメント済み: Desiree 2025 年 6 月 3 日
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.

採用された回答

Desiree
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?
  4 件のコメント
Adrian
Adrian 2025 年 6 月 2 日

Hi Desiree,

Yes, the process could be done manually, but I would rather have an automated solution. I did not come up with the idea of a post-processing via callback function as you suggested, so will definitely try that approach.

I tried defining the lookup table as a parameter with the "Const" storage class but it generates the table as a VAR_GLOBAL instead (without the CONSTANT attribute).

PS. I am using the Generic Target IDE PLC Coder.

Regards, Adrian

Desiree
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 ExchangeSimulink PLC Coder についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by