文档详情

EDA课程设计多功能数字钟

无***
实名认证
店铺
DOC
118.50KB
约17页
文档ID:93548447
EDA课程设计多功能数字钟_第1页
1/17

哈尔滨工业大学(威海)电子学课程设计报告带有整点报时的数字钟设计与制作姓名:蒋栋栋班级:0802503学号:080250331指导教师:井岩目录一、课程设计的性质、目的和任务………………………………3二、课程设计基本要求……………………………………………3三、设计课题要求…………………………………………………3四、课程设计所需要仪器…………………………………………4五、设计步骤………………………………………………………4 1、整体设计框图…………………………………………………4 2、各个模块的设计与仿真………………………………………4 2.1分频模块……………………………………………………………4 2.2计数器模块…………………………………………………………6 2.3控制模块…………………………………………………………10 2.4数码管分配………………………………………………………13 2.5显示模块…………………………………………………………14 2.6报时模块…………………………………………………………16六、调试中遇到的问题及解决的方法……………………………18七、心得体会………………………………………………………18一、课程设计的性质、目的和任务创新精神和实践能力二者之中,实践能力是基础和根本。

这是由于创新基于实践、源于实践,实践出真知,实践检验真理实践活动是创新的源泉,也是人才成长的必由之路通过课程设计的锻炼,要求学生掌握电路的一般设计方法,具备初步的独立设计能力,提高综合运用所学的理论知识独立分析和解决问题的能力,培养学生的创新精神二、课程设计基本要求掌握现代大规模集成数字逻辑电路的应用设计方法,进一步掌握电子仪器的正确使用方法,以及掌握利用计算机进行电子设计自动化(EDA)的基本方法三、设计课题要求(1)构造一个24小时制的数字钟要求能显示时、分、秒2)要求时、分、秒能各自独立的进行调整3)能利用喇叭作整点报时从59分50秒时开始报时,每隔一秒报时一秒,到达00分00秒时,整点报时整点报时声的频率应与其它的报时声频有明显区别设计提示(仅供参考):(1)对频率输入的考虑数字钟内所需的时钟频率有:基准时钟应为周期一秒的标准信号报时频率可选用1KHz和2KHz左右(两种频率相差八度音,即频率相差一倍)另外,为防止按键反跳、抖动,微动开关输入应采用寄存器输入形式,其时钟应为几十赫兹2)计时部分计数器设计的考虑分、秒计数器均为模60计数器小时计数为模24计数器,同理可建一个24进制计数器的模块。

3)校时设计的考虑数字钟校准有3个控制键:时校准、分校准和秒校准微动开关不工作,计数器正常工作按下微动开关后,计数器以8Hz频率连续计数(若只按一下,则计数器增加一位),可调用元件库中的逻辑门建一个控制按键的模块,即建立开关去抖动电路(见书70页)4)报时设计的考虑可以将高频时钟分频得到约2KHz和1KHz的音频,作为数字钟的报时频率当电子钟显示XX:59:50时,数字钟开始报时“DO",持续一秒,而且每隔一秒报一下,直至显示XX:00:00时报“DI",持续一秒后停止最后输出至喇叭应调用元件库中的逻辑门建一个控制报时的模块5)建一个七段译码的模块因在系统可编程器件实验箱上的数码管没有经过译码,故要用AHDL语言写一个七段译码的模块,且应考虑数码管为共阳极数码管上的点(D2、D4、D6)应置Vcc四、课程设计所需要仪器1、计算机一台2、quartusⅡ软件3、FPGA开发板五、设计步骤1、模块介绍(1) 分频模块:产生1Hz、1KHz、2KHz频率(2) 计数器模块:生成60进制、24进制计数器(3) 控制模块:按键控制、按键消抖(4) 显示模块:7段数码管显示器,分别显示小时、分钟、秒(5) 报时模块:进行整点报时2、各个模块的设计与仿真2.1分频模块CLK晶振频率50MHZ,分成2KHZ,1KHZ,1HZ的信号。

