基于VHDL的多功能数字钟设计报告.docx

上传人:b****0 文档编号:12610714 上传时间:2023-04-20 格式:DOCX 页数:20 大小:441.51KB
下载 相关 举报
基于VHDL的多功能数字钟设计报告.docx_第1页
第1页 / 共20页
基于VHDL的多功能数字钟设计报告.docx_第2页
第2页 / 共20页
基于VHDL的多功能数字钟设计报告.docx_第3页
第3页 / 共20页
基于VHDL的多功能数字钟设计报告.docx_第4页
第4页 / 共20页
基于VHDL的多功能数字钟设计报告.docx_第5页
第5页 / 共20页
点击查看更多>>
下载资源
资源描述

基于VHDL的多功能数字钟设计报告.docx

《基于VHDL的多功能数字钟设计报告.docx》由会员分享,可在线阅读,更多相关《基于VHDL的多功能数字钟设计报告.docx(20页珍藏版)》请在冰豆网上搜索。

基于VHDL的多功能数字钟设计报告.docx

基于VHDL的多功能数字钟设计报告

基于VHDL的多功能数字钟设计报告

 

 

————————————————————————————————作者:

————————————————————————————————日期:

 

 

基于VHDL的多功能数字钟

设计报告

 

021215班

卫时章

 

一、设计要求

1、具有以二十四小时制计时、显示、整点报时、时间设置和闹钟的功能。

2、设计精度要求为1秒。

二、设计环境:

Quartus II 

三、系统功能描述

1、系统输入:

时钟信号clk采用50MHz;系统状态及较时、定时转换的控制信号为k、set,校时复位信号为reset,均由按键信号产生。

2、系统输出:

LED显示输出;蜂鸣器声音信号输出。

3、多功能数字电子钟系统功能的具体描述如下:

(一)计时:

正常工作状态下,每日按24h计时制计时并显示,蜂鸣器无声,逢整点报时。

(二)校时:

在计时显示状态下,按下“k”键,进入“小时”待校准状态,若此时按下“set”键,小时开始校准;之后按下“k”键则进入“分”待校准状态;继续按下“k”键则进入“秒”待复零状态;再次按下“k”键数码管显示闹钟时间,并进入闹钟“小时”待校准状态;再次按下“k”键则进入闹钟“分”待校准状态;若再按下“k”键恢复到正常计时显示状态。

若校时过程中按下“reset”键,则系统恢复到正常计数状态。

(1)“小时”校准状态:

在“小时”校准状态下,显示“小时”的数码管以2Hz闪烁,并按下“set”键时以2Hz的频率递增计数。

(2)“分”校准状态:

在“分”校准状态下,显示“分”的数码管以2Hz闪烁,并按下“set”键时以2Hz的频率递增计数。

(3)“秒”校准状态:

在“秒复零”状态下,显示“秒”的数码管以2Hz闪烁,并以1Hz的频率递增计数。

(4)闹钟“小时”校准状态:

在闹钟“小时”校准状态下,显示“小时”的数码管以2Hz闪烁,并按下“set”键时以2Hz的频率递增计数。

(5)闹钟“分”校准状态:

在闹钟“分”校准状态下,显示“分”的数码管以2Hz闪烁,并按下“set”键时以2Hz的频率递增计数。

(三)整点报时:

蜂鸣器在“59”分钟的第“51”、“53”、“55”、“57”秒发频率为500Hz的低音,在“59”分钟的第“59”秒发频率为1000Hz的高音,结束时为整点。

(四)显示:

采用扫描显示方式驱动4个LED数码管显示小时、分,秒由两组led灯以4位BCD 码显示。

(五)闹钟:

闹钟定时时间到,蜂鸣器发出频率为1000Hz的高音,持续时间为60秒。

四、各个模块分析说明

1、分频器模块(freq.vhd)

(1)模块说明:

输入一个频率为50MHz的CLK,利用计数器分出

1KHz的q1KHz,500Hz的q500Hz,2Hz的q2Hz和1Hz的q1Hz。

(2)源程序:

libraryieee;

use ieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityfreqis

port(CLK:

instd_logic; --输入时钟信号

q1KHz:

buffer std_logic;

 q500Hz:

 bufferstd_logic;

 q2Hz:

bufferstd_logic;

   q1Hz:

 outstd_logic);

endfreq;

architecture bhvoffreqis

begin

P1KHZ:

process(CLK)

variablecout:

integer:

=0;

begin

if CLK'event andCLK='1'then    

cout:

=cout+1;       --每来个时钟上升沿时cout开始计数

ifcout<=25000thenq1KHz<='0';  --当cout<=25000时,q1KHz输出“0”

elsifcout<50000thenq1KHz<='1'; --当25000<cout<=50000时,q1KHz

  elsecout:

=0;  --输出“1”,完成1KHz频率输出

endif;

endif;

endprocess;

P500HZ:

process(q1KHz)   --q1KHz作为输入信号,分出q500Hz

variablecout:

integer:

=0;

begin

ifq1KHz'event and q1KHz='1' then

