数字钟VHDL 数字电路课程设计.docx
- 文档编号:24360879
- 上传时间:2023-05-26
- 格式:DOCX
- 页数:29
- 大小:101.29KB
数字钟VHDL 数字电路课程设计.docx
《数字钟VHDL 数字电路课程设计.docx》由会员分享,可在线阅读,更多相关《数字钟VHDL 数字电路课程设计.docx(29页珍藏版)》请在冰豆网上搜索。
数字钟VHDL数字电路课程设计
数字电路与自动化课程设计报告
设计题目:
数字电子钟
姓名:
林立萍陈平英
班级:
10级应电2班
学号:
10060102251006010213
小组成员:
林立萍0225陈平英0213
设计时间:
2011年12月15日~2011年12月30日
目录
一.设计目的
二.设计要求
三.设计方案
四.设计原理
五.设计过程
六.调试过程中的问题和解决方法
七.设计小结
八.VHDL程序
九.EDA实物图片
十.参考书目
一、设计目的
1.熟练地运用数字系统的设计方法进行数字系统的设计;
2.掌握运用数字钟的VHDL语言设计方法;
3.熟悉编程的过程;
4.理解运用分频、计时、多路选择器等课本理论;
5.进一步的学习电路的调试;
二、设计要求
1、显示
(1)小时——分钟——秒钟
(2)小时、分钟和秒钟各用两个数码管来显示
(3)小时、分钟、秒钟之间用一杠来显示
(4)杠每秒闪烁一次
2、时钟
(1)一个时钟
3、整点报时(当整点的时候,LED闪烁)
4、校准
(1)能够实现对小时、分钟、秒钟的调整
(2)按键去抖动
三、设计方案:
1、采用一个时钟信号,即扫描时钟,而秒时钟通过扫描时钟分频得到的。
2、利用嵌套的模式,在秒时钟的情况下且无模式选择时,让秒分时自动跳时。
3、使用防抖动的原理,减少按键产生的干扰。
4、当按键an1有效时,运用多路选择器,依次实现校时、校分和校秒多种模式的选择,在校准模式的时候,让数码管闪烁,杠不闪烁。
当按键an2有效时,当模式选择在校时或校分或校秒时,其数码管显示的值累加;
当按键an3有效时,当模式选择在校时或校分或校秒时,其数码管显示的值递减。
5、在整点时,运用流水灯进行整点报时显示。
6、用阴极数码管来译码显示时分秒的数值。
四、设计原理
1、定义模块
1、动态扫描模块
2、分频模块
3、去抖动模块
4、模式选择模块
5、(显示+闪烁)模块
6、跳时模块
7、校时模块(加法模块和减法模块)
8、整点报时模块(LED灯移位显示模块)
9、译码模块
五、设计过程
1、定义模块
(1)、定义实体:
对输入信号(扫描时钟sec_clk,按键(an1,an2,an3))、输出信号(动态扫描seg,LED输出temp,七段数码管data)进行声明
(2)、定义结构体:
对中间信号进行声明。
1、动态扫描模块
在扫描时钟为上升沿的时候,进行计数,再将中间信号赋值给输出seg,达到轮流显示,由于扫描时钟的频率大于人的视觉惰性20ms,所以我们看过去,八个数码管能够全部同时看到数字,。
process(sec_clk)--动态扫描
begin
ifrising_edge(sec_clk)then
cnt<=cnt+1;
endif;
endprocess;
seg<=cnt;
2、分频模块
在扫描时钟为上升沿的时候,进行计数,然后对扫描时钟进行1024分频,将其值赋给秒时钟clk,对扫描时钟进行64分频,将其值赋给秒时钟clk1。
process(sec_clk,n)--分频
begin
ifrising_edge(sec_clk)then
n<=n+1;
endif;
clk<=n(9);
clk1<=n(6);
endprocess;
3、去抖动模块
由于按键输入时会有抖动干扰,对输出会产生误差,因此对按键进行去抖动,当扫描时钟为上升沿的时候,采用对按键进行移位延迟输出,即当按键输出满足四个高电平时,才使得按键输出有效,从而达到去抖动的效果。
process(clk1)--去抖动
begin
ifrising_edge(clk1)then
An_out(3downto0)<=An_out(2downto0)&an1;
Bn_out(3downto0)<=Bn_out(2downto0)&an2;
Cn_out(3downto0)<=Cn_out(2downto0)&an3;
ifAn_out="1111"then
an1_out<='1';
else
an1_out<='0';
endif;
ifBn_out="1111"then
an2_out<='1';
else
an2_out<='0';
endif;
ifCn_out="1111"then
an3_out<='1';
else
an3_out<='0';
endif;
endif;
endprocess;
4、模式选择模块
在按键an1有效输出的情况下,对tz进行计数,选择时分秒的模块。
process(an1_out)--模式的选择
begin
ifan1_out='1'then
tz<=tz+1;
endif;
endprocess;
5、(显示+闪烁)模块
利用嵌套的模式,利用计数扫描显示,使按键an1所选择的模块闪烁,否则正常显示。
当按键an1有效时,杠正常显示,否则进行闪烁。
process(cnt,round,tz,clk)--扫描
begin
casecntis
when"000"=>iftz="01"then
ifclk='1'then--秒的个位的闪烁
dec<=round(3downto0);
else
dec<="1110";
endif;
else
dec<=round(3downto0);--秒个位的正常显示
endif;
when"001"=>iftz="01"then
ifclk='1'then--秒的十位的闪烁
dec<='0'&round(6downto4);
else
dec<="1110";
endif;
else
dec<='0'&round(6downto4);--秒十位的正常显示
endif;
when"011"=>iftz="10"then
ifclk='1'then--分的个位的闪烁
dec<=round(10downto7);
else
dec<="1110";
endif;
else
dec<=round(10downto7);--分个位的正常显示
endif;
when"100"=>iftz="10"then
ifclk='1'then--分的十位的闪烁
dec<='0'&round(13downto11);
else
dec<="1110";
endif;
else
dec<='0'&round(13downto11);--分十位的正常显示
endif;
when"110"=>iftz="11"then
ifclk='1'then--时的个位的闪烁
dec<=round(17downto14);
else
dec<="1110";
endif;
else
dec<=round(17downto14);--时个位的正常显示
endif;
when"111"=>iftz="11"then
ifclk='1'then--时的十位的闪烁
dec<='0'&'0'&round(19downto18);
else
dec<="1110";
endif;
else
dec<='0'&'0'&round(19downto18);--时十位的正常显示
endif;
when"010"|"101"=>iftz="01"ortz="10"ortz="11"then
dec<="1010";
else
dec<=round(23downto20);--横的显示
endif;
whenothers=>dec<="1011";--不显示
endcase;
endprocess;
process(tz,clk)--横的闪烁
begin
iftz="00"then
ifclk='1'then
round(23downto20)<="1010";
else
round(23downto20)<="1011";
endif;
else
round(23downto20)<="1010";
endif;
endprocess;
6、跳时模块
当时钟为上升沿且无进行模式调整,分别判断秒分时的个十位数值大小,若满足条件,则进行跳时,否则清零。
process(clk)--跳时
begin
ifrising_edge(clk)then
iftz="00"then--无进行模式调整
ifround(19downto18)>1andround(17downto14)>3then
round(19downto0)<="00000000000000000000";--清零
else
ifround(3downto0)<9then
round(3downto0)<=round(3downto0)+1;--秒个位的跳时
else
round(3downto0)<="0000";--清零
ifround(6downto4)<5then
round(6downto4)<=round(6downto4)+1;--秒十位的跳时
else
round(6downto4)<="000";--清零
ifround(10downto7)<9then
round(10downto7)<=round(10downto7)+1;--分个位的跳时
else
round(10downto7)<="0000";--清零
ifround(13downto11)<5then
round(13downto11)<=round(13downto11)+1;--分十位的跳时
else
round(13downto11)<="000";--清零
ifround(17downto14)<9then
round(17downto14)<=round(17downto14)+1;--时个位的跳时
else
round(17downto14)<="0000";--清零
ifround(19downto18)<3then
round(19downto18)<=round(19downto18)+1;--时十位的跳时
else
round(19downto18)<="00";--清零
endif;
endif;
endif;
endif;
endif;
endif;
endif;
7、校时模块
当按键an1有效时,当模式选择分别在秒、分、时块,分别进行加法计数和减法计数。
elsiftz="01"then--校秒
ifan2_out='1'andan3_out='0'then
ifround(3downto0)<9then
round(3downto0)<=round(3downto0)+1;
else
round(3downto0)<="0000";
ifround(6downto4)<5then
round(6downto4)<=round(6downto4)+1;
else
round(6downto4)<="000";
endif;
endif;
elsifan2_out='0'andan3_out='1'then
ifround(3downto0)>0then
round(3downto0)<=round(3downto0)-1;
else
round(3downto0)<="1001";
ifround(6downto4)>0then
round(6downto4)<=round(6downto4)-1;
else
round(6downto4)<="101";
endif;
endif;
endif;
elsiftz="10"then--校分
ifan2_out='1'andan3_out='0'then
ifround(10downto7)<9then
round(10downto7)<=round(10downto7)+1;
else
round(10downto7)<="0000";
ifround(13downto11)<5then
round(13downto11)<=round(13downto11)+1;
else
round(13downto11)<="000";
endif;
endif;
endif;
ifan2_out='0'andan3_out='1'then
ifround(10downto7)>0then
round(10downto7)<=round(10downto7)-1;
else
round(10downto7)<="1001";
ifround(13downto11)>0then
round(13downto11)<=round(13downto11)-1;
else
round(13downto11)<="101";
endif;
endif;
endif;
elsiftz="11"then--校时
ifan2_out='1'andan3_out='0'then
ifround(19downto18)>1andround(17downto14)>3then
round(19downto18)<="00";
else
ifround(17downto14)<9then
round(17downto14)<=round(17downto14)+1;
else
round(17downto14)<="0000";
ifround(19downto18)<3then
round(19downto18)<=round(19downto18)+1;
else
round(19downto18)<="00";
endif;
endif;
endif;
elsifan2_out='0'andan3_out='1'then
ifround(19downto18)=0andround(17downto14)=0then
round(19downto18)<="10";
round(17downto14)<="0011";
else
ifround(17downto14)>0then
round(17downto14)<=round(17downto14)-1;
else
round(17downto14)<="1001";
ifround(19downto18)>0then
round(19downto18)<=round(19downto18)-1;
else
round(19downto18)<="10";
endif;
endif;
endif;
endif;
endif;
endif;
endprocess;
8、整点报时模块(LED灯移位显示模块)
当整点时,即分模块为零,dbs为高电平,则LED灯进行移位显示,否则不显示。
process(round)--整点报时
begin
ifround(10downto7)=0andround(13downto11)=0then
dbs<='1';
else
dbs<='0';
endif;
endprocess;
process(dbs)--流水灯
begin
ifdbs='1'andrising_edge(clk)then
ifdtemp<="00000000"then
dtemp<='1'&dtemp(7downto1);
elsifdtemp<="00000001"then
dtemp<=(others=>'0');
else
dtemp<='0'&dtemp(7downto1);
endif;
endif;
endprocess;
temp<=dtemp;
9、译码模块
在数码管中锁存的BCD码转换成七段码用于LED灯的显示。
process(dec)--译码
begin
casedecis
when"0000"=>data<="0111111";
when"0001"=>data<="0000110";
when"0010"=>data<="1011011";
when"0011"=>data<="1001111";
when"0100"=>data<="1100110";
when"0101"=>data<="1101101";
when"0110"=>data<="1111101";
when"0111"=>data<="0000111";
when"1000"=>data<="1111111";
when"1001"=>data<="1101111";
when"1010"=>data<="1000000";
when"1011"=>data<="0000000";
whenothers=>data<="0000000";
endcase;
endprocess;
6、调试过程中的问题和解决方法:
我们先做分频模块,对程序进行综合时,发现时钟定义出错,分频概念不懂得运用,通过查资料,问老师和同学,最终实现了分频模块功能。
接下来再做扫描模块,综合完之后,发现数码管不能显示,经过查看程序之后,发现没有扫描计数进行赋值输出。
在设计按键去抖动模块时,发现按键an3没有作用,之后对按键an3赋予一个LED灯输出,发现按键an3高电平时,LED灯没有输出,检查程序,发现按键之间的嵌套出错,修改程序之后,可以实现按键an3的输出,最终达到去抖动功能。
由于跳时、校时和模式选择我们选择嵌套模式,在嵌套过程中混乱,其中不能进行跳时,还有模式选择不起作用,并且所选择的模块无法进行闪烁,做完加法模块之后,我们考虑再做减法模块。
在做减法计数时,数值为零时,不能正确赋值,检查程序后,一步一步进行改错、综合、调试,实现跳时,校时的功能。
在做整点报时模块时,本想让流水灯在整点时进行移位闪烁,由于条件判断错误,使得流水灯只有在十秒时才移一个灯,通过咨询同学我们的问题,修改程序之后,达到预想的结果。
七、设计小结
通过这次的课程设计使我对数电软件知识有了更深的了解,从一开始只懂得对老师所给的程序进行编程,再到自己逐渐了解程序、编写程序、调试修改程序,逐步懂得程序综合完后所提示的错误,并且能够根据所提示的错误,进行针对性的修改。
在课程设计中,我们更深一步的认识到了quartusII的用法,更加了解如何调试程序,检查程序中存在的问题,如何解决问题。
也知道了理论和实践相结合,学与致用。
八、VHDL程序
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityllois
port(sec_clk:
instd_logic;--扫描时钟
an1、an2、an3:
instd_logic;--按键
seg:
outstd_logic_vector(2downto0);--动态扫描输出
temp:
outstd_logic_vector(7downto0);--LED灯
data:
outstd_logic_vector(6downto0));--七段数码管
end;
architectureoneofllois
signalround:
std_logic_vector(23downto0);--秒分时的显示
signalcnt:
std_logic_vector(2downto0);
signaltz:
std_logic_vector(1downto0);--多路选择器
signaldec:
std_logic_vector(3downto0);--选择
signalAn_out:
std_logic_vector(3downto0);
signalBn_out:
std_logic_vector(3downto0);
signalCn_out:
std_logic_vector(3downto0);
signaldtemp:
std_logic_vector(7downto0);--彩灯
signalan1_out:
std_logic;
signalan2_out:
std_logic;
signalan3_out:
std_logic;
signaln:
std_logic_vector(9downto0);
signalclk:
std_logic;--秒时钟
signalclk1:
std_logic;--秒时钟
signaldbs:
std_logic;--报时的显示
begin
process(sec_clk)--扫描
begin
ifrising_edge(sec_clk)then
cnt<=cnt+1;
endif;
endprocess;
seg<=cnt;
process(sec_clk,n)--分频
begin
ifrising_edge(sec_clk)then
n<=n+1;
endif;
clk<=n(9);
clk1<=n(6);
endprocess;
process(clk1)--去抖动
begin
ifrising_edge(clk1)then
An_out(3downto0)<
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数字钟VHDL 数字电路课程设计 数字 VHDL 数字电路 课程设计