1、EDA实验报告60S电子闹钟 EDA实验报告 题 目 60秒电子闹钟 学 院 电子工程学院 专 业 学生姓名 导师姓名 初秀琴 一 功能描述电路上电后自动计时,到达预置的闹响时刻后,由扬声器发出音乐报警。闹响时刻可利用DIP开关设置,两位数:059。二 设计思路电路主要由分频器、M60计数器、闹铃电路、显示电路等部分组成。秒信号脉冲可由分频器产生,用DIP开关设置闹响时刻,当M60计数器的输出与设置的闹响时刻相等时,闹铃电路输出脉冲驱动扬声器发出音乐报警。总体设计思路如图1所示:图1 总体设计思路三 功能模块1 分频器程序代码如下:library ieee;use ieee.std_logic
2、_1164.all;use ieee.std_logic_unsigned.all;entity devide isport( clk :in std_logic; -输入时钟 clk_out :out std_logic -输出信号 );end devide;architecture arc_devide of devide is signal count:std_logic_vector (14 downto 0); -定义内部信号 begin process begin wait until clkevent and clk=1; if(count32767)then -改变最大计数值即
3、可得到不同的分频系数 count=count+1; clk_out=1; end if; end process;end architecture arc_devide;符号图如图2所示:图2 分频器符号图2 M60计数器程序代码如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity bcd_m60 isport ( CLK :in std_logic; EN :in std_logic; CR :in std_logic; QL,QH :out std_logic_vector(3
4、downto 0) -8421BCD码个位、十位输出 );end bcd_m60;architecture behav of bcd_m60 is signal couL,couH:std_logic_vector(3 downto 0);begin process(CR,CLK) begin if CR=0 then -异步复位 couL=0000; couH=0000; elsif clkevent and clk=1 then if EN=1 then if (couL=9 and couH=5) then -个位计到9十位计到5回零 couL=0000; couH=0000; elsi
5、f couL=9 then -个位计到9回零十位加1 couL=0000; couH=couH+1; else couL=couL+1; -否则个位加1 end if; end if; end if; end process; QL=couL; QH=couH; end behav;符号图如图3所示:图3 M60计数器符号图仿真波形如图4所示:图4 M60计数器仿真波形经分析,M60计数器仿真波形正确。3 闹铃电路程序代码如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity aler
6、t isport ( STOP :in std_logic; -控制是否响铃 CLK :in std_logic; DIPL,DIPH :in std_logic_vector(3 downto 0); QL,QH :in std_logic_vector(3 downto 0); SPEAK :out std_logic );end alert;architecture behav of alert isbegin process(STOP,CLK,QL,QH) begin if STOP=0 then SPEAK=0; elsif QL=DIPL and QH=DIPH then -输出脉
7、冲驱动扬声器 SPEAK tmp tmp tmp tmp tmp tmp tmp tmp tmp tmp tmp tmp tmp tmp tmp tmp null; end case; end process; a=tmp(6); b=tmp(5); c=tmp(4); d=tmp(3); e=tmp(2); f=tmp(1); g=tmp(0);end arc;符号图如图6所示:图6 显示电路符号图四 总体仿真顶层文件原理图如图7所示:图7 顶层文件原理图仿真波形如图8所示:如图8所示,当M60计数器计数与置入时刻相等时,SPEAKOUT为脉冲,驱动扬声器发声,从而实现报警。五 心得体会学习quartus II 的使用花了相当长的时间,虽然最后做出来的电路比较简单,但感觉很有成就感,因为这是我慢慢摸索得到的成果。