verilog代码中的语法错误

时间:2014-10-15 08:58:38

标签: verilog fpga system-verilog hdl

我想将此c代码转换为verilog模块,但我遇到了一些困难

void window_averaging(void) {

  register unsigned int i, k;
  for (i = 0; i < 128; i++) {
    // Copying first 128 output samples to the Window 0 and so on till Window 7.
    W[count][i] = O[i];
  }


  for (i = 0; i < 128; i++) {
    for (k = 0; k< 8; k++) {
      O[i] += W[k][i];
    }
    O[i] /= 8; // Averaging over 8 window
  } 
  count = (count++)%8; // Count = 0  after all the window elements are filled.
}

的Verilog:

module window_averaging(
  input      [16:0]in_noise, //input from noise cancellation
  input            clk,
  output reg [16:0]window_average // output after window averaging
  );

integer i;
integer k;
integer count = 0;
reg [16:0] store_elements[0:7][0:128]; //  2-D array for window averaging
reg [16:0] temp;

always @(posedge clk)
begin
  //  Copying first 128 output samples to the Window 0 and so on till Window 7
  for(i=0 ; i < 128 ; i = 1+1)
  begin
    store_elements[count][i] = in_noise;
  end
  for(i=0; i<128 ; i=i+1)
  begin
    for(k=0;k<8;k = k+1)
    begin
      temp = temp + store_elements[i][k];
    end
    window_average = temp/8;
    count = (count+1)%8;
  end
end
endmodule

我得到的错误是“(”和“=”附近的语法错误。我对verilog不熟悉,任何人都可以帮助我如何继续。

2 个答案:

答案 0 :(得分:1)

首先,您试图从@always块内部驱动电线,这是不允许的。如果您将电线转换为regs,那么它将起作用:

    module window_averaging(
    input [16:0]in_noise, //input from noise cancellation
    input clk,
    output reg [16:0]window_average // output after window averaging
    );

    integer i;
    integer k;
    integer count = 0;
    reg [16:0] store_elements[0:7][0:128]; //  2-D array for window averaging
    reg [16:0] temp;
    ...

另外我认为与你的C代码一致的是行数=(count + 1)%8;应该在for循环之外,如下所示:

    window_average = temp/8;
    end
    count = (count+1)%8;
    end
    endmodule

答案 1 :(得分:1)

我不知道你用什么来编译,但我认为以下内容会给你错误:
对于第一个循环:

for(i=0 ; i < 128 ; i = 1+1)

更改为i= i+1

另外,在行:

temp = temp + store_elements[i][k];

请记住声明store_elements[0:7][0:128],因此可能会切换ik



这不是一个真正的答案。对不起,我还没有评论权限。