EDA数字钟课程设计.docx
《EDA数字钟课程设计.docx》由会员分享,可在线阅读,更多相关《EDA数字钟课程设计.docx(18页珍藏版)》请在冰豆网上搜索。
EDA数字钟课程设计
课程设计报告
课程名称:
EDA技术与应用
设计题目:
数字钟设计
数字钟设计
摘要:
系统使用EDA技术设计了数字钟,采用硬件描述语言VHDL按模块化方式进行设计,然后进行编程,时序仿真等。
利用VHDL语言完成了数字钟的设计。
该数字钟能实现时、分、秒计数的显示功能,且以24小时循环计时。
整个系统结构简单,使用方便,功能齐全,精度高,具有一定的开发价值。
关键字:
数字钟;EDA;VHDL;
一、设计要求
1.1、时钟功能
设计一个具有时、分、秒计时的数字钟电路,计时采用24小时制。
小时、分钟可调的数字钟。
1.2、准确性要求
设计出的时钟电路要确保高精度的要求,每天的误差不得超过一秒。
二、数字钟的基本原理
1、具有时、分、秒计数显示功能,以24小时循环计时。
其中SECOND模块为60进制BCD码计数电路,实现秒计时功能;MINUTE模块为60进制BCD码计数电路,实现分计时功能;HOUR模块为24进制BCD码计数电路,实现小时计时功能。
2、有驱动8位七段共阴极扫描数码管的片选驱动信号输出和七段码输出。
SELTIME模块产生8位数码管的扫描驱动信号SEL[2..0]和时钟显示数据(动态显示)DAOUT[3..0]。
DELED模块则为数码管显示时钟数据的7段译码电路。
三、方案论证
3.1、数字钟的基本组成
数字钟实际上是一个对标准频率(1HZ)进行计数的计数电路,其基本组成电路如下图所示:
图3.1数字钟原理图
图
(1)中,秒冲发生器产生秒脉冲,作为图中各个计数器的脉冲信号。
分、秒计数器要求设计为六十进制计数器;时计数器则设计为二十四进制计数器。
时、分、秒的计时结果分别送入译码器中,经译码器翻译后,共由六个LED数码管显示出结果。
因此,使用计数器作为计时电路是可以实现的。
四、各功能模块
4.1、小时计时功能
实现程序如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityhouris
port(reset,clk:
instd_logic;
daout:
outstd_logic_vector(7downto0));
endhour;
architecturebehavofhouris
signalcount:
std_logic_vector(3downto0);
signalcounter:
std_logic_vector(3downto0);
begin
p1:
process(reset,clk)
begin
ifreset='0'then
count<="0000";
counter<="0000";
elsif(clk'eventandclk='1')then
if(counter<2)then
if(count=9)then
count<="0000";
counter<=counter+1;
else
count<=count+1;
endif;
else
if(count=3)then
count<="0000";
counter<="0000";
else
count<=count+1;
endif;
endif;
endif;
endprocess;
daout(7downto4)<=counter;
daout(3downto0)<=count;
endbehav;
图4.1时计时功能模块
4.2、分计时功能
实现程序如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityminuteis
port(reset,clk,sethour:
instd_logic;
daout:
outstd_logic_vector(7downto0);
enhour:
outstd_logic);
endminute;
architecturebehavofminuteis
signalcount:
std_logic_vector(3downto0);
signalcounter:
std_logic_vector(3downto0);
signalcarry_out1:
std_logic;
signalcarry_out2:
std_logic;
begin
p1:
process(reset,clk)
begin
ifreset='0'then
count<="0000";
counter<="0000";
elsif(clk'eventandclk='1')then
if(counter<5)then
if(count=9)then
count<="0000";
counter<=counter+1;
else
count<=count+1;
endif;
carry_out1<='0';
else
if(count=9)then
count<="0000";
counter<="0000";
carry_out1<='1';
else
count<=count+1;
carry_out1<='0';
endif;
endif;
endif;
endprocess;
p2:
process(clk)
begin
if(clk'eventandclk='0')then
if(counter=0)then
if(count=0)then
carry_out2<='0';
endif;
else
carry_out2<='1';
endif;
endif;
endprocess;
daout(7downto4)<=counter;
daout(3downto0)<=count;
enhour<=(carry_out1andcarry_out2)orsethour;
endbehav;
图4.2分计时模块
4.3、秒计时功能
实现程序如下;
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitysecondis
port(reset,clk,setmin:
instd_logic;
daout:
outstd_logic_vector(7downto0);
enmin:
outstd_logic);
endsecond;
architecturebehavofsecondis
signalcount:
std_logic_vector(3downto0);
signalcounter:
std_logic_vector(3downto0);
signalcarry_out1:
std_logic;
signalcarry_out2:
std_logic;
begin
p1:
process(reset,clk)
begin
ifreset='0'then
count<="0000";
counter<="0000";
elsif(clk'eventandclk='1')then
if(counter<5)then
if(count=9)then
count<="0000";
counter<=counter+1;
else
count<=count+1;
endif;
carry_out1<='0';
else
if(count=9)then
count<="0000";
counter<="0000";
carry_out1<='1';
else
count<=count+1;
carry_out1<='0';
endif;
endif;
endif;
endprocess;
daout(7downto4)<=counter;
daout(3downto0)<=count;
enmin<=carry_out1orsetmin;
endbehav;
图4.3秒计时模块
4.4、alert模块
实现程序如下:
LibraryIEEE;
useIEEE.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityalertis
Port(
clkspk:
instd_logic;
second:
instd_logic_vector(7downto0);
minute:
instd_logic_vector(7downto0);
speak:
outstd_logic;
lamp:
outstd_logic_vector(8downto0));
endalert;
architecturebehavofalertis
signaldivclkspk2:
std_logic;
begin
p1:
process(clkspk)
begin
if(clkspk'eventandclkspk='1')then
divclkspk2<=notdivclkspk2;
endif;
endprocess;
p2:
process(second,minute)
begin
if(minute="01011001")then
casesecondis
when"01010001"=>lamp<="000000001";speak<=divclkspk2;
when"01010010"=>lamp<="000000010";speak<='0';
when"01010011"=>lamp<="000000100";speak<=divclkspk2;
when"01010100"=>lamp<="000001000";speak<='0';
when"01010101"=>lamp<="000010000";speak<=divclkspk2;
when"01010110"=>lamp<="000100000";speak<='0';
when"01010111"=>lamp<="001000000";speak<=divclkspk2;
when"01011000"=>lamp<="010000000";speak<='0';
when"01011001"=>lamp<="100000000";speak<=clkspk;
whenothers=>lamp<="000000000";
endcase;
endif;
endprocess;
endbehav;
图4.4alert模块
4.5、DELED模块
实现程序如下;
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
ENTITYDELEDIS
PORT(
S:
INSTD_LOGIC_VECTOR(3DOWNTO0);
A,B,C,D,E,F,G,H:
OUTSTD_LOGIC);
ENDDELED;
ARCHITECTUREBEHAVOFDELEDIS
SIGNALDATA:
STD_LOGIC_VECTOR(3DOWNTO0);
SIGNALDOUT:
STD_LOGIC_VECTOR(7DOWNTO0);
BEGIN
DATA<=S;
PROCESS(DATA)
BEGIN
CASEDATAIS
WHEN"0000"=>DOUT<="00111111";
WHEN"0001"=>DOUT<="00000110";
WHEN"0010"=>DOUT<="01011011";
WHEN"0011"=>DOUT<="01001111";
WHEN"0100"=>DOUT<="01100110";
WHEN"0101"=>DOUT<="01101101";
WHEN"0110"=>DOUT<="01111101";
WHEN"0111"=>DOUT<="00000111";
WHEN"1000"=>DOUT<="01111111";
WHEN"1001"=>DOUT<="01101111";
WHEN"1010"=>DOUT<="01110111";
WHEN"1011"=>DOUT<="01111100";
WHEN"1100"=>DOUT<="00111001";
WHEN"1101"=>DOUT<="01011110";
WHEN"1110"=>DOUT<="01111001";
WHEN"1111"=>DOUT<="01000000";
WHENOTHERS=>DOUT<="00000000";
ENDCASE;
ENDPROCESS;
H<=DOUT(7);
G<=DOUT(6);
F<=DOUT(5);
E<=DOUT(4);
D<=DOUT(3);
C<=DOUT
(2);
B<=DOUT
(1);
A<=DOUT(0);
ENDBEHAV;
图4.5deled模块
4.6、seltime模块
实现程序如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityseltimeis
port(
ckdsp:
instd_logic;
reset:
instd_logic;
second:
instd_logic_vector(7downto0);
minute:
instd_logic_vector(7downto0);
hour:
instd_logic_vector(7downto0);
daout:
outstd_logic_vector(3downto0);
sel:
outstd_logic_vector(2downto0));
endseltime;
architecturebehavofseltimeis
signalsec:
std_logic_vector(2downto0);
begin
process(reset,ckdsp)
begin
if(reset='0')then
sec<="000";
elsif(ckdsp'eventandckdsp='1')then
if(sec="111")then
sec<="000";
else
sec<=sec+1;
endif;
endif;
endprocess;
process(sec,second,minute,hour)
begin
casesecis
when"000"=>daout<=second(3downto0);
when"001"=>daout<=second(7downto4);
when"011"=>daout<=minute(3downto0);
when"100"=>daout<=minute(7downto4);
when"110"=>daout<=hour(3downto0);
when"111"=>daout<=hour(7downto4);
whenothers=>daout<="1111";
endcase;
endprocess;
sel<=sec;
endbehav;
图4.6seltime模块
五、功能实现简述
5.1、具有时、分、秒计数显示功能,以24小时循环计时。
其中SECOND模块为60进制BCD码计数电路,实现秒计时功能;MINUTE为60进制BCD码计数电路,实现分计时功能;HOUR模块为24进制BCD码计数电路,实现小时计时功能。
5.2、有驱动8位七段共阴极扫描数码管的片选驱动信号输出和七段码输出。
SELTIME模块产生8位数码管的扫描驱动信号SEL[2..0]和时钟显示数据(动态显示)DAOUT[3..0]。
DELED模块则为数码管显示时钟数据的7段译码电路。
根据图1所示原理图,对其进行仿真,其仿真图如下:
图5.1实验仿真图
完成功能仿真之后,如图所示对其进行管脚锁定,并下载到目标芯片,将第一全局时钟CLK1的跳线器接1Hz,第二全局时钟CLK2的跳线器接1024Hz,第三全局时钟CLK3的跳线器接32768Hz。
拨位开关KD1为清零控制开关(高电平有效),KD2、KD3分别为小时调节、分钟调节允许端(低电平允许调节,高电平禁止调节/正常计时)。
按键K2、K3分别为小时调节、分钟调节按键(仅当KD2、KD3为低电平允许调节时有效),只能加调节。
数码管SM6-SM1分别显示小时,分钟,秒。
6、结果显示
图6.1实验显示图
7、心得体会
这次实验中积累了如下经验:
1、系统设计进要行充分的方案论证,不可盲目就动手去做;
2、实验中对每一个细节部分都要全面思考,要对特殊情况进行处理;
3、对于数字系统,要考虑同步、异步问题;
4、数字电路的理论分析要结合时序图;
5、遇到问题,要顺藤摸瓜,分析清楚,不可胡乱改动,每做一次改变都要有充分的理由;
6、模块化设计方法的优点在于其简洁性,但是在实验设计中也发现,在实验最终电路确定之前,要尽量减少模块重叠嵌套,因为在总的电路敲定之前,电路还不成熟,很多地方需要改进,如果在开始时就进行多层模块化,里层模块电路的修改将影响其外层的全部电路,这样就是牵一发动全身,很显然,这样将导致电路设计的低效,所以在设计过程中,一定要尽量减少超过两层的模块;
7、遇到问题花了很长时间没有解决掉,要学会想他人请教,别人的不经意一点,可能就能把自己带出思维死区。
8、参考文献
江国强编EDA技术与应用电子工业出版社2010.4