Generate ST code from a look-up table with CONSTANT attribute
조회 수: 13 (최근 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!