您的当前位置:首页正文

EDA课程设计电子时钟

来源:帮我找美食网


EDA技术课程设计

课题: 电子时钟

系 别: 电气与电子工程系 专 业: 电子信息工程 姓 名: 学 号: 指导教师:

河南城建学院

2012年6月 日

成绩评定·

一、指导教师评语(根据学生设计报告质量、答辩情况及其平时表现综合

评定)。

二、课程设计评分

成绩:

2

2012年 6月 日

目 录

一、设计目的................................................................................ 错误!未定义书签。 二、设计要求................................................................................ 错误!未定义书签。 三、总体设计方案要求................................................................ 错误!未定义书签。

1、设计的总体原理 ............................................................ 错误!未定义书签。 2、设计内容 ........................................................................................................ 1 四、EDA设计与仿真 .................................................................................................... 2

1、秒计时器模块 ................................................................................................ 2 2、分计数器模块 ................................................................................................ 4 3、时计数器模块 ............................................................................................... 6 4、分频器模块 ................................................................................................... 8 5、扫描电路模块 ............................................................................................... 9 6、译码显示器模块 ......................................................... 错误!未定义书签。1 7、系统设计 ..................................................................... 错误!未定义书签。3 五、硬件实现.............................................................................. 错误!未定义书签。6

1、硬件实现步骤 ............................................................. 错误!未定义书签。6 2、硬件实现结果 ............................................................. 错误!未定义书签。6 六、设计总结.............................................................................. 错误!未定义书签。8 七、参考文献.............................................................................. 错误!未定义书签。8 八、设计生成的电路总图.......................................................... 错误!未定义书签。8

3

一、设计目的

这次课程设计主要是培养我们的实际动手能力及对EDA这门课程的深入的理解,增强我们对EDA程序设计流程的掌握。这个课题还要求我们掌握计数器的设计,六十进制计数器和二十四进制计数器的设计方法,以及各个进制之间的连接关系。

二、设计要求

1、具有时、分、秒,计数显示功能,以二十四时制循环计; 2、设置启动、暂停开关,以满足启动计时和停止计时的功能; 3、要求计时精度为0.01秒,最长时间为24H。

4、具有时间设置(清零、调节小时和分功能)和闹钟功能;(扩展功能选作) 5、整点报时,整点报时的同时,LED灯花样显示或者给段动听音乐;(扩展功能选作)

三、总体设计方案要求

1.设计的总体原理

要实现一个数字时钟系统,整个系统由主要模块电路模块和外部输入输出以及显示模块组成。首先分别实现单个模块的功能,然后再通过级联组合的方式实现对整个系统的设计。原理框图如下:

图3-1.总体设计框图 2.设计内容

电子时钟主要模块有四个,它包括脉冲信号产生模块(即分频电路)、计数模块(计数模块又分为秒计数模块、分计数模块和时计数模块)、码显示模块、复位模块。各个模块先用EDA技术中的VHDL语言编程仿真,再生成各个小模块的

4

模拟元件,再元件例化,根据设计连接电路实现数字电子钟系统。

四、EDA设计及仿真(各个模块设计程序、原理框图及仿真波形图)

1.秒计时器(second) library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity second is

port(clk,reset:in std_logic;

sec1,sec2:out std_logic_vector(3 downto 0); ---------秒计数器的两个输出; cin:out std_logic); end second;

architecture second1 of second is

signal sec1_t,sec2_t:std_logic_vector(3 downto 0); ---------秒计数器的中间信号; begin

process(clk,reset) begin

if reset='1'then

sec1_t<=\"0000\"; ----------复位信号为1时秒信号复位; sec2_t<=\"0000\";

elsif clk'event and clk='1'then if sec1_t=\"1001\"then

sec1_t<=\"0000\"; ------秒计数器的个位为9时变为0; if sec2_t=\"0101\"then

sec2_t<=\"0000\"; ------秒计数器的十位为5时变为0; else

sec2_t<=sec2_t+1; -----秒计数器的十位不为5时加1; end if; else

sec1_t<=sec1_t+1; -----秒计数器的个位不为9时加1;

5

end if;

if sec1_t=\"1001\" and sec2_t=\"0101\"then ----------当计数器数值为59时向分

为进1;

cin<='1'; ---------向分进1,作为分的时钟信号; else cin<='0'; end if; end if; end process; sec1<=sec1_t; sec2<=sec2_t; end second1;

secondclkresetsec1[3..0]sec2[3..0]cininst

