FPGA项目设计:数字时钟

这篇具有很好参考价值的文章主要介绍了FPGA项目设计:数字时钟。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

项目要求:
设计一个数字时钟,数码管前两位显示小时,数码管中间两位显示分钟,数码管后面两位显示秒。

项目设计:
系统框架图:
FPGA项目设计:数字时钟,fpga开发
计数模块时序图:
FPGA项目设计:数字时钟,fpga开发
代码实现:
计数模块:

/*
 * @Description: 用于记数产生时钟
 * @Author: Fu Yu
 * @Date: 2023-08-02 11:16:46
 * @LastEditTime: 2023-08-02 15:23:14
 * @LastEditors: Fu Yu
 */

module counter (
    input       wire            clk         ,
    input       wire            rst_n       ,

    output      wire [23:0]     clock_data      //输出时钟数值
);

parameter   MAX_1S    = 26'd49_999_999;//1s
parameter   MAX_S     = 6'd59;//1S*60 = 1min
parameter   MAX_MIN   = 6'd59;//1min*60 = 1h
parameter   MAX_H     = 5'd23;//1h*24 = 1d

localparam  INIT_S = 40,//赋初值
            INIT_M = 58,
            INIT_H = 23;

reg [25:0]  cnt_1s;
reg [5:0]   cnt_s;
reg [5:0]   cnt_min;
reg [4:0]   cnt_h;

reg [3:0]   time_s_low;
reg [3:0]   time_s_high;
reg [3:0]   time_min_low;
reg [3:0]   time_min_high;
reg [3:0]   time_h_low;
reg [3:0]   time_h_high;

wire add_cnt_1s;
wire end_cnt_1s;

wire add_cnt_s;
wire end_cnt_s;

wire add_cnt_min;
wire end_cnt_min;

wire add_cnt_h;
wire end_cnt_h;

//****************************************************************
//--1s计数器
//****************************************************************
always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        cnt_1s <= 26'd0;
    end
    else if(add_cnt_1s) begin
        if(end_cnt_1s) begin
            cnt_1s <= 26'd0;
        end
        else begin
            cnt_1s <= cnt_1s + 1'd1;
        end
    end
    else begin
        cnt_1s <= cnt_1s;
    end
end

assign add_cnt_1s = 1'b1;
assign end_cnt_1s = add_cnt_1s && cnt_1s == MAX_1S;

//****************************************************************
//--秒计数器
//****************************************************************
always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        cnt_s <= INIT_S;
    end
    else if(add_cnt_s) begin
        if(end_cnt_s) begin
            cnt_s <= 6'd0;
        end
        else begin
            cnt_s <= cnt_s + 1'd1;
        end
    end
    else begin
        cnt_s <= cnt_s;
    end
end

assign add_cnt_s = end_cnt_1s;
assign end_cnt_s = add_cnt_s && cnt_s == MAX_S;

//****************************************************************
//--分钟计数器
//****************************************************************
always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        cnt_min <= INIT_M;
    end
    else if(add_cnt_min) begin
        if(end_cnt_min) begin
            cnt_min <= 6'd0;
        end
        else begin
            cnt_min <= cnt_min + 1'd1;
        end
    end
    else begin
        cnt_min <= cnt_min;
    end
end

assign add_cnt_min = end_cnt_s;
assign end_cnt_min = add_cnt_min && cnt_min == MAX_MIN;

//****************************************************************
//--小时计数器
//****************************************************************
always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        cnt_h <= INIT_H;
    end
    else if(add_cnt_h) begin
        if(end_cnt_h) begin
            cnt_h <= 5'd0;
        end
        else begin
            cnt_h <= cnt_h + 1'd1;
        end
    end
    else begin
        cnt_h <= cnt_h;
    end
end

assign add_cnt_h = end_cnt_min;
assign end_cnt_h = add_cnt_h && cnt_h == MAX_H;

//****************************************************************
//--clock_data
//****************************************************************
always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        time_s_high <= 4'd0;
        time_s_low <= 4'd0;
        time_min_high <= 4'd0;
        time_min_low <= 4'b0;
        time_h_high <= 4'd0;
        time_h_low <= 4'd0;
    end
    else begin
        time_h_high <= cnt_h/10;
        time_h_low <= cnt_h%10;
        time_min_high <= cnt_min/10;
        time_min_low <= cnt_min%10;
        time_s_high <= cnt_s/10;
        time_s_low <= cnt_s%10;
    end
end

assign clock_data = {time_h_high,time_h_low,time_min_high,time_min_low,time_s_high,time_s_low};

endmodule //counter

数码管显示模块:

/*
 * @Description: 数码管显示模块,前两位显示时钟数据的小时,中间两位显示时间数据的分钟,最后两位显示时间数据的秒
 * @Author: Fu Yu
 * @Date: 2023-08-02 13:43:47
 * @LastEditTime: 2023-08-02 14:00:00
 * @LastEditors: Fu Yu
 */


