简体   繁体   English

错误:localparam shift1无法覆盖,但是我在verilog中声明为参数

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

I have the following LFSR written in verilog: 我有以下用Verilog编写的LFSR:

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. 不知道我在做什么错,它无法在ISE14.7和Modelsim 10.2中编译。

What is causing the issue and how can I fix it? 是什么原因导致该问题,我该如何解决?

When you define your parameters as follow: 当您按如下方式定义参数时:

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

Modelsim allows you to modify this values with defparam keyword, ie: Modelsim允许您使用defparam关键字修改此值,即:

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 (eg Riviera) don't have any problems while compiling your code. 它看起来像是Modelsim问题,因为其他一些程序(例如Riviera)在编译代码时没有任何问题。

The LFSR only has 1 configurable parameter. LFSR只有1个可配置参数。 module LFSR #(parameter SIZE=1) . module LFSR #(parameter SIZE=1) But you instance tries to set 4. 但是您的实例尝试设置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
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM