EDA 课程设计报告书课题名称 数字钟的设计 姓 名王砾学 号 0812201-37 院 系 物理与电信工程系 专 业 电子信息工程 指导教师周来秀讲师2011年 6月13日※※※※※※※※※ ※※ ※※ ※※2008级学生EDA 课程设计数字钟的设计王砾(湖南城市学院物理与电信工程系电子信息工程专业,湖南益阳,41300)1设计目的1,熟练的运用数字系统的设计方法进行数字时钟设计2,能进行较复杂的数字系统设计3,按要求设计一个数字钟2设计的主要内容和要求a.计时计数器用24进制计时器电路。
b.可手动校时,能清零及分别进行时、分、秒的校正。
c.可整点报时,扬声器发出时长为1s的信号。
d.可设置闹钟功能。
当计时计到预定时间时,扬声器发出闹铃信号,可控制闹铃时长。
3 整体设计方案基于VHDL 语言,用Top_Down 的思想进行设计,其中计数模块、闹铃模块、定时模块、显示模块为主要模块,选择模块为辅助模块。
选择模块定时模块显示模块闹铃模块计数模块选择模块数码显示管4 硬件电路的设计4.1如下分别为60与24进制模块的代码: library ieee;use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity count_60 isport(en1,en2,clr,clk : in std_logic; rco : out std_logic;q1,q2 : out std_logic_vector(3 downto 0));end count_60;architecture behav of count_60 issignal iq1,iq2 : std_logic_vector(3 downto 0); beginprocess(en1,en2,clr,clk) beginif(clr='1')then iq1<="0000"; iq2<="0000";elsif(clk='1' and clk'event)thenif(en1 or en2)='1'thenif(iq2>=5)thenif(iq1>=9)theniq1<="0000";iq2<="0000";elseiq1<=iq1+1;end if;elseiq2<=iq2+1;end if;end if;end if;if(iq2=5 and iq1=9 and en1='1')thenrco<='1';else rco<='0';end if;q1<=iq1;q2<=iq2;end process;end behav;library ieee;use ieee.std_logic_1164.all;entity count_24 isport(en1,en2,clr,clk : in std_logic;q1,q2 : out std_logic_vector(3 downto 0)); end count_24;architecture behav of count_24 issignal iq1,iq2 : std_logic_vector(3 downto 0);beginprocess(en1,en2,clr,clk)beginif(clr='1')theniq1<="0000";iq2<="0000";elsif(clk='1' and clk'event)thenif(en1 or en2)='1'thenif(iq2>=2)thenif(iq1>=3)theniq1<="0000";iq2<="0000";elseiq1<=iq1+1;end if;elseiq2<=iq2+1;end if;end if;end if;q1<=iq1;q2<=iq2;end process;end behav;然后将各模块进行组合,形成计数模块和定时模块,其组合方式如图所示:d[3..0]p[6..0]displayinst4生成的计数模块与定时模块的元件符号分别如下图:4.2显示模块为六个时、分、秒的十位与个位的显示模块组成的,即六个七段译码器。
将输入的4位BCD 码进行译码,输出7位,p0~p6分别外接数码管a~g 段,如下为七段译码器代码: library ieee;use ieee.std_logic_1164.all; entity display isport(d : in std_logic_vector(3 downto 0);p : out std_logic_vector(6 downto 0));end display;architecture behav of display isbeginwith d selectp<="0111111"when"0000","0000110"when"0001","1011011"when"0010","1001111"when"0011","1100110"when"0100","1101101"when"0101","1111101"when"0110","0000111"when"0111","1111111"when"1000","1101111"when"1001","0000000"when others;end behav;再用六个七段译码器组合成同时能够显示时、分、秒的十位与个位的模块,其组合方式和生成元件符号如图所示:V C C m i n E [3..0]I N P U TV C C s e c E [3..0]I N P U TV C C h r _10E [3..0]I N P U TV C C h r E [3..0]I N P U TV C C m i n _10E [3..0]I N P U TV C Cs e c _10E [3..0]I N P U Th r [6..0]O U T P U Tm i n [6..0]O U T P U Ts e c [6..0]O U T P U Th r _10[6..0]O U T P U Tm i n _10[6..0]O U T P U Ts e c _10[6..0]O U T P U Td [3..0]p [6..0]d i s p l a yi n s t 6d [3..0]p [6..0]d i s p l a yi n s t 7d [3..0]p [6..0]d i s p l a yi n s t 8d [3..0]p [6..0]d i s p l a yi n s t 9d [3..0]p [6..0]d i s p l a yi n s t 10d [3..0]p [6..0]d i s p l a yi n s t 114.3定时报时模块具有闹钟和整点报时的功能。
实现整点报时功能是判断当前时若为整点则发出闹铃信号激发扬声器使其鸣响。
实现闹钟功能与它相似,是将判断是否为整点改成判断当前时间是否与既定时间相同。
为了实现控制闹铃时长,可考虑用D 触发器,将与定时时间相同时进行循环。
报时模块代码和实现可控制闹铃的组装方式分别如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity bell isport(hr_10C,hrC,min_10C,minC,sec_10C,secC : in std_logic_vector(3 downto 0);clk,alarm : in std_logic; hr_10D,hrD,min_10D,minD,sec_10D,secD : std_logic_vector(3 downto 0);sign,ring : out std_logic); end bell;architecture behav of bell is beginprocess(clk,alarm,hr_10C,hrC,min_10C,minC,sec_10C,secC,hr_10D,hrD,min _10D,minD,sec_10D,secD) variable tip : std_logic; beginif(min_10C=0 and minC=0 and sec_10C=0 and secC=0)then tip:='1'; else tip:='0'; end if;if(hr_10C=hr_10D and hrC=hrD and min_10C=min_10D and minC=minD and sec_10C=sec_10D and secC=secD)then sign<='1'; else sign<='0'; end if;if(clk='1' and clk'event)thenif(tip='1' or alarm='1')then ring<='1'; else ring<='0'; end if; end if; end process; end behav;4.4组合时间计数模块、显示模块、定时报时模块,构成数字钟的原理图。
考到计数模块与定时模块相类功能可以共用同一接口,以减少接口与器材。
如下为两个选择模块的代码: entity selectionA isport(sel,C0,C1,C2,C3 : in bit; A0,A1,A2,A3 : out bit; B0,B1,B2,B3 : out bit); end selectionA;architecture behav of selectionA is beginprocess(sel,C0,C1,C2,C3) beginif(sel='0')then A0<=C0;B0<='0'; A1<=C1;B1<='0'; A2<=C2;B2<='0'; A3<=C3;B3<='0'; elseB0<=C0;A0<='0'; B1<=C1;A1<='0'; B2<=C2;A2<='0'; B3<=C3;A3<='0';end process;end behav;library ieee;use ieee.std_logic_1164.all;entity selectionB isport(A0,A1,A2,A3,A4,A5 : in std_logic_vector(3 downto 0);sel : in std_logic;B0,B1,B2,B3,B4,B5 : in std_logic_vector(3 downto 0); C0,C1,C2,C3,C4,C5 : out std_logic_vector(3 downto 0));end selectionB;architecture behav of selectionB isbeginprocess(sel,A0,A1,A2,A3,A4,A5,B0,B1,B2,B3,B4,B5)beginC0<=B0;C1<=B1;C2<=B2;C3<=B3;C4<=B4;C5<=B5;elseC0<=A0;C1<=A1;C2<=A2;C3<=A3;C4<=A4;C5<=A5;end process;end behav;4.5将所有设计好的模块有序地进行组合,形成数字钟的原理图,其中CLK_A接入的时钟信号为1Hz脉冲,CLK_B接入的时钟信号频率较高的脉冲(如500Hz)如图所示:5系统仿真6设计总结通过这次课程设计,我进一步加深了对电子设计自动化的了解。