1

I'm trying to instantiate multiple copies of a module using a generate. However, these multiple copies have a different output type (depending on a parameter). Is there a way to conditionally connect an output port. eg:

module #(parameter type OUT_TYPE = logic[31:0]) myModule (
   input ....
   output OUT_TYPE mod_out
);

Calling module , note that out_a, out_b, out_c are different types

generate for (genvar g=0; g<4; g++) begin
    localparam type g_TYPE = g==0 ? logic[31:0] : (g==1 ? logic[15:0] : logic[7:0]);
    myModule #(.OUT_TYPE(g_TYPE)) inst_myModule (
      .
      .
      if (g==0)
         .mod_out(out_a)
      else if (g==1)
         .mod_out (out_b)
      else
         .mod_out (out_c)
    );
end endgenerate
0

1 Answer 1

2

No, you cannot do it this way. However, generate blocks allow you to fully instantiate the module:

for (genvar g=0; g<4; g++) begin: loopblk
   if (g == 0) begin
       typedef logic[31:0] g_TYPE;
       myModule#(.OUT_TYPE(g_TYPE)) inst_myModule(.mod_out(out_a));
   end
   else if (g == 1) begin
      myModule #(.OUT_TYPE(logic[15:0])) inst_myModule(.mod_out(out_b));
   end
   else 
      ...
end

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.