0

I would like to parameterize localparam parameters.

My module definition:

module native  #(
  parameter SIM_ONLY = 0,
  parameter FREQ = 500
)(
  ...
);

I have lots of instantiations using the same localparam parameter A.

if (FREQ == 550) begin
  localparam A = 987;
end else begin
  localparam A = 122;
end

AA #(
   .A_VALUE  (A),
) AA_inst (
 ...
);

But that isn't allowed in the specification, is there a different proper way to do it?

/!\ The A value is a magic number, not something that can be calculated from FREQ.

I've tried:

if (FREQ == 550) begin
  shortreal A = 987;
end else begin
  shortreal A = 122;
end

but I get The expression for a parameter actual associated with the parameter name... must be constant.

Alexis
  • 2,136
  • 2
  • 19
  • 47

1 Answers1

3

Use the conditional operator ?:

localparam A = (FREQ==550) 987 : 122;

You can also put more complicated expressions into a constant function

localparam A = some_function(FREQ);

function int some_function(int F);
   case(F)
     550: return 987;
     123: return 456;
     default: return 122;
   endcase
endfunction
dave_59
  • 39,096
  • 3
  • 24
  • 63