基准1HZ信号作为时钟计时的秒计数时钟信号;分频的1KHZ,2KHZ信号用于报时电路的不同声讯程序代码:library ieee;use ieee.std_logic_1164.all;entity fre isport(clk ,sel: in std_logic;clk1hz,clk1khz,clk2khz:out std_logic);end fre;architecture beh of fre issignal data1khz,data2khz,data1hz : std_logic := '0';begin clk1hz <= data1hz; clk1khz <= data1khz; clk2khz <= data2khz; clk1khz_pro : process(clk) --产生1khz信号 variable cnt : integer range 0 to 24999; begin if clk'event and clk='1' then if cnt = 24999 then cnt := 0 ; data1khz <= not data1khz; else cnt := cnt + 1; end if; end if; end process clk1khz_pro; clk2khz_pro : process(clk) --产生2khz信号 variable cnt : integer range 0 to 12499; begin if clk'event and clk='1' then if cnt = 12499 then cnt := 0 ; data2khz <= not data2khz; else cnt := cnt + 1; end if; end if; end process clk2khz_pro; clk1hz_pro : process(data1khz) --产生1hz 信号 variable cnt : integer range 0 to 499; begin if data1khz'event and data1khz='1' then if sel='0' then cnt:=0; else if cnt = 499 then cnt := 0 ;data1hz <= not data1hz ; else cnt := cnt + 1; end if; end if; end if; end process clk1hz_pro; end beh;输入模块电路图:2.2计数器模块由秒计数器,分计数器,时计数器组成了最基本的数字钟计时电路,两个六十进制计数器与二十四进制计数器组合构成。

程序代码:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use IEEE.STD_LOGIC_ARITH.ALL;entity shuzizhong isport(clk_change : in std_logic;s_en,m_en,h_en:in std_logic;sel:in std_logic;secout,minout,hourout :out std_logic;sl,sh,ml,mh,hl,hh:out std_logic_vector(3 downto 0);a:out std_logic_vector(15downto 0));end shuzizhong;architecture behav of shuzizhong issignal low_rega,high_rega,low_regb,high_regb,low_regc,high_regc :std_logic_vector(3 downto 0):="0000";signal sout,mout,hout :std_logic :='0';begin--秒的60进制进制 counter_sec_l : process(clk_change,s_en) begin sl<=low_rega;sh<=high_rega;ml<=low_regb;mh<=high_regb;hl<=low_regc;hh<=high_regc; if clk_change'event and clk_change='1' then if s_en='1' then if low_rega="1001" then low_rega <= "0000"; else low_rega <= low_rega+'1'; end if; end if; end if; end process counter_sec_l; counter_sec_h : process(clk_change,s_en,low_rega) begin if clk_change'event and clk_change='1' then if s_en='1' then if low_rega="1001" then if high_rega ="0101"then high_rega <= "0000"; else high_rega <= high_rega+'1'; end if; end if; end if; end if; end process counter_sec_h; sout <= '1' when low_rega="1001" and high_rega="0101" else '0'; ----分钟的60进制设置 counter_min_l : process(clk_change,m_en) begin if clk_change'event and clk_change='1' then if m_en='1' then if sout='1'or sel='0' then if low_regb="1001" then low_regb <= "0000"; else low_regb <= low_regb+'1'; end if; end if; end if; end if; end process counter_min_l; counter_min_h : process(clk_change,m_en,low_regb) begin if clk_change'event and clk_change='1' then if sout='1'or sel='0' then if m_en='1' then if low_regb="1001" then if high_regb ="0101"then high_regb <= "0000"; else high_regb <= high_regb+'1'; end if; end if; end if; end if; end if; end process counter_min_h; mout <= '1' when low_regb="1001" and high_regb="0101"and sout='1' else '0'; --小时的24进制设置counter_hour_l : process(clk_change,h_en) begin if clk_change'event and clk_change='1' then if h_en='1' then if mout='1'or sel='0' then if low_regc="1001"or hout='1' then low_regc <= "0000"; else low_regc <= low_regc+'1'; end if; end if; end if; end if; end process counter_hour_l; counter_hour_h : process(clk_change,h_en,hout) begin if clk_change'event and clk_change='1' then if mout='1'or sel='0' then if h_en='1' then if hout='1' then high_regc<="0000"; else if low_regc="1001" then high_regc <= high_regc+'1'; end if; end if; end if; end if; end if; end process counter_hour_h; hout <= '1' when low_regc="0011" and high_regc="0010" else '0'; secout<=sout;minout<=mout;hourout<=hout; a<=high_regb&low_regb&high_rega&low_rega ; end behav;输入模块电路图:2.3控制模块分五个状态0状态正常计时,按下按键进入下一状态开始调时模式1,按下按键进入调秒模式2,按下按键进入调分模式3,按下按键进入调小时模式4.按下按键恢复正常计时模式。