cout:

=cout+1;

ifcout=1thenq500Hz<='0';    --二分频

 elsif cout=2thencout:

=0;q500Hz<='1';

end if; 

end if;

end process;

P2HZ:

process(q500Hz)

variablecout:

integer:

=0;

begin

ifq500Hz'eventandq500Hz='1'then

cout:

=cout+1;

ifcout<=125thenq2Hz<='0';

elsifcout<250 thenq2Hz<='1';

  elsecout:

=0;

end if;

endif; 

endprocess;

P1HZ:

process(q2Hz)

variablecout:

integer:

=0;

begin

ifq2Hz'eventandq2Hz='1'then

cout:

=cout+1;

ifcout=1thenq1Hz<='0';

elsifcout=2thencout:

=0;q1Hz<='1';

endif; 

end if; 

end process;

endbhv;

(3)模块图:

2、控制器模块(contral.vhd)

(1)模块说明:

输入端口k,set键来控制6个状态,这六个状态分别是:

显示计时时间状态,调计时的时、分、秒的3个状态,调闹铃的时、分的3个状态,reset键是复位键,用来回到显示计时时间的状态。

(2)波形仿真图:

(3)模块图:

3、二选一模块(mux21a.vhd)

(1)源程序:

libraryieee;

useieee.std_logic_1164.all; 

useieee.std_logic_unsigned.all;

entitymux21ais

port(a,b,s:

inbit;

    y:

outbit);

endentitymux21a;

architectureone ofmux21ais

begin

process(a,b,s)

begin

if s='0'then

y<=a;--若s=0,y输出a,反之输出b。

elsey<=b;

endif;

end process;

endarchitecture one;

(2)仿真波形图:

(3)模块图:

4、计时模块

a.秒计时(second.vhd)

(1)仿真波形图:

(2)模块图:

b.分计时(minute.vhd)

(1)仿真波形图:

(2)模块图:

c.小时计时(hour.vhd)

(1)仿真波形图:

(2)模块图:

d.闹钟分计时(cntm60b.vhd)

(1)仿真波形图:

(2)模块图:

e.闹钟小时计时(cnth24b.vhd)

(1)仿真波形图:

(2)模块图:

5、闹钟比较模块(compare.vhd)

(1)模块说明:

比较正常计数时间与闹钟定时时间是否相等,若相等,compout输出“1”,反之输出“0”。

(2)仿真波形图:

(3)模块图:

6、报时模块(bell.vhd)

(1)模块说明:

该模块既实现了整点报时的功能,又实现了闹铃的功能,蜂鸣器通过所选频率的不同,而发出不同的声音。

(2)仿真波形图:

(3)模块图:

7、控制显示模块(show_con.vhd)

(1)模块说明:

该模块实现了数码管既可以显示正常时间,又可以显示闹钟时间的功能;调时过程的定时闪烁功能也在此模块中真正实现。

(2)源程序:

library ieee;

useieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity show_conis

  port(th1,tm1,ts1:

instd_logic_vector(7downto 4);

  th0,tm0,ts0:

instd_logic_vector(3downto0);

   bh1,bm1:

instd_logic_vector(7downto4);

     bh0,bm0:

instd_logic_vector(3 downto0);

   sec1,min1,h1:

out std_logic_vector(7 downto 4);

 sec0,min0,h0:

out std_logic_vector(3downto 0);

    q2Hz,flashs,flashh,flashm,sel_show:

instd_logic);

endshow_con;

architecturertlofshow_con is

begin

process(th1,tm1,ts1,th0,tm0,ts0,bh1,bm1,bh0,bm0,q2Hz,flashs,flashh,flashm,sel_show)

begin

  ifsel_show='0'then

 if(flashh='1'andq2Hz='1')then

  h1<="1111";h0<="1111"; --显示小时数码管以2Hz闪烁

   min1<=tm1;min0<=tm0;

 sec1<=ts1;sec0<=ts0;

  elsif(flashm='1'and q2Hz='1')then

    h1<=th1;h0<=th0;

   min1<="1111";min0<="1111";

    sec1<=ts1;sec0<=ts0;

   elsif(flashs='1'andq2Hz='1')then

   h1<=th1;h0<=th0;

   min1<=tm1;min0<=tm0;

    sec1<="1111";sec0<="1111";

  else

   h1<=th1;h0<=th0;

  min1<=tm1;min0<=tm0;

 sec1<=ts1;sec0<=ts0;

     end if;

  elsifsel_show='1'then--若sel_show为“1”,数码管显示闹钟时间

if(flashh='1'andq2Hz='1')then

h1<="1111";h0<="1111";

  min1<=bm1;min0<=bm0;

 sec1<="0000";sec0<="0000";

   elsif(flashm='1'and q2Hz='1')then

 h1<=bh1;h0<=bh0;

 min1<="1111";min0<="1111";

 sec1<="0000";sec0<="0000";

 else

  h1<=bh1;h0<=bh0;

  min1<=bm1;min0<=bm0;

  sec1<="0000";sec0<="0000";

