How do I convert between enumeration and integer types for use with HDL Coder?
35 次查看(过去 30 天)
显示 更早的评论
I am using enumerations in my model, and would like to generate HDL code. However, when I use a data type conversion block to convert between integer types and enumerations and try to generate HDL code, I get an error:
"Illegal conversion to/from an enumerated type in modelName/Data Type Conversion"
What is the recommended approach for converting between enums and integer types for HDL Coder?
采纳的回答
MathWorks Support Team
2020-5-7
Using data type conversion blocks to convert between enumeration and integer types is not currently support for HDL Coder.
As a workaround, you may use the following:
1) Enumeration to integer: Use a multiport switch or use a MATLAB Function block with a switch statement, as shown in the attached model
2) Integer to enumeration: Use a selector block or use a MATLAB Function block with a switch statement, as shown in the attached model.
Please note that there is not one accepted approach, and each approach will generate slightly different HDL code. Therefore, please choose the option that best suits your modeling needs in Simulink.
Finally, please note that enumerations have further limitations when used with HDL Coder, as described here:
0 个评论
更多回答(1 个)
Kiran Kintali
2021-7-9
Updated Answer (R2021a)
HDL Code Generation for Data Type Conversion block supports enumerated data types in R2021a release. See web(fullfile(docroot, 'hdlcoder/release-notes.html'))
You can now use enumerated signals at the ports of the Data Type Conversion block for HDL code generation. You can use the Data Type Conversion block to convert the enumeration data to integer or integer-to-enumeration data. Specify your enumerated data to your Data Type Conversion block.
See attached updated Example showing HDL friendly model.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 External Component Interfaces 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!