程序代码:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity key_press isport( set ,mode: in std_logic; clk1khz,clk1hz: in std_logic; secout,minout: in std_logic; clk_change,clk2hz_en:out std_logic ; sel,s_ce,m_ce,h_ce:out std_logic; s_en,m_en,h_en:out std_logic ); end key_press; architecture beh of key_press is signal key1,key2:std_logic; signal sce_reg, mce_reg ,hce_reg:std_logic ; signal ssl,ssen,mmen,hhen:std_logic; signal con : integer range 0 to 4 :=0; --按键按下(延时) begin key_press2 : process(set,clk1khz) variable cnt :integer range 0 to 999; begin if set='0' then if clk1khz'event and clk1khz='1'then if cnt=50 and set='0' then cnt :=cnt+1; key2 <= '1'; else cnt:=cnt+1;key2 <= '0'; end if; end if; else cnt:=0; key2<='0'; end if; end process key_press2; key_press1 : process(mode,clk1khz) variable cnt :integer range 0 to 999; begin if mode='0' then if clk1khz'event and clk1khz='1'then if cnt=50 and mode='0' then cnt :=cnt+1; key1 <= '1'; else cnt:=cnt+1;key1 <= '0'; end if; end if; else cnt:=0; key1<='0'; end if; end process key_press1; count : process(key1,key2) begin if key1'event and key1='1' then if con=4 then con<=0; else con<=con+1; end if; end if; end process count; con_pro : process(con) begin case con is when 0 => ssl<='1'; sce_reg <= '0';ssen <='1'; mce_reg <= '0';mmen <='1'; hce_reg <= '0';hhen <='1'; clk2hz_en <='0'; when 1 => ssl<='0'; sce_reg <= '0';ssen <='1'; mce_reg <= '0';mmen <='1'; hce_reg <= '0';hhen <='1'; clk2hz_en <='1'; when 2 => ssl<='0'; sce_reg <= '1';ssen <='1'; mce_reg <= '0';mmen <='0'; hce_reg <= '0';hhen <='0'; clk2hz_en <='1'; when 3 => ssl<='0'; sce_reg <= '0';ssen <='0'; mce_reg <= '1';mmen <='1'; hce_reg <= '0';hhen <='0'; clk2hz_en <='1'; when 4 => ssl<='0'; sce_reg <= '0';ssen <='0'; mce_reg <= '0';mmen <='0'; hce_reg <= '1';hhen <='1'; clk2hz_en <='1'; when others => ssl<='0'; sce_reg <= '0';ssen <='1'; mce_reg <= '0';mmen <='1'; hce_reg <= '0';hhen <='1'; clk2hz_en <='0'; end case; end process con_pro; sel_pro : process(ssl) begin case ssl is when '0'=> s_ce<=sce_reg; m_ce<=mce_reg; h_ce<=hce_reg; clk_change<=key2; when '1'=> s_ce<=ssen; m_ce<=mmen; h_ce<=hhen; clk_change<=clk1hz; when others=> s_ce<=ssen; m_ce<=secout; h_ce<=minout; clk_change<=clk1hz; end case; end process sel_pro; sel<=ssl;s_en<=ssen;m_en<=mmen;h_en<=hhen; end beh;输入模块电路图:2.4数码管分配程序代码:library ieee;use ieee.std_logic_1164.all;entity display isport(datain : in std_logic_vector(3 downto 0);dataout : out std_logic_vector(7 downto 0));end display;architecture duan of display isbegin process(datain) begin case datain is when "0000" => dataout <="11000000"; --dp,g,f,e,d,c,b,a when "0001" => dataout <="11111001"; when "0010" => dataout <="10100100"; when "0011" => dataout <="10110000"; when "0100" => dataout <="10011001"; when "0101" => dataout <="10010010"; when "0110" => dataout <="10000010"; when "0111" => dataout <="11111000"; when "1000" => dataout <="10000000"; when "1001" => dataout <="10010000"; when "1010" => dataout <="10111111"; when "1011" => dataout <="10000011"; when "1100" => dataout <="10100111"; when "1101" => dataout <="10100001"; when "1110" => dataout <="10000110"; when "1111" => dataout <="10001110"; when others => null; end case; end process; end ;输入模块电路图:2.5显示模块使用七段数码管显示小时、分钟与秒程序代码:library ieee;use ieee.std_logic_1164.all;entity scan isport(clk1khz : in std_logic;sl,sh,ml,mh,hl,hh : in std_logic_vector(3 downto 0);clk2hz_en : in std_logic;s_ce,m_ce,h_ce : in std_logic;en_out : out std_logic_vector(7 downto 0);dataout : out std_logic_vector(3 downto 0));end scan;architecture beh of scan issignal cnt : integer range 0 to 7;signal en : std_logic_vector(7 downto 0);signal clk2hz : std_logic; signal h_ce_reg,m_ce_reg,s_ce_reg : std_logic;begin h_ce_reg <= not h_ce; m_ce_reg <= not m_ce; s_ce_reg <= not s_ce; cnt_pro : process(clk1khz) begin if clk1khz'event and clk1khz='1' then if cnt = 7 then cnt <= 0; else cnt <= cnt + 1; end if; end if; end process cnt_pro; clk2hz_pro :process(clk1khz) variable c : integer range 0 to 499 := 0; begin if clk1khz'event and clk1khz='1' then if clk2hz_en ='1' then if c =499 then c := 0 ; clk2hz <= not clk2hz; else c := c + 1; end if; else clk2hz <= '0'; end if; end if; end process clk2hz_pro; scan_pro : process(cnt,sl,sh,ml,mh,hl,hh) begin case cnt is when 0 => dataout <= sl;en <= "11111110"; when 1 => dataout <= sh;en <= "11111101"; when 2 => dataout <= ml;en <= "11110111"; when 3 => dataout <= mh;en <= "11101111"; when 4 => dataout <= hl;en <= "10111111"; when 5 => dataout <= hh;en <= "01111111"; when 6 => dataout <= "1010";en <= "11111011"; when 7 => dataout <= "1010";en <= "11011111"; when others => null; end case; end process scan_pro; en_out <= en or ((clk2hz & clk2hz) or (h_ce_reg & h_ce_reg)) & clk2hz & ((clk2hz & clk2hz) or (m_ce_reg & m_ce_reg)) & clk2hz & ((clk2hz & clk2hz) or (s_ce_reg & s_ce_reg)); end beh;输入模块电路图:2.6报时模块利用蜂鸣器进行整点报时程序代码:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use IEEE.STD_LOGIC_ARITH.ALL; --整点报时 entity baoshi isport(clk1khz,clk2khz : in std_logic;a:in std_logic_vector(15 downto 0);sel:in std_logic;bell:out std_logic); end baoshi; architecture zhong of baoshi is signal c1,ring:std_logic; begin ring_bell :process(clk1khz,clk2khz) begin case a is when "0101100101010000" => c1<=clk1khz; when "0101100101010010" => c1<=clk1khz; when "0101100101010100" => c1<=clk1khz; when "0101100101010110" => c1<=clk1khz; when "0101100101011000" => c1<=clk1khz; when "0000000000000000" => c1<=clk2khz; when "0011000000000000" => c1<=clk2khz; when others => c1<='0'; end case; end process ring_bell; bs: process(c1) begin if sel='1' then if c1='1' then ring<='0'; else ring<='1'; end if; end if; end process bs; bell<=ring; end zhong; 输入模块电路图:整体模块电路图六、调试中遇到的问题及解决的方法:1、编程时,经常导致语法错误,如:“;”没有写上,变量类型没有预先标明,前后变量名字由于缺少一个或多一个字母而导致出错。

解决办法:对照错误,认真检查程序,看哪个地方的标点,变量没有写上或标明2、进行编译或波形仿真时,经常得到的不是预想中的结果解决办法:将需要编译或进行仿真的实体文件置顶,经检错无误后,进行波形仿真,在仿真之前需要合理设置仿真结束时间和信号周期3、在控制时间的显示的时候,由于变量太多多发现不能完全的控制住变量,导致显示的时候出现了乱码,数码管显示不正常解决办法:减少变量,仔细推敲,合理命名七、心得体会一个多星期的课程设计让我受益匪浅,也让我真正明白理论与。

下载提示
相关文档
正为您匹配相似的精品文档