endif ;

   endif;

 endprocess;

end rtl;

(3)模块图:

8、动态扫描显示模块(scan_led.vhd)

(1)模块说明:

由4组输入信号和输出信号进而实现了时钟时、分的动态显示。

(2)源程序:

library ieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityscan_led is

port(clk1:

instd_logic;

  h0:

instd_logic_vector(3 downto0);

  h1:

in std_logic_vector(7 downto4);

  min0:

instd_logic_vector(3downto 0);

 min1:

instd_logic_vector(7downto 4);

 ML:

outstd_logic_vector(7downto0);

MH:

outstd_logic_vector(7 downto0);

 HL:

outstd_logic_vector(7downto 0);

  HH:

outstd_logic_vector(7downto 0)

  );

end scan_led;

architectureoneofscan_ledis

signalcnt4:

std_logic_vector(1 downto0);

signala:

 std_logic_vector(3downto0);

begin

p1:

process(clk1)

begin

 ifclk1'eventandclk1 ='1' then 

   cnt4<=cnt4+1;

  if cnt4=3 then

 cnt4<="00";

 endif;

endif;

endprocessp1;

p2:

process(cnt4,h1,h0,min1,min0)

begin

casecnt4is   --控制数码管位选

when"00"=>casemin0is

   when"0000"=>ML<="11000000";

ﻩ   when"0001"=>ML<="11111001"; 

  when "0010"=>ML<="10100100";

  when"0011"=>ML<="10110000";

   when"0100"=>ML<="10011001";

ﻩ  when"0101"=>ML<="10010010"; 

when "0110"=>ML<="10000010";

 when "0111"=>ML<="11111000";

ﻩ when"1000"=>ML<="10000000"; 

ﻩwhen"1001"=>ML<="10010000";

      whenothers=>NULL;

  endcase;

when"01"=>casemin1is

   when "0000"=>MH<="11000000";

ﻩ    when"0001"=>MH<="11111001";

   when"0010"=>MH<="10100100"; 

ﻩﻩ when"0011"=>MH<="10110000";

ﻩ   when"0100"=>MH<="10011001"; 

ﻩ when"0101"=>MH<="10010010";

ﻩ  when "0110"=>MH<="10000010";

ﻩ   when"0111"=>MH<="11111000";

 when"1000"=>MH<="10000000";

ﻩ  when"1001"=>MH<="10010000";

   whenothers=>NULL;

    endcase;

when "10"=>caseh0 is

  when "0000"=>HL<="11000000";

ﻩ   when "0001"=>HL<="11111001";

 when"0010"=>HL<="10100100";

ﻩﻩwhen"0011"=>HL<="10110000";

ﻩwhen"0100"=>HL<="10011001";

   when"0101"=>HL<="10010010";

ﻩ when"0110"=>HL<="10000010"; 

   when"0111"=>HL<="11111000";

ﻩ  when"1000"=>HL<="10000000";

ﻩ  when"1001"=>HL<="10010000"; 

   whenothers=>NULL;

   end case;

when"11"=>case h1is

  when"0000"=>HH<="11000000"; 

ﻩ    when "0001"=>HH<="11111001";

ﻩ    when "0010"=>HH<="10100100";

ﻩ  when"0011"=>HH<="10110000";

ﻩ  when"0100"=>HH<="10011001";

ﻩ    when"0101"=>HH<="10010010";

ﻩ  when "0110"=>HH<="10000010";

ﻩ  when"0111"=>HH<="11111000";

 when"1000"=>HH<="10000000";

     when"1001"=>HH<="10010000";

     whenothers=>NULL;

    endcase;

whenothers=>null;

endcase;

end processp2;

endone;

(3)模块图:

 

5、端口设定

k:

button2,set:

button1,reset:

button0;

Bell:

SW1 用于开关蜂鸣器;

 

六、顶层电路图

7、心得体会

此次的数字钟设计重在于按键的控制和各个模块代码的编写,虽然能把键盘接口和各个模块的代码编写出来,并能正常显示,但对于各个模块的优化设计还有一定的缺陷和不足,比如对按键消抖等细节处并未作出优化。

经过此次数字钟的设计,我确实从中学到很多的东西。

首先,通过VHDL硬件语言的学习,我充分认识到了功能模块如何用语言实现,让我初步了解到了一个数字电路用硬件语言设计的方式和设计思想。

其次,也让我深深地体会到实践的重要性,起初我学VHDL语言的时候,只是学得书本上的知识,经过这次课程设计,通过对模块的语言实现,对于VHDL语言我有了更深的认识。

而且在程序错误的发现和改正的过程中,我得到了更多的收获,也确实让我进步了不少。

再次,当我遇到一些问题的时候,请教老师,和同学们一起讨论,令我受益颇多!

最后,这个多功能数字电子钟是自我创造与吸取借鉴共同作用的产物,是自我努力的结果。

这让我对数字电路的设计充满了信心。

虽然课程设计已经结束,但这并不代表着我已经真正掌握了VHDL语言,仍需继续学习!

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1