Professional Documents
Culture Documents
课程名称 实验日期 成绩
同组实验者
实验项目名称 数字逻辑实验 3
1. 实验目的
1. 1. 掌握基于 SystemVerilog HDL 的时序逻辑电路建模方法;
2. 掌握计数器设计方法,并能够使用计数器设计使能时钟(用于时钟分频);
3. 掌握移位寄存器设计方法,并能够利用移位寄存器设计边沿检测电路;
4. 掌握 7 段数码管的动态显示。 1. 首先实现边沿检测电路,命名为 chk_asc 模块。阅读实验指导书可知,i_start 可
看作一个按钮,每按一次改变一次当前电路的状态。所以 chk_asc 模块中需要使
用到 2 位移位寄存器,来存储两个状态,可看作现态和次态。
代码:
module chk_asc(
input sys_clk,
2. 实验内容 input sys_rst_n,
input cin,
基于 SystemVerilog HDL 设计并实现一个分秒数字钟。整个工程的顶层模块 如图 3-6 所示,输入/输出 output logic cout
端口如表 3-1 所示。使用 4 个七段数码管显示当前的 计时。其中,两个数码管对应“分”,另两个数码 );
管对应“秒”。通过 1 个拨动开关 对数字钟进行复位控制。使用 1 个按键对数字中进行“暂停/计时”
控制,按键每按 下一次,进行暂停和计时的切换,即暂停时,按下按键启动计时;计时过程中, 按下按 logic [1:0]temp=0;
键暂停计时 logic en=0;
always_ff @(posedge sys_clk) begin
if(sys_rst_n==1) begin
temp={cin,temp[1]};
if(temp[1]==1&&temp[0]==0) en=~en;
end
else begin
temp=0;
en=0;
end
end
assign cout=(en==1?1:0);
endmodule
2.然后实现使能时钟生成器,命名为 en_clock 模块。其中时钟周期为 40ns,而七段数码管动态扫描周期为
代码:
3.之后实现计时电路,命名为 cnt_clock 模块。分秒时钟每加 1 秒需要经过 2 千 500
`timescale 1ns / 1ps 万 40ns 的时钟周期。与使能时钟生成器类似,可以使用计数器实现此功能
代码:
module en_clock( `timescale 1ns / 1ps
input sys_clk,
input sys_rst_n, module cnt_clock(
output logic [3:0]cout input sys_clk,
); input sys_rst_n,
input en,
integer r_cnt=0; output logic [7:0]min,
always_ff @(posedge sys_clk) begin output logic [7:0]sec
if(sys_rst_n==1) begin );
if(r_cnt==24999) begin
if(cout==4'b0000) cout=4'b0001; integer cnt=0;
else if(cout==4'b0001) cout=4'b0010; integer CNT=0;
else if(cout==4'b0010) cout=4'b0100; always_ff @(posedge sys_clk) begin
else if(cout==4'b0100) cout=4'b1000; if(sys_rst_n==1) begin
else if(cout==4'b1000) cout=4'b0001; if(en==1) begin
r_cnt=0; if(cnt==24999) begin
end cnt=0;
else begin CNT=CNT+1;
r_cnt=r_cnt+1; if(CNT==999) begin
end CNT=0;
end sec=sec+1;
else begin if(sec==60) begin
r_cnt=0; min=min+1;
cout=4'b0; sec=0;
end end
end end
end
endmodule else begin
cnt=cnt+1;
end
end
end
else begin
cnt=0;
CNT=0;
3. 还需要写一个 BCD 码转换为七段数码管信号的模块,命名为 BCD_2_7Dig 模块。
min=0;
sec=0;
使用 case 语句即可完成
end
end
代码:
`timescale 1ns / 1ps endmodule
第二个用来将时钟频率分频为 1Hz,实现计时功能,每秒+1
教师签字:
年 月 日