图4-1 秒计数器框图

图4-2 秒计数器时序仿真图

秒计数器的波形分析:由程序及仿真波形图可以看出该计数器是59进制计数器,当sec1计数到9是sec2增加1,而sec1变为0,当sec2增加到5,而且sec1为9时,sec1,sec2变为0,cin1增加1向分计数器进位,提供一个分计数器的时钟信号。

6

2. 分计数器(minute) 分同秒计时器一样 library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity minute is

port(clk,reset:in std_logic;

min1,min2:out std_logic_vector(3 downto 0); --------秒计数器的两个输出; cin1:out std_logic); end minute;

architecture minute1 of minute is

signal min1_t, min2_t:std_logic_vector(3 downto 0); begin

process(clk,reset) begin

if reset='1'then

min1_t<=\"0000\"; --------复位信号为1是分的信号复位为0; min2_t<=\"0000\";

elsif clk'event and clk='1'then if min1_t=\"1001\"then

min1_t<=\"0000\"; --------分计数器的个位为9时变为0; if min2_t=\"0101\"then

min2_t<=\"0000\"; --------分计数器的个位为5时变为0; else

min2_t<= min2_t+1; --------分计数器的十位不为5时加1; end if; else

min1_t<= min1_t+1; --------分计数器的个位不为9时加1; end if;

if min1_t=\"1001\" and min2_t=\"0101\"then -----计数器的值到59是向时进1;

7

cin1<='1'; ------向时的进位,相当于时的时钟信号; else cin1<='0'; end if; end if; end process;

min1<=min1_t; ----------把中间信号的值付给分信号; min2<=min2_t; end minute1;

minuteclkresetmin1[3..0]min2[3..0]cin1inst

图4-3 分计数器的原理框图

图4-4 分计数器的时序仿真波形图

图4-5 分计数器程序错误显示图

分计数器波形分析:在刚开始的仿真时,程序出现了一点的错误,引起错误

8

的原因是min 1,min 2这两个信号的声明是错误的,正确的声明方法是min1,min2。经过改正后程序是正确的,正确的波形显示该计数器和秒计数器是59进制计数器,当min1计数到9是min2增加1,而min1变为0,当min2增加到5,且min1增加到9时,min1,min2变为0,cin2增加1向时计数器进位,提供一个时计数器的时钟信号。 3. 时计时器(hour) library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;

entity hour is

port (clk,reset:in std_logic;

hour1,hour2:out std_logic_vector(3 downto 0)); ------时计数器的两个输出信号 end hour;

architecture hour1 of hour is

signal hour1_t,hour2_t:std_logic_vector(3 downto 0); begin

process(clk,reset) begin

if reset='1'then hour1_t<=\"0000\"; hour2_t<=\"0000\"; elsif clk'event and clk='1'then

if hour1_t=\"0011\" and hour2_t=\"0010\"then

hour1_t<=\"0000\"; ---------当时计数器的值达到23是,当分秒计数器都到59时时计数器变为0; hour2_t<=\"0000\"; else

if hour1_t=\"0011\"then

9

hour1_t<=\"0000\"; --------当时计数器的个位为3时值变为0; if hour2_t=\"0010\"then

hour2_t<=\"0000\"; --------当时计数器的个位变2时值变为0; else

hour2_t<=hour2_t+1; --------当时计数器的十位不为2时值加1; end if; else

hour1_t<=hour1_t+1; --------当时计数器的个位不为3时值加1;

end if; end if; end if;

end process; hour1<=hour1_t; hour2<=hour2_t; end hour1;

hourclkresethour1[3..0]hour2[3..0]inst

图4-6 时计数器原理框图

图4-7 时计数器时序仿真波形图

时波形图分析:由程序及时序仿真波形图可以知道该时计数器是二十四进制计数器,当hour1计数到3是hour2增加1,而hour1变为0,当hour2增加到2,且hour1

10

增加到3时,hour2变为0,hour1也变为0。 4. 分频器(freq_divider) library IEEE;

use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity freq_divider is

port (reset,clk : in STD_LOGIC; Q: out STD_LOGIC); end freq_divider;

architecture freq_divider1 of freq_divider is signal count50 : integer range 0 to 49; signal out1:std_logic; begin

process (reset,clk) begin

if reset='1' then count50<=0; elsif clk'event and clk='1'then

count50<= count50 + 1 ; -----当时钟周期小于50是信号来时加1;

out1<= out1;

