MATLAB HDL-Coder: Expression could not be reduced to a constant.

I am trying to pass a struct hwconst into a MATLAB function.
function [out] = function_hdl(in, hwconst)
That function I want to translate into Verilog code using HDL-Coder. hwconst contains a field lfsrWidth. I am then using this field in the MATLAB function as follows:
WD_lfsr = coder.const(hwconst.lfsrWidth);
However, that line gives me an error during building: "Expression could not be reduced to a constant." I guess it's because lfsrWidth is not defined as a constant, see below. That's because the option for that is not there. How to use a structure with hardware constants properly with HDL Coder?

 채택된 답변

Kiran Kintali
Kiran Kintali 2025년 2월 10일

0 개 추천

Is hwconst an input variable (creates hardware interface pins) or just a non-tuanble constant parameter passed into the design from the testbench. If it is a constant parameter you need to right click in the GUI for hwconst and define it a constant value.
Here are some examples on how to do this via command line workflows.
This example shows how to pass / load constants
>> mlhdlc_demo_setup('comms_data_packet')

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Code Generation에 대해 자세히 알아보기

제품

릴리스

R2024b

질문:

2025년 2월 10일

답변:

2025년 2월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by