Simulink HDL Coder error when generating

조회 수: 8 (최근 30일)
Mikel
Mikel 2025년 2월 20일
댓글: Steven Hatcher 2025년 3월 6일
HEllo,
It is my first time with Simulink's HDL Coder and I am trying to code a very simple program.
I have it ready, it simulates correctly but when I hit Generate HDL Code, it gives me this error:
Error:Error:signal:addDriver:invalidOutPortIndex: Error: Invalid output port index 3, hdl_test" RefNum="c31" UserName="If" RTTIClass ="class pir::NetworkInstComp" Network="n1"/> has 3 output port(s)
It is a simple counter that outputs 8 bits to toggle corresponding leds.
Can anyone give me some light on what can it be happening??
Thanks!!
  댓글 수: 2
Steven Hatcher
Steven Hatcher 2025년 2월 20일
편집: Steven Hatcher 2025년 2월 20일
Hi Mikel,
Which release are you using? It will be helpful to reach out to technical support to help get the issue sorted out.
Can I ask what you are trying to do with this If Action Subsystem structure? It almost looks like lookup table logic if those are constants inside. If so, you can get much more efficient HDL code using the nD Lookup Table block and also reduce modeling overhead with a single block.
Steven
Mikel
Mikel 2025년 2월 20일
편집: Mikel 2025년 2월 20일
I am using MAtlab R2023b
I am trying to implement a binary counter that, depending on the value of it, will turn on-off 8 leds.
the equivalent VHDL code would be:
MAIN: process(rst,clk)
begin
if (rst = '1') then
count <= (OTHERS => '0');
leds <= (OTHERS => '0');
elsif rising_edge(clk) then
count <= std_logic_vector(to_unsigned(to_integer(unsigned(count))+1,count'length));
if to_integer(unsigned(count)) <= 500000 then
leds <= std_logic_vector(to_unsigned(1,leds'length));
elsif to_integer(unsigned(count)) <= 1000000 then
leds <= std_logic_vector(to_unsigned(2,leds'length));
elsif to_integer(unsigned(count)) <= 1500000 then
leds <= std_logic_vector(to_unsigned(4,leds'length));
elsif to_integer(unsigned(count)) <= 2000000 then
leds <= std_logic_vector(to_unsigned(8,leds'length));
elsif to_integer(unsigned(count)) <= 2500000 then
leds <= std_logic_vector(to_unsigned(16,leds'length));
elsif to_integer(unsigned(count)) <= 3000000 then
leds <= std_logic_vector(to_unsigned(32,leds'length));
elsif to_integer(unsigned(count)) <= 3500000 then
leds <= std_logic_vector(to_unsigned(64,leds'length));
elsif to_integer(unsigned(count)) <= 4000000 then
leds <= std_logic_vector(to_unsigned(128,leds'length));
else
count <= (OTHERS => '0');
leds <= (OTHERS => '0');
end if;
end if;
end process MAIN;

댓글을 달려면 로그인하십시오.

답변 (1개)

Kiran Kintali
Kiran Kintali 2025년 2월 20일
This is an unexpected error handling the if/elseif control structure. Please reach to tech support or share your model here. We will provide a workaround and a patch as soon once we diagnose the issue.
  댓글 수: 6
Kiran Kintali
Kiran Kintali 2025년 2월 21일
We are addressing the issue with the if-elseif blocks and will release an update patch shortly. For control structures such as if/elseif and switch/case, we recommend using the MATLAB function block. This approach enhances model readability and clarifies control logic. Nonetheless, we also fully support the Simulink representations, as it explicitly illustrates both the data flow and control flow.
Please note that HDL Coder unifies all these modeling/representations internally prior to code generation and attempts to optimizes the logic across those constructs. Ideally users should use what works best for them in terms of representing math in MATLAB, Simulink, Stateflow and Simscape.
We will see what else can be done to improve the nD-lookup support. This page has some guidance on best practices using LUT blocks
https://www.mathworks.com/help/hdlcoder/ug/getting-started-with-ram-and-rom-in-simulink.html
Steven Hatcher
Steven Hatcher 2025년 3월 6일
We've published a bug report on this issue. You can track when the fix gets ported to updates for older releases with it.

댓글을 달려면 로그인하십시오.

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by