Getting error: localparam shift1 cannot be overwritten,however I declared as parameter in verilog

1.1k views Asked by At

I have the following LFSR written in verilog:

module LFSR #(parameter SIZE=1) /*Define a parameter for size of output*/
    ( 
        input clk,
        input reset,
        output [SIZE-1:0] q
    );

/*feedback taps for the LFSR*/
parameter shift1=1,shift2=2,shift3=2;

reg [15:0] shift; /*Shift register*/
wire xor_sum1,xor_sum2; /*feedback signals*/

/*Feedback logic*/
assign xor_sum1=shift[shift1] ^ shift[shift2];
assign xor_sum2=xor_sum1 ^ shift[shift3];

/*Shift the registers*/
always @ (posedge clk,posedge reset)
    if(reset)
        shift<=16'b1111111111111111;
    else
        shift<={xor_sum2,shift[15:1]};

/*Set the output*/
assign q=shift[SIZE-1:0];

endmodule

I try to instantiate it as follows:

/*Instantiate LFSR for the Random_X_Vel variable*/
    LFSR 
        #(.SIZE(2),
          .shift1(3),
          .shift2(9),
          .shift3(1))
    LFSR_Random_X_Vel
    (
        .clk(clk),
        .reset(reset),
        .q(Random_X_Vel)
    );

Not sure what I am doing wrong, It fails to compile in ISE14.7 and in Modelsim 10.2.

What is causing the issue and how can I fix it?

2

There are 2 answers

2
Morgan On BEST ANSWER

The LFSR only has 1 configurable parameter. module LFSR #(parameter SIZE=1). But you instance tries to set 4.

LFSR #(
  .SIZE(2),
  .shift1(3),
  .shift2(9),
  .shift3(1)
)

Moving the 'local' parameters into the port list will allow them to be set on the instance;

module LFSR #(
  parameter SIZE=1,
  parameter shift1=1,
  parameter shift2=2,
  parameter shift3=2
)
0
Qiu On

When you define your parameters as follow:

parameter shift1=1,shift2=2,shift3=2;

Modelsim allows you to modify this values with defparam keyword, i.e.:

defparam LFSR_Random_X_Vel.shift1 = 3;

If you want to be able to do in-line redefinition you should declare your parameters as follow:

module LFSR #(parameter SIZE=1,shift1=1,shift2=2,shift3=2)
( 
    input clk,
    input reset,
    output [SIZE-1:0] q
);

It looks like a Modelsim problem, because some other programs (e.g. Riviera) don't have any problems while compiling your code.