Verilog 升降计数器代码

Verilog 升降计数器代码,verilog,Verilog,我需要在我的项目,这是一个计数器,从0到20计数或下降的帮助。我已经做了我的计数器代码,它在活动HDL中工作。但是现在我需要在nexys3FPGA板中以7段显示数字 我有段的代码,但是当我调用段的模块时,我遇到了一个问题-它在活动HDL中给了我一个错误。你能告诉我错误是什么吗 这是我当前的代码: module main #(parameter N=7) ( input switch, input button, input fastclk, out

我需要在我的项目,这是一个计数器,从0到20计数或下降的帮助。我已经做了我的计数器代码,它在活动HDL中工作。但是现在我需要在
nexys3
FPGA板中以7段显示数字

我有段的代码,但是当我调用段的模块时,我遇到了一个问题-它在活动HDL中给了我一个错误。你能告诉我错误是什么吗

这是我当前的代码:

module main
    #(parameter N=7)
    (
    input switch,
    input button,
    input fastclk,
    output [3:0] enable,
    output reg[6:0] out
    );    
    wire[N:0]count;
    wire slowclk;

    clock c1(fastclk,slowclk);
    Updown u1(switch,button,slowclk,count);
    segment s1([3:0]count,[7:4]count,fastclk,enable,out); 
    endmodule


module clock(fastclk,slowclk); //clock code
    input fastclk;
    output wire slowclk;
    reg[25:0]period_count = 0;

    always @(posedge fastclk)
        begin
            period_count <= period_count + 1;
        end
    assign slowclk = period_count[25];
endmodule

module Updown // UpDown Counter
#(parameter N=7)    
    (
    input switch,
    input button,
    input clk,
    output reg [N:0]count=8'd0,
    );  


always @(posedge clk)
    begin

        if(switch == 1 && button == 1)  // Countup from 0 to 20
            begin 
                if(count == 8'd20)
                    count <= 0 ;

                else 
                    count <= count +1;

            end
        else if(switch == 0 && button == 1) // Countdown from 20 to 0
        begin 
                if(count == 8'd0)
                    count <= 8'd20 ;

                else 
                    count <= count -1;

            end 
        else count <=8'd0;  
    end
endmodule

module mux(A,B,sel,Y); // 2x1 Multiplexer
    input [3:0]A;
    input [3:0]B;
    input sel;
    output [3:0]Y;
    reg [3:0]Y;

    always @(*)
        begin 
            if(sel==0)
                Y=A;
            else 
                Y=B;

            end
endmodule

module hex7seg(input wire [3:0]x , output reg[6:0]a_to_g); // Hex to 7seg Code

    always @(*)

        case(x)
            0: a_to_g = 7'b0000001; 
            1: a_to_g = 7'b1001111;
            2: a_to_g = 7'b0010010;
            3: a_to_g = 7'b0000110;
            4: a_to_g = 7'b1001100;
            5: a_to_g = 7'b0100100;
            6: a_to_g = 7'b0100000;
            7: a_to_g = 7'b0001111;
            8: a_to_g = 7'b0000000;
            9: a_to_g = 7'b0000100;
            'hA: a_to_g = 7'b0001000;
            'hB: a_to_g = 7'b1100000;
            'hC: a_to_g = 7'b0110001;
            'hD: a_to_g = 7'b1000010;
            'hE: a_to_g = 7'b0110000;
            'hF: a_to_g = 7'b0111000;
            default: a_to_g = 7'b0000001;
        endcase
endmodule

module segment (a,b,fast,enable,seg7);
    input [3:0]a;
    input [3:0]b;
    input fast;
    output [3:0] enable;
    output [6:0] seg7;
    wire [3:0]e1 = 4'b1110;
    wire [3:0]e2 = 4'b1101;
    wire slow;
    wire [3:0]number;

    clock c1(fast,slow);
    mux m1(a,b,slow,number);
    mux m2(e1,e2,slow,enable);
    hex7seg h1(number,seg7);

endmodule
主模块
#(参数N=7)
(
输入开关,
输入按钮,
输入fastclk,
输出[3:0]启用,
输出寄存器[6:0]输出
);    
导线[N:0]计数;
钢丝慢行;
时钟c1(快时钟、慢时钟);
上下u1(开关、按钮、慢行、计数);
段s1([3:0]计数,[7:4]计数,快速时钟,启用,输出);
端模
模块时钟(快时钟、慢时钟)//时钟代码
输入fastclk;
输出线慢行;
reg[25:0]周期计数=0;
始终@(posedge fastclk)
开始

周期计数您在代码的
模块初始化部分有一个小错误:

segment s1([3:0]count,[7:4]count,fastclk,enable,out); 
这部分代码看起来应该有点不同:

segment s1(count[3:0],count[7:4],fastclk,enable,out); 
  • 大问题是:

    segment s1([3:0]count,[7:4]count,fastclk,enable,out);
    
    应该是:

    segment s1(count[3:0],count[7:4],fastclk,enable,out);
    
    其他选项(IEEE标准1364-2001按名称自动连接(
    *
    ):

  • 一些模拟器可能会抱怨输出上的初始值带有ANSI样式的端口列表或端口列表中的尾随逗号。因此:

    output reg [N:0]count=8'd0,
    );
    
    应该是:

    output reg [N:0] count
    );
    initial count=8'd0;
    
    我更喜欢在我的设计中控制重置,因此我更喜欢:

    input reset_n,
    output reg [N:0] count
    );
    always @(posedge clk
      // or negedge reset_n // <-- uncomment for asynchronous reset
      ) begin
      if (!reset_n) begin
        count=8'd0;
      end
      else begin
        // synchronous code here
      end
    end
    
    输入重置\u n,
    输出寄存器[N:0]计数
    );
    始终@(posedge clk
    //或负边缘重置\u n//
    
    input reset_n,
    output reg [N:0] count
    );
    always @(posedge clk
      // or negedge reset_n // <-- uncomment for asynchronous reset
      ) begin
      if (!reset_n) begin
        count=8'd0;
      end
      else begin
        // synchronous code here
      end
    end