With variable
as an input, the compiler can't assign a constant value to transitionConst
, as you've discovered.
You should declare your module like this, over rideand then override the OFFSET
parameter as a parameter to each invocation of the module. localparam
variables may not be overriden, but parameter
can be as shown. You can also supply a default value to the parameter, so you don't need to override it if it's not necessary. I chose variable
to be 32 bits wide, but that's arbitrary*.
module pole #(parameter OFFSET = 0) (input logic [31:0] variable);
localparam x = 1;
localparam y = 1;
localparam z = 1;
localparam transitionConst = x + y + z + OFFSET;
reg [31:0] transitionPoint = transitionConst + variable;
endmodule : pole
You can then invoke this in your top module like this:
module toplevel();
localparam offset0 = 0;
localparam offset120 = 120;
localparam offset240 = 240;
logic [31:0] variable;
pole mypole0(.variable(variable)); // no need to use offset0
pole #(.OFFSET(offset120)) mypole120(.variable(variable));
pole #(.OFFSET(offset240)) mypole240(.variable(variable));
endmodule : toplevel
*: As declared, the localparam
s will be 32 bits wide