列表

详情


VL50. 简易秒表

描述

请编写一个模块,实现简易秒表的功能:具有两个输出,当输出端口second1-60循环计数,每当second计数到60,输出端口minute加一,一直到minute=60,暂停计数。

模块的接口信号图如下:


       模块的时序图如下:

      

      

请使用Verilog HDL实现以上功能,并编写testbench验证模块的功能

输入描述

clk:系统时钟信号
rst_n:异步复位信号,低电平有效

输出描述

second:6比特位宽,秒表的秒读数
minute:6比特位宽,秒表的分读数

原站题解

Verilog 解法, 执行用时: 0ms, 内存消耗: 0KB, 提交时间: 2022-08-06

`timescale 1ns/1ns

module count_module(
	input clk,
	input rst_n,

    output reg [5:0]second,
    output reg [5:0]minute
	);
	
    
    reg            time_vaild    ;
    always@(posedge clk or negedge rst_n)
        begin
            if(rst_n==1'd0)
               second <= 6'd0                     ;
            else if((time_vaild == 1'd1)&&(second == 6'd60))
                second <= 6'd1                    ; 
            else if(time_vaild == 1'd1)
                 second <=   second + 1'd1        ;    
            else
                 second <=   second               ;    
        end     
	
    always@(posedge clk or negedge rst_n)
        begin
            if(rst_n==1'd0)
               minute <= 6'd0                     ;
           else if(second == 6'd60)
                minute <=   minute   +1'd1        ;    
            else 
                 minute <=   minute               ;      
        end   
    always@(posedge clk or negedge rst_n)
        begin
            if(rst_n==1'd0)
               time_vaild <= 1'd1                 ;
           else if(( minute == 6'd59)&&(second == 6'd60))
                time_vaild <= 1'd0                ;
            else 
                 time_vaild <=   time_vaild       ;      
        end   
    
	
endmodule

Verilog 解法, 执行用时: 0ms, 内存消耗: 0KB, 提交时间: 2022-08-06

`timescale 1ns/1ns

module count_module(
	input clk,
	input rst_n,

    output reg [5:0]second,
    output reg [5:0]minute
	);
	
    always@(posedge clk or negedge rst_n) begin
        if(!rst_n) begin
            second    <= 6'd0;
            minute    <= 6'd0;
        end
        else if(minute < 6'd60) begin
            if(second == 60) begin
                second    <= 6'd1;
                minute    <= minute + 1'b1;
            end
            else begin
                second    <= second + 1'b1;
                minute    <= minute;
            end
        end
        else if(minute == 6'd60) begin
                second    <= 6'd0;
                minute    <= minute;
        end
    end
    
    
	
endmodule

Verilog 解法, 执行用时: 0ms, 内存消耗: 0KB, 提交时间: 2022-08-06

`timescale 1ns/1ns

module count_module(
	input clk,
	input rst_n,

    output reg [5:0]second,
    output reg [5:0]minute
	);
    
    always @(posedge clk or negedge rst_n) begin
        if(!rst_n) begin
            second <= 6'd0;
            minute <= 6'd0;
        end
        else begin
            if(minute == 6'd60) begin
                second <= 6'd0;
                minute <= minute;
            end
            else begin
                if(second == 6'd60) begin
                    second <= 6'd1;
                    minute <= minute + 1'b1;
                end
                else begin
                    second <= second + 1'b1;
                end
            end
        end
    end
    
endmodule

Verilog 解法, 执行用时: 0ms, 内存消耗: 0KB, 提交时间: 2022-08-06

`timescale 1ns/1ns

module count_module(
	input clk,
	input rst_n,

    output reg [5:0]second,
    output reg [5:0]minute
	);    
always@(posedge clk or negedge rst_n)
   if(rst_n==0)
     second<=6'd0;
   else if(minute==60)
     second<=6'd0;
   else if(second==60)
     second<=1;
   else 
     second<=second+1;

always@(posedge clk or negedge rst_n)
   if(rst_n==0)
     minute<=6'd0;
   else if(minute==60)
     minute<=minute;
   else if(second==60)
     minute<=minute+1;




	
endmodule

Verilog 解法, 执行用时: 0ms, 内存消耗: 0KB, 提交时间: 2022-08-06

`timescale 1ns/1ns

module count_module(
	input clk,
	input rst_n,

    output reg [5:0]second,
    output reg [5:0]minute
	);
    always@(posedge clk or negedge rst_n)
        if(!rst_n)
            second<=0;
    else if(second==60)
        second<=1;
    else if(minute==60)
        second<=0;
    else second<=second+1;
   always@(posedge clk or negedge rst_n)
       if(!rst_n)
           minute<=0;
    else if(second==60)
        minute<=minute+1;
    else minute<=minute;
endmodule

上一题