module seg_driver (
    input       wire            clk             ,
    input       wire            rst_n           ,
    input       wire [23:0]     clock_data_in   ,

    output      wire [5:0]      sel             ,//位选信号
    output      wire [7:0]      dig                 //段选信号
);

parameter MAX_1MS = 16'd49_999;//1ms

parameter   ZERO  = 7'b100_0000,
            ONE   = 7'b111_1001,
            TWO   = 7'b010_0100,
            THREE = 7'b011_0000,
            FOUR  = 7'b001_1001,
            FIVE  = 7'b001_0010,
            SIX   = 7'b000_0010,
            SEVEN = 7'b111_1000,
            EIGHT = 7'b000_0000,
            NINE  = 7'b001_0000;

reg [5:0] sel_r;
reg [7:0] dig_r;
reg [5:0] point_n;//小数点
reg point_n_r;
reg [3:0]   disp_data   ;//每一位数码管显示的数值

reg [15:0]  cnt_1ms;
wire add_cnt_1ms;
wire end_cnt_1ms;

//****************************************************************
//--1ms计数器
//****************************************************************
always @(posedge clk or negedge rst_n)begin 
   if(!rst_n)begin
        cnt_1ms <= 16'd0;
    end 
    else if(add_cnt_1ms)begin 
        if(end_cnt_1ms)begin 
            cnt_1ms <= 16'd0;
        end
        else begin 
            cnt_1ms <= cnt_1ms + 1'b1;
        end 
    end
end 

assign add_cnt_1ms = 1'b1;
assign end_cnt_1ms = add_cnt_1ms && cnt_1ms == MAX_1MS;

//****************************************************************
//--point_n
//****************************************************************
always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        point_n <= 6'b111_111;
    end
    else begin
        point_n <= 6'b110101;
    end
end

//****************************************************************
//--sel
//****************************************************************
always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        sel_r <= 6'b111110;
    end
    else if(end_cnt_1ms) begin
        sel_r <= {sel_r[4:0],sel_r[5]};
    end
    else begin
        sel_r <= sel_r;
    end
end

assign sel = sel_r;

//****************************************************************
//-- disp_data   
//****************************************************************
always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        disp_data <= 4'd0;
        point_n_r <= 1'b1;
    end
    else begin
        case (sel_r)
            6'b111110 : begin
                disp_data <= clock_data_in[23:20];
                point_n_r <= point_n[0];
            end
            
            6'b111101 : begin
                disp_data <= clock_data_in[19:16];
                point_n_r <= point_n[1];
            end

            6'b111011 : begin
                disp_data <= clock_data_in[15:12];
                point_n_r <= point_n[2];
            end

            6'b110111 : begin
                disp_data <= clock_data_in[11:8];
                point_n_r <= point_n[3];
            end

             6'b101111 : begin
                disp_data <= clock_data_in[7:4];
                point_n_r <= point_n[4];
            end

            6'b011111 : begin
                disp_data <= clock_data_in[3:0];
                point_n_r <= point_n[5];
            end
        endcase
    end
end

//****************************************************************
//--dig
//****************************************************************
always @(*)begin 
        case (disp_data)
            0 :  dig_r <= {point_n_r,ZERO  };
            1 :  dig_r <= {point_n_r,ONE   };
            2 :  dig_r <= {point_n_r,TWO   };
            3 :  dig_r <= {point_n_r,THREE };
            4 :  dig_r <= {point_n_r,FOUR  };
            5 :  dig_r <= {point_n_r,FIVE  };
            6 :  dig_r <= {point_n_r,SIX   };
            7 :  dig_r <= {point_n_r,SEVEN };
            8 :  dig_r <= {point_n_r,EIGHT };
            9 :  dig_r <= {point_n_r,NINE  };
           
            default: dig_r <= 8'hff;
        endcase
    end

assign dig = dig_r;

endmodule //seg_driver

顶层文件:文章来源地址https://www.toymoban.com/news/detail-629373.html

module top (
    input           wire        clk     ,
    input           wire        rst_n   ,

    output          wire [5:0]  sel     ,
    output          wire [7:0]  dig         
);

wire [23:0] data;

counter u_counter(
    .     clk        (clk) ,
    .     rst_n      (rst_n) ,

    .     clock_data    (data)
);


seg_driver u_seg_driver (
    .     clk            (clk) ,
    .     rst_n          (rst_n) ,
    .     clock_data_in  (data),

    .     sel            (sel) ,
    .     dig              (dig)
);

endmodule //top

