Skip to main content
Added some claricification.
Source Link
awjlogan
  • 8k
  • 2
  • 31
  • 48

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 localparams will be 32 bits wide

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 ride 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.

module pole #(parameter OFFSET = 0) (input variable);
    localparam x = 1;
    localparam y = 1;
    localparam z = 1;

    localparam transitionConst = x + y + z + OFFSET;
    reg 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 variable;

    pole mypole0(variable);  // no need to use offset0
    pole #(.OFFSET(offset120)) mypole120(variable);
    pole #(.OFFSET(offset240)) mypole240(variable);
endmodule : toplevel

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, and 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 localparams will be 32 bits wide

Added example invocation.
Source Link
awjlogan
  • 8k
  • 2
  • 31
  • 48

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, to pass OFFSETover ride the OFFSET parameter as a constant 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.

module pole #(parameter OFFSET = 0) (input variable);
    localparam x = 1;
    localparam y = 1;
    localparam z = 1;

    localparam transitionConst = x + y + z + OFFSET;
    reg 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 variable;

    pole mypole0(variable);  // no need to use offset0
    pole #(.OFFSET(offset120)) mypole120(variable);
    pole #(.OFFSET(offset240)) mypole240(variable);
endmodule : toplevel

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, to pass OFFSET as a constant parameter to each invocation of the module.

module pole #(parameter OFFSET = 0) (input variable);
    localparam x = 1;
    localparam y = 1;
    localparam z = 1;

    localparam transitionConst = x + y + z + OFFSET;
    reg transitionPoint = transitionConst + variable;
endmodule : pole

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 ride 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.

module pole #(parameter OFFSET = 0) (input variable);
    localparam x = 1;
    localparam y = 1;
    localparam z = 1;

    localparam transitionConst = x + y + z + OFFSET;
    reg 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 variable;

    pole mypole0(variable);  // no need to use offset0
    pole #(.OFFSET(offset120)) mypole120(variable);
    pole #(.OFFSET(offset240)) mypole240(variable);
endmodule : toplevel
Source Link
awjlogan
  • 8k
  • 2
  • 31
  • 48

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, to pass OFFSET as a constant parameter to each invocation of the module.

module pole #(parameter OFFSET = 0) (input variable);
    localparam x = 1;
    localparam y = 1;
    localparam z = 1;

    localparam transitionConst = x + y + z + OFFSET;
    reg transitionPoint = transitionConst + variable;
endmodule : pole