我得到一个错误说1)意外的genvar 2)undefined i

时间:2016-07-17 09:59:05

标签: verilog system-verilog

module clock
  (
 input logic wclk,rclk
 );
  initial begin
    wclk = 1'b0;
    rclk = 1'b0;
  end



task genclock;
begin
  genvar i;
    generate
      begin
    for(i=0;i<20;i++)
    begin
    #10
    wclk=~wclk;
    rclk=~rclk;
    #20
    rclk=~rclk;
    #20
    wclk=~wclk;
    #40
    wclk=~wclk;
    #40
    rclk=~rclk;
    #80
    wclk=~wclk;
    #100
    rclk=~rclk;
    #10
    wclk=~wclk;
    #2
    rclk=~rclk;
    #150
    wclk=~wclk;
    rclk=~rclk;
    #30
    wclk=~wclk;
    #44
    rclk=~rclk;
    end
    #100
    $finish;
    end
    endgenerate
    end
   endtask
   endmodule

1 个答案:

答案 0 :(得分:2)

Generate通常用于生成modulesfunctionstasks等多个实例。它用于重复顶级结构。

genvar通常用于generate块。对于您的情况,您真的不需要genvargenerate

您的小编辑示例:

module clock(wclk, rclk);

input reg wclk;
input reg rclk;

initial begin
  wclk = 1'b0;
  rclk = 1'b0;
  $finish;
end

task genclock;
    integer i;

    begin
    for(i=0;i<20;i=i+1) 
      #10
        wclk <= ~wclk;
        rclk <= ~rclk;
        #20
        rclk <= ~rclk;
        #20
        wclk <= ~wclk;
        #40
        wclk <= ~wclk;
        #40
        rclk <= ~rclk;
        #80
        wclk <= ~wclk;
        #100
        rclk <= ~rclk;
        #10
        wclk <= ~wclk;
        #2
        rclk <= ~rclk;
        #150
        wclk <= ~wclk;
        rclk <= ~rclk;
        #30
        wclk <= ~wclk;
        #44
        rclk <= ~rclk;
        #100;

    end

endtask
endmodule