到了这里,关于FPGA项目设计:数字时钟的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • FPGA课程设计——数字电子时钟VERILOG(基于正点原子新起点开发板,支持8位或6位共阳极数码管显示时分秒毫秒,可校时,可设闹钟,闹钟开关,led指示)

    2019   级    电子科学与技术   专业FPGA课程设计 报   告 2022  年 5 月 20 日 多功能数字电子钟的设计 摘要 电子设计自动化(EDA)是一种实现电子系统或电子产品自动化设计的技术,使用EDA技术设计的结果既可以用FPGA / CPLD来实施验证,也可以直接做成专用集成电路(ASIC)。

    2024年02月03日
    浏览(35)
  • FPGA小脚丫开发板实现数字时钟,具备调时、整点报时、闹钟功能(含verilog代码)

    一、实现功能 1. 能正常完成时钟的时、分、秒走时; 2. 使用 LED 闪烁或者改变颜色等方式实现秒的指示,要求闪烁频率或者颜色切换频率为 1Hz ; 3. 使用两位七段数码管显示时和分,其切换方式为:默认显示“分钟”,按住 K4 键显示“小时”,按下 K3 显示秒针; 4. 关上开关

    2024年02月11日
    浏览(43)
  • FPGA多功能数字时钟 基于Quartus实现设计与仿真 华南师范大学数电综设

    专业: 通信工程 学号:__ 姓名: 龚易乾___指导老师: 电子与信息工程学院 2023年2月 有任何疑问可以联系邮箱:codealan@qq.com 项目仓库地址:https://github.com/CodeAlanqian/e-clock github仓库地址 熟练掌握Quartus等EDA设计与仿真工具,掌握多路选择器、N进制计数器、显示译码电路、开关

    2024年02月12日
    浏览(32)
  • 基于FPGA的电子时钟设计与实现 (在EDA开发板上实现电子时钟功能)

    开发板: 此款开发板使用的是 ALTERA 公司的 Cyclone IV 系列 FPGA,型号为 EP4CE6F17C8, 256 个引脚的 FBGA 封装。  题目:在EDA开发板上实现电子时钟功能 要求:实现电子时钟程序编写,实现在7段数码管显示时、分、秒,使用4x4矩阵按键模拟调节时钟指令输入按键,并实现整点报时

    2024年02月04日
    浏览(31)
  • 【FPGA & Modsim】数字时钟

    实验题目:    数字时钟设计                                   实验目的:    掌握数字时钟的工作原理;掌握使用数字逻辑设计集成开发环境分模块设计数字时钟的方法。                           实验内容: 1、创建一个数字时钟工程,使用

    2024年01月18日
    浏览(27)
  • 基于FPGA的数字时钟(使用vivado)

    使用两个四位数码管,可以实现时钟分钟秒钟显示,高两位设置不显示。 换了一个新开发板,nexys4ddr,资料不多,最多使用的就是一本英文Reference Manual。 其实是老师觉得我计数器还差点,得再练练。 Digilent NEXYS4DDR Vivado2018.3 60进制秒钟计数然后进1分钟 60进制分钟计数然后进

    2024年02月03日
    浏览(32)
  • FPGA数字时钟(可暂停调数,含代码)

    前段时间刚刚开始初步学习FPGA相关知识,在学习了一段时间后,利用前面所学知识,写了一个数字时钟,顺便在这里写下总结,方便理解。 (本人小白一名,有错欢迎指出,欢迎探讨) 我使用的FPGA芯片型号是Cyclone IV的EP4CE6F17C8,如有想测试实现效果的同学,可以把后面3-

    2024年02月02日
    浏览(33)
  • FPGA实验报告 Verilog HDL:7人表决器 巴克码信号发生器 FPGA数字时钟

    写在前面:本文提供以下三个任务的思路讲解和代码实现, 如需参考引脚配置说明,可以点击下方链接跳转查看完整实验报告 ;本实验使用的是Altera公司的cycloneⅢ类型的芯片。 Verilog HDL实现:7人表决器 信号发生器 多功能数字时钟 实验目标:实现7人投票表决电路,支持人

    2024年02月05日
    浏览(37)
  • Verilog语言fpga小脚丫数字时钟(整点报时,调时,显示秒钟等功能)

    学弟加油!                                                                       ———来自科大焯人 最近刚好学习了数电有关知识,就做了这个项目(闹钟过于繁琐就没有做了) 希望给还在学习的大伙一点参考,完整代码在最后 在这里先附上两串代码分别是d

    2024年02月07日
    浏览(37)
  • 时钟信号设计基础——FPGA

    目录/ contents ● 时钟信号设计概述 ● 时钟信号属性特征 ● 常见时钟信号概念 ● 时钟信号设计要点 01——时钟信号设计概述 时钟信号作为数字电路系统的“心脏”,始终伴随着数字电路信号的变化,在数字电路设计中具有重要意义。数字电路通常被划分为组合逻辑与时序逻

    2024年02月04日
    浏览(25)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包