Simulink HDL Coder error when generating
Afficher commentaires plus anciens
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 commentaires
Steven Hatcher
le 20 Fév 2025
Modifié(e) : Steven Hatcher
le 20 Fév 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
Réponses (1)
Kiran Kintali
le 20 Fév 2025
0 votes
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 commentaires
Steven Hatcher
le 20 Fév 2025
Thanks for sharing the model.
It appears to be a bug when using multiple elseif expressions. I was able to make the fix already.
But this will not generate very efficient code if all you are doing in the action subsystems is passing out a constant. There's better ways to create this mapping logic. You can easily use a MATLAB Function block to do this, which even allows the use of binary and hex literals.
function leds = fcn(count)
if count <= 500000
leds = 0b00000001;
elseif count <= 1000000
leds = 0b00000010;
elseif count <= 1500000
leds = 0b00000100;
elseif count <= 2000000
leds = 0b00001000;
elseif count <= 2500000
leds = 0b00010000;
elseif count <= 3000000
leds = 0b00100000;
elseif count <= 3500000
leds = 0b01000000;
elseif count <= 4000000
leds = 0b10000000;
else
leds = 0b00000000;
end
The generated VHDL code for this also looks similar to the style of logic you were looking for with if-elseif usage.
MATLAB_Function_1_output : PROCESS (count_unsigned)
BEGIN
IF count_unsigned <= to_unsigned(16#0007A120#, 32) THEN
leds_tmp <= to_unsigned(16#01#, 8);
ELSIF count_unsigned <= to_unsigned(16#000F4240#, 32) THEN
leds_tmp <= to_unsigned(16#02#, 8);
ELSIF count_unsigned <= to_unsigned(16#0016E360#, 32) THEN
leds_tmp <= to_unsigned(16#04#, 8);
ELSIF count_unsigned <= to_unsigned(16#001E8480#, 32) THEN
leds_tmp <= to_unsigned(16#08#, 8);
ELSIF count_unsigned <= to_unsigned(16#002625A0#, 32) THEN
leds_tmp <= to_unsigned(16#10#, 8);
ELSIF count_unsigned <= to_unsigned(16#002DC6C0#, 32) THEN
leds_tmp <= to_unsigned(16#20#, 8);
ELSIF count_unsigned <= to_unsigned(16#003567E0#, 32) THEN
leds_tmp <= to_unsigned(16#40#, 8);
ELSIF count_unsigned <= to_unsigned(16#003D0900#, 32) THEN
leds_tmp <= to_unsigned(16#80#, 8);
ELSE
leds_tmp <= to_unsigned(16#00#, 8);
END IF;
END PROCESS MATLAB_Function_1_output;
Steven Hatcher
le 20 Fév 2025
Here's the model I modified using the MATLAB Function block.
Mikel
le 21 Fév 2025
Kiran Kintali
le 21 Fév 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
le 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.
Catégories
En savoir plus sur Speed and Area Optimization dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!