当前位置:文档之家› 基于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 isport (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 isbeginP1KHZ:process(CLK)variable cout:integer:=0;beginif CLK'event and CLK='1' thencout:=cout+1; --每来个时钟上升沿时cout开始计数if cout<=25000 then q1KHz<='0'; --当cout<=25000时,q1KHz输出“0”elsif cout<50000 then q1KHz<='1'; --当25000<cout<=50000时,q1KHzelse cout:=0; --输出“1”,完成1KHz频率输出end if;end if;end process;P500HZ:process(q1KHz) --q1KHz作为输入信号,分出q500Hz variable cout:integer:=0;beginif q1KHz'event and q1KHz='1' thencout:=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;beginif q500Hz'event and q500Hz='1' thencout:=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;beginif q2Hz'event and q2Hz='1' thencout:=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 isport(a,b,s:in bit;y:out bit);end entity mux21a;architecture one of mux21a isbeginprocess(a,b,s)beginif s='0' theny<=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 isport(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 isbeginprocess(th1,tm1,ts1,th0,tm0,ts0,bh1,bm1,bh0,bm0,q2Hz,flashs,flashh,flashm,sel_sho w)beginif sel_show='0'thenif ( flashh='1'and q2Hz='1')thenh1<="1111";h0<="1111"; --显示小时数码管以2Hz闪烁min1<=tm1;min0<=tm0;sec1<=ts1;sec0<=ts0;elsif (flashm='1'and q2Hz='1')thenh1<=th1;h0<=th0;min1<="1111";min0<="1111";sec1<=ts1;sec0<=ts0;elsif (flashs='1'and q2Hz='1')thenh1<=th1;h0<=th0;min1<=tm1;min0<=tm0;sec1<="1111";sec0<="1111";elseh1<=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')thenh1<="1111";h0<="1111";min1<=bm1;min0<=bm0;sec1<="0000";sec0<="0000";elsif ( flashm='1' and q2Hz='1')thenh1<=bh1;h0<=bh0;min1<="1111";min0<="1111";sec1<="0000";sec0<="0000";elseh1<=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组输入信号和输出信号进而实现了时钟时、分的动态显示。

相关主题