Simulink HDL Coder error when generating
5 views (last 30 days)
Show older comments
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 Comments
Steven Hatcher
on 20 Feb 2025
Edited: Steven Hatcher
on 20 Feb 2025
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
Answers (1)
Kiran Kintali
on 20 Feb 2025
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 Comments
Kiran Kintali
on 21 Feb 2025
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
on 6 Mar 2025
We've published a bug report on this issue. You can track when the fix gets ported to updates for older releases with it.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!