数字钟实验报告.docx
《数字钟实验报告.docx》由会员分享,可在线阅读,更多相关《数字钟实验报告.docx(20页珍藏版)》请在冰豆网上搜索。
数字钟实验报告
EDA数字钟设计
项目名称:
VHDL数字钟
适用年级:
2
所属课程:
《可编程数字系统》
姓名:
****
学号:
***********
班级:
***********
指导老师:
***
《可编程数字系统》课程设计题目
一、课程设计目的:
熟悉EDA工具;掌握用VHDL语言进行数字系统设计的基本方法和流程。
二、设计任务:
任选以下两道题目中的一道,用VHDL语言描述,用QuartusII工具编译和综合,仿真,并在实验板上实现,同时提交实验报告。
设计一数字钟,用数码管显示
基本功能要求:
(1)可以分屏显示时、分、秒,可用数码管的小数点“.”代替时、分、秒的分隔符“:
”,分屏显示是指由于数码管只有4个,不能同时显示时、分、秒,但可以只显示时、分,或只显示分、秒,通过按键来切换这两种显示方式。
(2)可设置时钟的开始时间。
设置时,相应的数码管要闪烁,指示当前设置的位置(内容)。
(3)具有闹铃功能,可以设定闹铃时间。
闹铃时间到,LED闪烁进行指示
三、设计与实验报告要求
1、项目必须在一周内独立完成,发现抄袭者,一律不及格;
2、以上题目的要求为必须完成的基本功能,在此基本功能的基础上,鼓励学生增加更多功能(可加分);
3、提交的实验报告必须包含但不限于以下基本内容:
设计原理、系统分析、程序设计、仿真结果、实验结果(可附上实验板运行时的照片)、结论或分析
4、验收方式:
实物验收,需演示,并答辩。
5、评分标准:
以完成上述的基本功能为基准,第一道题目的基准分为75,第二道题目的基准分为85分,根据完成设计的具体情况以及设计报告的质量,综合得分上下浮动。
6、实验套件要妥善使用和保管,如有损坏或丢失,按情节轻重处理。
一、设计原理
EP2C5T144C8有50MHZ的时钟频率输出,通过分频计数器,接入数字钟。
数字钟由计数器、译码器、显示器等部分构成,数字钟的时、分、秒实际上就是由一个24进制计数器(00-23),两个60进制计数器(00-59)级联构成。
显示模块用200HZ的频率,显示效果很好。
利用QuartusII9.0软件编写VHDL语言,编写六十进制、二十四进制;译码、显示部分用一个四进制,二-四译码器,数据选择器及七段译码器构成。
最后生成相对应的模块连接成数字钟电路图。
数字钟的功能实际上是对秒信号计数。
EDA-V硬件开发系统可提供不同的时钟信号,分频后可产生秒时钟。
数字钟在结构上可分为两个部分:
计数器和显示器。
计数器又可分为秒计数器、分计数器和小时计数器;秒计数器和分计数器由两个六十进制构成,小时计数器由二十四进制计数器实现。
动态显示电路可用三态门构成的四选一数据选择器,和一个四进制加一个二四译码器,还有一个七段译码器7448组成。
三态门在选择了一个数码管的同时,打开一个三态门,其他的关闭。
进而实现数据选择。
如图1所示的用三态门实现动态显示的框图。
在QuartusII软件中实现四个数码管的动态显示原理
二、程序设计
计数部分
(1)VHDL语言设计的秒和分,带整点报时和分的设置
--Second1(秒计数6进制和10进制)
Libraryieee;
Useieee.std_logic_1164.all;
Useieee.std_logic_unsigned.all;
Entitysecond1is
Port(clks,clr:
instd_logic;
Secs,Secg:
outstd_logic_vector(3downto0);
cout1:
outstd_logic);
Endsecond1;
Architectureaofsecond1is
Begin
Process(clks,clr)
variabless,sg:
std_logic_vector(3downto0);
variableco:
std_logic;
Begin
Ifclr='0'thenss:
="0000";sg:
="0000";
Elsifclks'eventandclks='1'then
ifss="0101"andsg="1001"thenss:
="0000";sg:
="0000";co:
='1';
elsifsg<"1001"thensg:
=sg+1;co:
='0';
elsifsg="1001"thensg:
="0000";ss:
=ss+1;co:
='0';
endif;
endif;
cout1<=co;
Secs<=ss;
Secg<=sg;
endprocess;
Enda;
--Min1(分计数器6进制和10进制alm实现整点报时)
Libraryieee;
Useieee.std_logic_1164.all;
Useieee.std_logic_unsigned.all;
Entitymin1is
Port(clkm,clr:
instd_logic;
mins,ming:
bufferstd_logic_vector(3downto0);
enmin,alarm:
outstd_logic);
End;
Architectureaofmin1is
Begin
Process(clkm,clr)
variablems,mg:
std_logic_vector(3downto0);
variableso,alm:
std_logic;
Begin
Ifclr='0'thenms:
="0000";mg:
="0000";
Elsifclkm'eventandclkm='1'then
ifms="0101"andmg="1001"thenms:
="0000";mg:
="0000";so:
='1';alm:
='1';
elsifmg<"1001"thenmg:
=mg+1;so:
='0';alm:
='0';
elsifmg="1001"thenmg:
="0000";ms:
=ms+1;so:
='0';alm:
='0';
endif;
endif;
alarm<=alm;
enmin<=so;
mins<=ms;
ming<=mg;
Endprocess;
Enda;
(2)VHDL语言设计的二十四进制电路
--Hour1(时计数器4进制与2进制)
Libraryieee;
Useieee.std_logic_1164.all;
Useieee.std_logic_unsigned.all;
Entityhour1is
Port(clkh,clr:
instd_logic;
hours,hourg:
outstd_logic_vector(3downto0));
End;
Architectureaofhour1is
Begin
Process(clkh,clr)
variablehs,hg:
std_logic_vector(3downto0);
Begin
Ifclr='0'thenhs:
="0000";hg:
="0000";
Elsifclkh'eventandclkh='1'then
ifhs="0010"andhg="0011"thenhs:
="0000";hg:
="0000";
elsifhg<"1001"thenhg:
=hg+1;
elsifhg="1001"thenhg:
="0000";hs:
=hs+1;endif;
endif;
hours<=hs;
hourg<=hg;
Endprocess;
End;
模块动态显示部分
(1)VHDL语言设计的四进制电路,模块
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitytime4_oldis
port(
clk:
instd_logic;
q:
bufferstd_logic_vector(1downto0)
);
endtime4_old;
architecturexxoftime4_oldis
begin
process(clk)
begin
if(clk'eventandclk='1')then
ifq<"11"then
q<=q+1;
else
q<="00";
endif;
else
q<=q;
endif;
endprocess;
endxx;
(2)VHDL语言设计的2线-4线译码器
entitycase24is
port(
sel:
inbit_vector(1downto0);
y:
outbit_vector(3downto0)
);
endcase24;
architecturexxofcase24is
begin
process(sel)
begin
caseselis
when"00"=>y<="1110";
when"01"=>y<="1101";
when"10"=>y<="1011";
whenothers=>y<="0111";
endcase;
endprocess;
endxx;
(3)VHDL语言设计的数据选择器模块
entitymux4vis
port(
a,b,c,d:
inbit_vector(3downto0);
sel:
inbit_vector(1downto0);
result:
outbit_vector(3downto0)
);
endmux4v;
architectureaaofmux4vis
begin
withselselect
result<=awhen"11",
bwhen"10",
cwhen"01",
dwhenothers;
endaa;
(4)VHDL语言七段译码器设计模块
entitym7448is
port(
result:
inbit_vector(3downto0);
seg:
outbit_vector(6downto0)
);
endm7448;
architecturexxofm7448is
begin
process(result)
begin
caseresultis
when"0000"=>seg<="0000001";
when"0001"=>seg<="1001111";
when"0010"=>seg<="0010010";
when"0011"=>seg<="0000110";
when"0100"=>seg<="1001100";
when"0101"=>seg<="0100100";
when"0110"=>seg<="0100000";
when"0111"=>seg<="0001111";
when"1000"=>seg<="0000000";
whenothers=>seg<="0000100";
endcase;
endprocess;
endxx;
(5)6选4数据选择器和切换显示按键模块
Libraryieee;
Useieee.std_logic_1164.all;
Useieee.std_logic_unsigned.all;
entitytry_new_64is
port(
secs,secg,mins,ming,hours,hourg:
inbit_vector(3downto0);
key_sel:
inbit;
loc1,loc2,loc3,loc4:
outbit_vector(3downto0)
);
endtry_new_64;
Architectureaoftry_new_64is
signalkey_sel_con:
integerrange0to1;
Begin
key_sel_con_proc:
process(key_sel)
begin
ifkey_sel'eventandkey_sel='0'then
ifkey_sel_con=1then
key_sel_con<=0;
else
key_sel_con<=key_sel_con+1;
endif;
endif;
endprocess;
Process(key_sel_con)
Begin
casekey_sel_conis
when0=>
loc1<=mins;
loc2<=ming;
loc3<=secs;
loc4<=secg;
when1=>
loc1<=hours;
loc2<=hourg;
loc3<=mins;
loc4<=ming;
endcase;
endprocess;
enda;
因为板上资源有限,用4个数码管显示时钟,下面是切换显示的程序
Libraryieee;
Useieee.std_logic_1164.all;
Useieee.std_logic_unsigned.all;
entitytry_new_64is
port(
secs,secg,mins,ming,hours,hourg:
inbit_vector(3downto0);
key_sel:
inbit;
loc1,loc2,loc3,loc4:
outbit_vector(3downto0)
);
endtry_new_64;
Architectureaoftry_new_64is
signalkey_sel_con:
integerrange0to1;
Begin
key_sel_con_proc:
process(key_sel)
begin
ifkey_sel'eventandkey_sel='0'then
ifkey_sel_con=1then
key_sel_con<=0;
else
key_sel_con<=key_sel_con+1;
endif;
endif;
endprocess;
Process(key_sel_con)
Begin
casekey_sel_conis
when0=>
loc1<=mins;
loc2<=ming;
loc3<=secs;
loc4<=secg;
when1=>
loc1<=hours;
loc2<=hourg;
loc3<=mins;
loc4<=ming;
endcase;
endprocess;
enda;
小数点被我分开显示了。
只要第二个亮输出1011即可。
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitygivesigis
port(
sel:
inbit_vector(1downto0);
y:
outbit
);
endgivesig;
architecturexxofgivesigis
begin
process(sel)
begin
if(sel="10")then
y<='0';
else
y<='1';
endif;
endprocess;
endxx;
打包了时钟的程序如下
--Topclock(元件例化顶层文件)
Libraryieee;
Useieee.std_logic_1164.all;
Useieee.std_logic_arith.all;
Useieee.std_logic_unsigned.all;
Entitytopclockis
Port(clk,clr,en,m1,h1:
instd_logic;
alarm:
outstd_logic;
secs,secg,mins,ming,hours,hourg:
bufferstd_logic_vector(3downto0));
End;
Architectureoneoftopclockis
Componentsecond1
Port(clks,clr:
instd_logic;
secs,secg:
bufferstd_logic_vector(3downto0);
cout1:
outstd_logic);
EndComponent;
Componentmin1
Port(clkm,clr:
instd_logic;
mins,ming:
bufferstd_logic_vector(3downto0);
enmin,alarm:
outstd_logic);
EndComponent;
Componenthour1
Port(clkh,clr:
instd_logic;
hours,hourg:
bufferstd_logic_vector(3downto0));
EndComponent;
Componentmadapt
Port(en,m1,clk,secin:
instd_logic;
minset:
outstd_logic);
EndComponent;
Componenthadapt
Port(en,h1,clk,minin:
instd_logic;
hourset:
outstd_logic);
EndComponent;
signala,b,c,d:
std_logic;
begin
u1:
second1portmap(clr=>clr,
secs=>secs,secg=>secg,clks=>clk,cout1=>a);
u2:
min1portmap(clr=>clr,alarm=>alarm,
mins=>mins,ming=>ming,clkm=>b,enmin=>c);
u3:
hour1portmap(clr=>clr,
hours=>hours,hourg=>hourg,clkh=>d);
u4:
madaptportmap(en=>en,m1=>m1,clk=>clk,secin=>a,minset=>b);
u5:
hadaptportmap(en=>en,h1=>h1,clk=>clk,minin=>c,hourset=>d);
end;
数码管显示模块只要把通常用的模块0改11改0就可用了。
如下
entitym7448is
port(
result:
inbit_vector(3downto0);
seg:
outbit_vector(6downto0)
);
endm7448;
architecturexxofm7448is
begin
process(result)
begin
caseresultis
when"0000"=>seg<="0000001";
when"0001"=>seg<="1001111";
when"0010"=>seg<="0010010";
when"0011"=>seg<="0000110";
when"0100"=>seg<="1001100";
when"0101"=>seg<="0100100";
when"0110"=>seg<="0100000";
when"0111"=>seg<="0001111";
when"1000"=>seg<="0000000";
whenothers=>seg<="0000100";
endcase;
endprocess;
endxx;
4选1选择器
entitymux4vis
port(
a,b,c,d:
inbit_vector(3downto0);
sel:
inbit_vector(1downto0);
result:
outbit_vector(3downto0)
);
endmux4v;
architectureaaofmux4vis
begin
withselselect
result<=awhen"11",
bwhen"10",
cwhen"01",
dwhenothers;
endaa;
分频器由Quartus自己的程序库提出
位选模块CASE24
entitycase24is
port(
sel:
inbit_vector(1downto0);
y:
outbit_vector(3downto0)
);
endcase24;
architecturexxofcase24is
begin
process(sel)
begin
caseselis
when"00"=>y<="1110";
when"01"=>y<="1101";
when"10"=>y<="1011";
whenothers=>y<="0111";
endcase;
endprocess;
endxx;
上面就是我的完整程序。
三、仿真结果
VHDL语言设计的六十进制电路,模块及其波形
VHDL语言设计的二十四进制电路,模块及其波形
四、总电路图
五、运行情况
按键说明:
S6:
切换显示
S3小时设置
S1分钟设置
S5清零按钮
S2屏蔽设置分、时设置(按住为屏蔽)
时分显示
分秒显示
Key72切换显示
显示效果良好,没有出现错误
六、结论分析
1时钟显示正常;
2设置时、分功能正常、
3清零键正常
因为时间和个人能力,没能做出闪烁。
用了失能和双频率赋值的方法做了4个程序,都不能正常使用,故放弃了闪烁。
闹钟程序虽然比较简单但是因为时间问题,也夭折了。
七、收获感想
**
八、参考资料
《VHDL使用教程》潘松王国栋编著
《EDA技术与VHDL程序开发基础教程》清华大学出版社