1. 课程信息 实验地点:清水河校区KB239
**实验时间:**2021.04.9
实验时长: 3小时(4节课)
2. 实验要求 驱动板上数码管显示当前时间(包含时、分、秒)
①建议定义n个按键,如用于功能切换 (tab)、校时+1(up)及确认(ok)
②整点报时: 7:00~23:00间每个整点蜂鸣器响1s
思考(加分项):
1. 如何添加闹钟功能?
2. 如何添加定时器功能?
3. 设计模N计数器的测试向量集,撰写testbench进行验证测试
3. 设计与实现 3.1 电路功能说明 (包括各个模块功能、关键代码分析,可以使用文字、框图、功能表、状态图等进行说明)
3.1.1 顶层设计 3.1.2 timing_module 接收PLL多次分频得到的1Hz时钟信号作为模块的时钟信号,设置17位数据用来存储当前时间([5:0]表示秒,[11:6]表示分,[16:12]表示小时),当秒达到59时,则下一次操作为秒位置0,同时分位加1,分钟与小时的关系依次类推。同时当load信号使能时,即设置时间功能打开时,数据位数据将被加载进来的数据覆盖。
// timing_module.v `timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: UESTC // Engineer: Qy_Ley // // Create Date: 2021/03/14 15:06:37 // Design Name: Digital Clock for EES331 // Module Name: timing_module // Project Name: Digital Clock // Target Devices: EES331 // Tool Versions: Vivado 18.3 // Description: // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: // ////////////////////////////////////////////////////////////////////////////////// module timing_module( input i_clk_1Hz, input i_load, input i_rstn, input i_ena, input [16:0] i_load_hms, // [5:0] for sec, [11:6] for min, [16:12] for hour, BCD coding output [16:0] o_hms // [5:0] for sec, [11:6] for min, [16:12] for hour, BCD coding ); // wire m_co_sec, m_co_min; // Carry output from second & minute counter reg ld; reg [16:0] ld_cnt; reg [4:0] hour_cnt; reg [5:0] min_cnt,sec_cnt; always @(posedge i_clk_1Hz) begin ld <= i_load; ld_cnt <= i_load_hms; end //clock cross-domain buffer always @(posedge i_clk_1Hz or negedge i_rstn) begin if(!i_rstn) begin hour_cnt <= 0; min_cnt <= 0; sec_cnt <= 0; end else if(ld) begin {hour_cnt, min_cnt, sec_cnt} <= ld_cnt; end else if(i_ena) begin if(sec_cnt == 6'd59) begin sec_cnt <= 0; if(min_cnt == 6'd59) begin min_cnt <= 0; if(hour_cnt == 5'd23) begin hour_cnt <= 0; end else begin hour_cnt <= hour_cnt+1; end end else begin min_cnt <= min_cnt+1; end end else begin sec_cnt <= sec_cnt+1; end end end /* Complete the counter for second, minute, hour */ assign o_hms = {hour_cnt, min_cnt, sec_cnt}; endmodule 3.1.3 control_module 为系统控制的模块,采用有限状态机的描述方式,如图:
...