verilog中的格式错误的陈述

时间:2014-02-14 04:51:16

标签: verilog system-verilog vlsi

您好我正在使用以下代码设计一个n位计数器。 根据开始和结束,我想实例化向上或向下计数器。

但我得到了#34;格式错误的声明"。请帮忙。

module nbitUpCounter(startc,endc , clk, rst_n,actlow,count);
parameter n = 7;

    output reg [n:0] count;
    input  [n:0] startc;
    input  [n:0] endc;
    input clk;
    input rst_n;
    input actlow;

    // Increment count on clock
    always @(actlow or posedge clk or negedge rst_n)
    begin
       if (actlow == 0)
       begin
           if (rst_n==0) 
          count = startc;
       else if (count==endc) count=startc;
           else count = count + 1;
       end
    end
endmodule

module nbitDownCounter(startc,endc , clk, rst_n,actlow,count);

parameter n = 7;

    output reg [n:0] count;
    input  [n:0] startc;
    input  [n:0] endc;
    input clk;
    input rst_n;
    input actlow;

    // Increment count on clock
    always @(actlow or posedge clk or negedge rst_n)
    begin
       if (actlow == 0)
       begin
           if (rst_n==0) 
          count = startc;
       else if (count==endc) count=startc;
           else count = count - 1;
       end
    end
endmodule

module Init(startc,endc , clk, rst_n,actlow,count);
parameter n = 7;

    output wire [n:0] count;
    input  [n:0] startc;
    input  [n:0] endc;
    input clk;
    input rst_n;
    input actlow;
generate
    initial
    begin
        if(startc>endc)
        nbitDownCounter c(startc, endc, C_t,rst_t,actlow,count);
    end
endgenerate
endmodule

module Testbench;

    reg [7:0] startc, endc;
    reg C_t, rst_t;
    reg actlow;
    wire [7:0] outc;

    initial
    begin

    //case 0
    startc <= 8'b00000011; endc <= 8'b0000001;
    //Init i(startc,endc,C_t,rst_t,actlow,count);
    actlow<=0;
    C_t <=1; rst_t <=0;
    #1 $display("count = %b",outc );
    //case1

    rst_t<=1;C_t<=0;C_t<=1;
    #1 $display("count = %b",outc );

    //Case3
    C_t<=0;C_t<=1;
    #1 $display("count = %b",outc );
    //Case3
    C_t<=0;C_t<=1;
    #1 $display("count = %b",outc );
    end
endmodule

1 个答案:

答案 0 :(得分:2)

您尝试在初始块中实例化您的模块,这是非法的。删除模块初始化初始化Init应解决问题。请查看此页面以获取示例:http://asic-soc.blogspot.de/2012/06/verilog-hdl-generate-blocks.html