if count50=49 then

count50<=0;

-------50个时钟周期后计数器清零;

out1<=not out1; -------当时钟周期达到50是输出信号反相,即有高电平

变低电平或有低电平变高电平;

end if ; end if;

Q<= out1; -------把中间信号的值赋给总输出; end process; end freq_divider1;

11

freq_dividerresetclkQinst

图4-8 分频器的原理框图

图4-9 分频器的时序仿真波形图

图4-10 分频器程序错误显示图

分频器波形分析:在第一次仿真是显示程序是错误的,进过更改及调试程序正确了,由程序及时序仿真图可以知道该分频器是100倍分频,由于该设计的目的是设计一个数字电子钟,可知时钟需要一个1s的时钟信号,必须用到分频器,该分频器的时钟信号的周期是100ns,经过三次次100倍分频,可以得到1s的时钟信号。也就是说在这个程序中要用到三个这样的分频器。

5、扫描模块源程序 library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;

12

entity mux6 is

port(clkscan,reset:in std_logic;

in1,in2,in3,in4,in5,in6:in std_logic_vector(3 downto 0); BT:out std_logic_vector(7 downto 0);------显示控制信号输出 A:out std_logic_vector(3 downto 0));-------数码管显示数值输出

end mux6;

architecture mux60 of mux6 is

signal cnt8:std_logic_vector(2 downto 0); begin

process(clkscan,reset) begin

if reset='1'then

cnt8<=\"000\";-------异步复位

elsif clkscan'event and clkscan='1'then----------检测时钟上升沿

if cnt8=\"111\"then cnt8<=\"000\"; else

cnt8<= cnt8+1;---------六进制计数器 end if; end if; end process; process(cnt8) begin

case cnt8 is

when \"000\" => BT <= \"\" ; A <=in1;

13

when \"001\" => BT <= \"\" ; A <=in2; when \"010\" => BT <= \"\" ; A <=in3; when \"011\" => BT <= \"\" ; A <=in4; when \"100\" => BT <= \"\" ; A <=in5; when “101”=> BT <= \"\" ; A <=in6; when “110”=> BT <= \"\";A<=“0000” ;

when “111”=> BT <= \"\";A<=“0000” ; ----------数据选择输出 end case ; end process; end mux60;

图4-11 多路复用器的原理框图

图4-12 多路复用器的时序仿真波形图

波形图的分析:由以上的程序和波形图可以看出来,当sel=0时,多路复用器选择的是in1,当sel=1时选择的是in2,当sel=2是选择的是in3,当sel=3时选择的是in4,当sel=5时选择的是in5.

6. 译码显示模块的VHDL程序(yima.vhd) library ieee;

use ieee.std_logic_1164.all; entity yima is

14

port(BT:in std_logic_vector(3 downto 0); LED7:out std_logic_vector(6 downto 0)); end yima;

architecture behav of yima is begin process(BT) begin case BT is

when \"0000\"=> LED7<=\"\"; when \"0001\"=> LED7<=\"\"; when \"0010\"=> LED7<=\"\"; when \"0011\"=> LED7<=\"\"; when \"0100\"=> LED7<=\"\"; when \"0101\"=> LED7<=\"\"; when \"0110\"=> LED7<=\"\"; when \"0111\"=> LED7<=\"\"; when \"1000\"=> LED7<=\"\"; when \"1001\"=> LED7<=\"\"; when others=> LED7<=\"\"; end case; end process; end behav;

yimaBT[3..0]LED7[6..0]inst 图4-13 译码显示电路的原理框图

15

图4-16 译码显示电路的时序仿真波形图

7、系统设计

将上述5个程序作为底层文件,存放在同一个文件夹中,然后按下面的图将这几个文件连接起来,并用元件例化语句编写顶层文件的程序, 如下:总程序(前面的分模块程序省略,下面只写了原件例化得程序) ------------------my_components.vhd(package)------------------ library IEEE;

use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all;

------------------------------------------------------------ package my_components is

---------------------------------------------------- component second is port(clk,reset:in std_logic;

sec1,sec2:out std_logic_vector(3 downto 0); cin:out std_logic); end component;

----------------------------------------------------- component minute is port(clk,reset:in std_logic;

min1,min2:out std_logic_vector(3 downto 0); cin1:out std_logic);

16

end component;

-------------------------------------------------------- component hour is port (clk,reset:in std_logic;

hour1,hour2:out std_logic_vector(3 downto 0)); end component;

