当前位置:文档之家› 基于VHDL的多功能数字钟设计报告

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

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

基于VHDL的多功能数字钟

设计报告

021215班

卫时章

02121451

一、设计要求

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)源程序:

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity freq is

port (CLK: in std_logic ; --输入时钟信号

q1KHz: buffer std_logic;

q500Hz: buffer std_logic;

q2Hz: buffer std_logic;

q1Hz: out std_logic);

end freq;

architecture bhv of freq is

begin

P1KHZ:process(CLK)

variable cout:integer:=0;

begin

if CLK'event and CLK='1' then

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

if cout<=25000 then q1KHz<='0'; --当cout<=25000时,q1KHz输出“0”elsif cout<50000 then q1KHz<='1'; --当25000

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

end if;

end if;

end process;

P500HZ:process(q1KHz) --q1KHz作为输入信号,分出q500Hz variable cout:integer:=0;

begin

if q1KHz'event and q1KHz='1' then

cout:=cout+1;

if cout=1 then q500Hz<='0'; --二分频

elsif cout=2 then cout:=0;q500Hz<='1';

end if;

end if;

end process;

P2HZ:process(q500Hz)

variable cout:integer:=0;

begin

if q500Hz'event and q500Hz='1' then

cout:=cout+1;

if cout<=125 then q2Hz<='0';

elsif cout<250 then q2Hz<='1';

else cout:=0;

end if;

end if;

end process;

P1HZ:process(q2Hz)

variable cout:integer:=0;

begin

if q2Hz'event and q2Hz='1' then

cout:=cout+1;

if cout=1 then q1Hz<='0';

elsif cout=2 then cout:=0;q1Hz<='1';

end if;

end if;

end process;

end bhv;

(3)模块图:

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

(1)模块说明:输入端口k,set键来控制6个状态,这六个状态分别是:

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

(2)波形仿真图:

(3)模块图:

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

(1)源程序:

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity mux21a is

port(a,b,s:in bit;

y:out bit);

end entity mux21a;

architecture one of mux21a is

begin

process(a,b,s)

begin

if s='0' then

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

end if;

end process;

end architecture 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;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity show_con is

port(th1,tm1,ts1:in std_logic_vector(7 downto 4);

th0,tm0,ts0:in std_logic_vector(3 downto 0);

bh1,bm1:in std_logic_vector(7 downto 4);

bh0,bm0:in std_logic_vector(3 downto 0);

sec1,min1,h1: out std_logic_vector(7 downto 4);

sec0,min0,h0: out std_logic_vector(3 downto 0);

q2Hz,flashs,flashh,flashm,sel_show:in std_logic);

end show_con;

architecture rtl of show_con is

begin

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

begin

if sel_show='0'then

if ( flashh='1'and q2Hz='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'and q2Hz='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;

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

if(flashh='1' and q2Hz='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";

end if ;

end if;

end process;

end rtl;

(3)模块图:

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

(1)模块说明:由4组输入信号和输出信号进而实现了时钟时、分的动态显示。(2)源程序:

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity scan_led is

port(clk1:in std_logic;

h0:in std_logic_vector(3 downto 0);

h1:in std_logic_vector(7 downto 4);

min0:in std_logic_vector(3 downto 0);

min1:in std_logic_vector(7 downto 4);

ML:out std_logic_vector(7 downto 0);

MH:out std_logic_vector(7 downto 0);

HL:out std_logic_vector(7 downto 0);

HH:out std_logic_vector(7 downto 0)

);

end scan_led;

architecture one of scan_led is

signal cnt4:std_logic_vector(1 downto 0);

signal a: std_logic_vector(3 downto 0) ;

begin

p1:process(clk1)

begin

if clk1'event and clk1 ='1' then

cnt4<=cnt4+1;

if cnt4=3 then

cnt4<="00";

end if;

end if;

end process p1;

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

begin

case cnt4 is --控制数码管位选when "00"=>case min0 is

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";

when others=>NULL;

end case;

when "01"=>case min1 is

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";

when others=>NULL;

end case;

when "10"=>case h0 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";

when others=>NULL;

end case;

when "11"=>case h1 is

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";

when others=>NULL;

end case;

when others =>null;

end case;

end process p2;

end one;

(3)模块图:

五、端口设定

k:button2 ,set:button1 ,reset:button0 ;Bell:SW1 用于开关蜂鸣器;

六、顶层电路图

七、心得体会

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

经过此次数字钟的设计,我确实从中学到很多的东西。首先,通过VHDL硬件语言的学习,我充分认识到了功能模块如何用语言实现,让我初步了解到了一个数字电路用硬件语言设计的方式和设计思想。其次,也让我深深地体会到实践的重要性,起初我学VHDL语言的时候,只是学得书本上的知识,经过这次课程设计,通过对模块的语言实现,对于VHDL语言我有了更深的认识。而且在程序错误的发现和改正的过程中,我得到了更多的收获,也确实让我进步了不少。再次,当我遇到一些问题的时候,请教老师,和同学们一起讨论,令我受益颇多!最后,这个多功能数字电子钟是自我创造与吸取借鉴共同作用的产物,是自我努力的结果。这让我对数字电路的设计充满了信心。虽然课程设计已经结束,但这并不代表着我已经真正掌握了VHDL语言,仍需继续学习!

相关主题
文本预览
相关文档 最新文档