---------------------------------------------------------- component freq_divider is port (reset,clk : in STD_LOGIC; Q: out STD_LOGIC); end component;

-------------------------------------------------------- component mux6 is

port(clkscan,reset:in std_logic;

in1,in2,in3,in4,in5,in6:in std_logic_vector(3 downto 0); BT:out std_logic_vector(7 downto 0); A:out std_logic_vector(3 downto 0)); end component;

--------------------------------------------------------- component yima is

port(BT1:in std_logic_vector(3 downto 0); LED7:out std_logic_vector(6 downto 0)); end component;

--------------------------------------------------------- end my_components;

--------------------------------------------------------- ------------------time----------------------------------- library IEEE;

use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all;

17

use IEEE.std_logic_unsigned.all; use work.my_components.all;

--------------------------------------------------------- entity time is

port(clk,clkscan,reset:in std_logic;

LED7:out std_logic_vector(6 downto 0); BT:out std_logic_vector(7 downto 0)); end time;

--------------------------------------------------------- architecture structural of time is signal x3,x4,x5:std_logic;

signal x6,x7,x8,x9,x10,x11,x12:std_logic_vector(3 downto 0); begin

u1:component second port map (x3,reset,x6,x7,x4); u2:component minute port map (x4,reset,x8,x9,x5); u3:component hour port map(x5,reset,x10,x11); u4:component freq_divider port map(clk,reset,x3);

u5:component mux6 port map(clkscan,reset,x6,x7,x8,x9,x10,x11,BT,x12); u6:component yima port map(x12,LED7); end structural;

----------------------------------------------------------

图4-17 总程序的时序仿真波形图

程序仿真波形图分析:在这个程序中两个时钟信号clk,clkscan是不同频率的,

18

clk时钟信号控制秒计数器,它的周期是100ns,而clkscan控制着整个程序,它的频率可以是任意设定的。

五、硬件实现

1、给出硬件实现 实验步骤:

⑴打开QuartusⅡ9.0软件,建立进程,进程的名字和程序的名字相同; ⑵打开新建选择VHDL File,然后把程序输入进去; ⑶保存文件点击软件页面上方的编译按键进行编译;

⑷编译成功后,进行软件仿真,点击File选择Vector Waveform File,然后点击鼠标右键选inset node or bus键,把脚码输入进去,再进行脚码设定; ⑸然后保存,点击Assigment中的settings选择时序仿真,进行程序的时序仿真;

⑹时序仿真成功后,点击上方Assigment Editor键进行脚码锁定;脚码锁定中我们用了模式六。

图5-1 脚码锁定图

2.硬件仿真结果

在这次设计中刚开始由于种种原因我们的硬件仿真结果没能够正常的显示出来,经多次的努力我们修改了程序后,最终仿真结果显示是正确的。下面我照了一些我们仿真的硬件结果,如下图所示:

19

图5-2 硬件仿真结果图示一

图5-3 硬件仿真结果图示二

图5-4 硬件仿真结果图示三

图5-5 硬件仿真结果图示四

20

六、设计总结

在这次设计过程中,我们在老师的指导下对VHDL这门课程逐步加深了了解,但是在设计中遇到很多问题,其中在程序设计方面的问题在我们查阅资料后的到了解决,在程序软件的实现过程中所遇到的问题最后也得到了圆满的解答,但是在程序最后的硬件仿真过程中遇到的问题还是没能够得到解决,这也是这次课程设计中的遗憾之处。

计数器的设计并不困难,就是用了三个计数器,其中秒和分计数器是六十进制计数器,时计数器是二十四计数器,并且秒和分各有一个进位端,秒到59时向分进一位,分到59时向时进一位,这个设计中的主要问题是时分秒与一码电路的连接,在这里我们用到了动态扫描电路,在脚码锁定时我们用了模式六,但是结果不理想,这次设计的硬件仿真结果不理想。

经过这次课程设计我还得到了一点感想,无论我们做什么事情都要懂得团结,在生活中我们自己的力量是极其薄弱的,有时候只有我们大家团结一致才能攻克所有困难,战无不胜。

七.参考文献

⑴ ,基于EDA的数字电子钟的实现;

⑵ Volnei A.Pedroni.VHDL 数字电路设计教程.电子工业出版社; ⑶ 杭州康芯电子有限公司.EDA技术实验讲义;

八、设计生成的电路图

附表:程序生成电路总图

21

因篇幅问题不能全部显示,请点此查看更多更全内容

Top