基于FPGA的数字时钟的设计1_第1页
基于FPGA的数字时钟的设计1_第2页
基于FPGA的数字时钟的设计1_第3页
基于FPGA的数字时钟的设计1_第4页
基于FPGA的数字时钟的设计1_第5页
已阅读5页,还剩20页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、数 字 电 路 课 程 设 计基于FPGA的数字时钟的设计课 题: 基于FPGA的数字时钟的设计 学 院: 电气信息工程学院 专 业 : 测量控制与仪器 班 级 : 08测控(2)班 姓 名 : 潘 志 东 学 号 : 08314239 合作者姓名: 颜志林 2010 年 12 月 12 日综述近年来随着数字技术的迅速发展,各种中、大规模集成电路在数字系统、控制系统、信号处理等方面都得到了广泛的应用。这就迫切要求理工科大学生熟悉和掌握常用中、大规模集成电路功能及其在实际中的应用方法,除通过实验教学培养数字电路的基本实验方法、分析问题和故障检查方法以及双踪示波器等常用仪器使用方法等基本电路的基本

2、实验技能外,还必须培养大学生工程设计和组织实验能力。本次课程设计的目的在于培养学生对基本电路的应用和掌握,使学生在实验原理的指导下,初步具备基本电路的分析和设计能力,并掌握其应用方法;自行拟定实验步骤,检查和排除故障 、分析和处理实验结果及撰写实验报告的能力。综合实验的设计目的是培养学生初步掌握小型数字系统的设计能力,包括选择设计方案,进行电路设计、安装、调试等环节,运用所学知识进行工程设计、提高实验技能的实践。数字电子钟是一种计时装置,它具有时、分、秒计时功能和显示时间功能;具有整点报时功能。本次设计我查阅了大量的文献资料,学到了很多关于数字电路方面的知识,并且更加巩固和掌握了课堂上所学的课

3、本知识,使自己对数字电子技术有了更进一步的认识和了解。1、 课题要求1.1课程设计的性质与任务本课程是电子与信息类专业的专业的专业基础必修课“数字电路”的配套实验课程。目的在于培养学生的理论联系实际,分析和解决问题的能力。通过本课程设计,使学生在理论设计、计算机仿真、指标调测、故障排除等方面得到进一步的训练,加强学生的实践能力。学生通过设计、仿真、调试、撰写设计报告等过程,培养学生的动手能力和严谨的工作作风。1.2课程设计的基本技术要求1)根据课题要求,复习巩固数字电路有关专业基础知识;2)掌握数字电路的设计方法,特别是熟悉模块化的设计思想;3) 掌握QUARTUS-2软件的使用方法;4) 熟

4、练掌握EDA工具的使用,特别是原理图输入,波形仿真,能对仿真波形进行分析;5) 具备EDA技术基础,能够熟练使用VHDL语言进行编程,掌握层次化设计方法;6) 掌握多功能数字钟的工作原理,学会不同进制计数器及时钟控制电路的设计方法;7) 能根据设计要求对设计电路进行仿真和测试;8) 掌握将所设计软件下载到FPGA芯片的下载步骤等等。9) 将硬件与软件连接起来,调试电路的功能。1.3课程设计的功能要求基本功能:能进行正常的时、分、秒计时功能,分别由6个数码管显示24小时,60分钟,60秒钟的计数器显示。附加功能:1)能利用硬件部分按键实现“校时”“校分”“清零”功能; 2)能利用蜂鸣器做整点报时

5、:当计时到达5959时开始报时,鸣叫时间1秒钟; 3)定时闹铃:本设计中设置的是在七点时进行闹钟功能,鸣叫过程中,能够进行中断闹铃工作。本人工作:负责软件的编程与波形的仿真分析。2、 方案设计与分析1.1设计方案 1、时钟功能,具有显示时、分、秒的功能; 2、具有整点报时功能,在整点时使用蜂鸣器进行报时,具有闹钟功能,鸣叫过程中,具有中断闹铃功能。1.2设计要点数字钟一般是由振荡器、分频器、计数器、译码器、显示器等几部分组成。这些都是数字电路中应用最广泛的基本电路,本设计分模块设计实现各部分功能,采用软件编程控制FPGA芯片内部产生振动周期为1s的脉冲。并将信号送入计数器进行计算,并把累加的结

6、果以“时”、“分”、“秒”的数字显示出来。“秒”的显示由两级计数器和译码器组成的六十进制计数电路实现;“分”的显示电路“秒”相同,“时”的显示由两级计数器和译码器组成的二十四进制电路来实现。所有计时结果由六位数码管显示。1.3工作原理数字电子钟由振荡器、分频器 计数器、译码显示、报时等电路组成。振荡器产生稳定的高频脉冲信号,作为数字钟的时间基准,然后经过分频器输出标准秒脉冲。秒计数器满60后向分计数器进位,分计数器满60后向小时计数器进位,小时计数器按照“24翻1”规律计数。计满后各计数器清零,重新计数。计数器的输出分别经译码器送数码管显示,计时出现误差时,可以用校时电路“校时”“校分”“清零

7、”。秒脉冲可以通过分频电路得到。通过报时设计模块可以实现整点报时及定时闹铃,译码显示由七段译码器完成,显示由数码管构成,采用的是动态显示方式。数码管动态显示:动态扫描电路将计数器输出的8421BGD码转换为数码管需要的逻辑状态,并且输出数码管的片选信号和为选信号。所谓动态扫描显示方式是在显示某一位LED显示块的数据的时候,让其它位不显示,然后再显示下一位的数据。只要保证每一位显示的时间间隔不要太大,利用人眼的视觉暂留的现象,就可以造成各位数据同时显示的假象。一般每一位的显示时间为110ms。3、 单元电路的设计,仿真与分析(1)分频模块(fenpin)1)程序:library ieee;use

8、 ieee.std_logic_1164.all;entity fenpin is port(clk6:in std_logic; q1000,q5,q1:out std_logic);end fenpin;architecture ccc_arc of fenpin issignal x:std_logic;begin process(clk6) variable cnt:integer range 0 to 24999; begin if clk6'event and clk6='1' then if cnt<24999 then cnt:=cnt+1; el

9、se cnt:=0; x<=not x; end if; end if;end process;q1000<=x;process(x)variable cnt2:integer range 0 to 999;variable y:std_logic;begin if x'event and x='1' then if cnt2<999 then cnt2:=cnt2+1; q1<='0' else cnt2:=0; q1<='1' end if; end if;if x'event and x=

10、9;1' theny:=not y;end if;q5<=y;end process;end ccc_arc;2)仿真波形:3) 仿真结果分析:产生用于计时,扫描输入,扫描显示,以及蜂鸣器所需的各个频率的信号。(2)秒模块(second)1)程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity second is port (clk1,en1:in std_logic; qa:out std_logic_vector(3 downto 0); co1:out std_l

11、ogic; qb:out std_logic_vector(3 downto 0);end second;architecture cc of second issignal cout2,cout1:std_logic_vector(3 downto 0);signal mm: std_logic;beginprocess(clk1,en1)beginif en1='1' thencout2<="0000"cout1<="0000"elsif (clk1'event and clk1='1')theni

12、f (cout2=1 and cout1=8) then cout2<=cout2;cout1<=cout1+1;mm<='1'elsif (cout2=1 and cout1=9) then cout2<="0000"cout1<="0000"mm<='0'else if (cout1=9) then cout2<=cout2+1;cout1<="0000"mm<='0' else cout2<=cout2;cout1<

13、=cout1+1;mm<='0' end if;end if; end if;end process;co1<=mm;qa<=cout2;qb<=cout1;end cc;2)仿真波形:3) 仿真结果分析:该模块实际是一个六十进制计数器,而六十秒为一分钟,故用此模块可以作为秒部分设计,通过观察可知,仿真波形是正确可行的。(3)分模块(minute)1)程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity minute is port (clk2

14、,en2:in std_logic; qc:out std_logic_vector(3 downto 0); co2:out std_logic; qd:out std_logic_vector(3 downto 0);end minute;architecture bb of minute issignal cout2,cout1:std_logic_vector(3 downto 0);signal cc:std_logic;beginprocess(clk2,en2)beginif en2='1' thenif (clk2'event and clk2='

15、;1')thenif (cout2=1 and cout1=8) then cout2<=cout2;cout1<=cout1+1;cc<='1'elsif (cout2=1 and cout1=9) then cout2<="0000"cout1<="0000"cc<='0'else if (cout1=9) then cout2<=cout2+1;cout1<="0000"cc<='0' else cout2<=co

16、ut2;cout1<=cout1+1;cc<='0' end if;end if;end if; end if;end process;co2<=cc;qc<=cout2;qd<=cout1;end bb2)仿真波形:3) 仿真结果分析:此模块实际也是一个六十进制的计数器模块,六十分钟即为一个小时,用此模块就成功解决了分设计模块这个难题。从仿真波形可知,该设计时正确的。(4)时模块(hour)1)程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;e

17、ntity hour is port (clk3,en3:in std_logic; qe:out std_logic_vector(3 downto 0); qf:out std_logic_vector(3 downto 0);end hour;architecture aa of hour issignal cout2,cout1:std_logic_vector(3 downto 0);beginprocess(clk3,en3)beginif en3='1' thenif (clk3'event and clk3='1')thenif (cou

18、t2=4 and cout1=0) then cout2<="0000"cout1<="0000"else if (cout1=9) then cout2<=cout2+1;cout1<="0000" else cout2<=cout2;cout1<=cout1+1; end if;end if;end if; end if;end process;qe<=cout2;qf<=cout1;end aa;2)仿真波形:3) 仿真结果分析:这是一个24计数器,用来表示24小时,通过波形可知,

19、程序设计正确,正常计时是每次清零后从00:00:00开始计时的,若要从预置时间开始,可以通过“校时”“校分”“清零”三个按键调整时间。(5)数码显示驱动模块1)程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity hhh isport(n1,n2,n3,n4,n5,n6:in std_logic_vector(3 downto 0); a:in std_logic_vector(2 downto 0); qqq:out std_logic_vector(3 downto 0);end

20、 hhh;architecture dd of hhh is begin with a selectqqq<=n1 when "000", n2 when "001", n3 when "010", n4 when "011", n5 when "100", n6 when "101", "0000" when others;end dd;2)仿真波形:3) 仿真结果分析:其实这是一个选择器,从波形图可以很容易看出来。它是用来选择需要显示的数字,比如

21、秒的十位,就会选择n1到译码显示器显示出来,具备驱动数码管的作用!(6)片选模块(sell)1)程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity ggg isport(m:in std_logic_vector(2 downto 0); b:out std_logic_vector(5 downto 0); end ggg;architecture ee of ggg is begin with m selectb<="100000" when &quo

22、t;000", "010000" when "001", "001000" when "010", "000100" when "011", "000010" when "100", "000001" when "101", "000000" when others;end ee;2)仿真波形:3) 仿真结果分析:设置时间时将所需的数据传给显示模块,当设置闹铃时将数据

23、传给闹钟和显示模块。 (7)译码显示模块(display)1)程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity decoder isport(x:in std_logic_vector(3 downto 0); y:out std_logic_vector(6 downto 0); end decoder;architecture one of decoder is begin with x selecty<="1111110" when "0

24、000", "0110000" when "0001", "1101101" when "0010", "1111001" when "0011", "0110011" when "0100", "1011011" when "0101", "1011111" when "0110", "1110000" when "

25、0111", "1111111" when "1000", "1111011" when "1001", "0000000" when others;end one;2)仿真波形:3) 仿真结果分析:此模块是用来显示时间的,采用动态显示方式。(8)报时模块(alart)1) 程序:library ieee;use ieee.std_logic_1164.all;entity sst isport(h1,h0,m1,m0,s1,s0:in std_logic_vector(3 downt

26、o 0);clk4:in std_logic;q500:out std_logic);end sst;architecture sss of sst isbegin process(clk4,m1,m0,s1,s0)beginif (clk4'event and clk4='1') then if (h1="0000" and h0="0111" and m1="0000" and m0="0000") or (m1="0101" and m0="1001&qu

27、ot; and s1="0101" and s0="1001")then q500<='1' else q500<='0'end if;end if;end process;end sss;2) 仿真波形:3) 仿真结果分析:通过观察波形可知,当时钟时间与整点或闹铃预设时间相同时,给出一个脉冲信号,使蜂鸣器鸣叫,实现整点报时和定时闹铃功能。(9)六进制计数器模块(cnt6)1)程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsig

28、ned.all;entity cnt6 is port (clk5:in std_logic; n:out std_logic_vector(2 downto 0);end cnt6;architecture behav of cnt6 issignal q1:std_logic_vector(2 downto 0);beginprocess(clk5)beginif clk5'event and clk5='1' then if q1<5 then q1<=q1+1; else q1<=(others=>'0');end if;

29、end if; end process;n<=q1;end behav;2)仿真波形:3) 仿真结果分析:很明显可以看出这是一个简单的六进制计数器。它与3-6译码器配合作用产生片选信号。(10)两输入与模块(and2a)1)程序:library ieee;use ieee.std_logic_1164.all;entity anda isport (a1,b1:in std_logic; y:out std_logic);end anda;architecture an of anda isbeginy<=a1 and b1;end an;2)仿真波形:3) 仿真结果分析:经观察波

30、形,程序正确。该与门的两个输入端分别为秒模块和分模块的进位输出信号,当它们均为高电平时,时模块使能端即为高电平,时模块工作。(11)两输入或模块(or2a)1)程序:library ieee;use ieee.std_logic_1164.all;entity or_1 isport (a1,b1:in std_logic; y:out std_logic);end or_1;architecture oo of or_1 isbeginy<=a1 or b1;end oo;2)仿真波形:3) 仿真结果分析:在整个数字钟程序设计中,两处用到两输入或门。一处是分模块,或门两输入分别是秒模块

31、的进位输出信号和外部校分信号,任一一个信号为高电平,分模块使能端就为高电平,分模块工作。另一处是在时模块的使能端,它受分模块进位输出和外部校时信号输入的控制,只要其一位高电平,时模块都将工作。4、 顶层电路设计及仿真结果与分析1) 程序:library ieee;use ieee.std_logic_1164.all;entity digital_clock isport(clk,sa,sb,sc:in std_logic; q1:out std_logic; r:out std_logic_vector(5 downto 0); q0:out std_logic_vector(6 downt

32、o 0);end digital_clock;architecture main of digital_clock iscomponent andaport(a1,b1:in std_logic; y:out std_logic);end component;component or_1port(a1,b1:in std_logic; y:out std_logic);end component;component fenpinport(clk6:in std_logic;q1000,q1,q5:out std_logic);end component;component hourport (

33、clk3,en3:in std_logic; qe:out std_logic_vector(3 downto 0); qf:out std_logic_vector(3 downto 0);end component;component minute port (clk2,en2:in std_logic; qc:out std_logic_vector(3 downto 0); co2:out std_logic; qd:out std_logic_vector(3 downto 0);end component;component second port (clk1,en1:in std

34、_logic; qa:out std_logic_vector(3 downto 0); co1:out std_logic; qb:out std_logic_vector(3 downto 0);end component;component sst isport(h1,h0,m1,m0,s1,s0:in std_logic_vector(3 downto 0); clk4:in std_logic; q500:out std_logic);end component;component hhh port(n1,n2,n3,n4,n5,n6:in std_logic_vector(3 do

35、wnto 0); a:in std_logic_vector(2 downto 0); qqq:out std_logic_vector(3 downto 0);end component;component ggg port(m:in std_logic_vector(2 downto 0); b:out std_logic_vector(5 downto 0); end component;component cnt6 is port (clk5:in std_logic; n:out std_logic_vector(2 downto 0);end component;component

36、 decoder port(x:in std_logic_vector(3 downto 0); y:out std_logic_vector(6 downto 0); end component;signal a,b,c,h, i,j,z:std_logic;signal k,l,e,f,u,v,t:std_logic_vector(3 downto 0);signal s: std_logic_vector(2 downto 0);begin u1:fenpin port map(clk6=>clk,q1=>h,q1000=>z);u2:second port map(c

37、lk1=>h,en1=>sc,qa=>k,qb=>l,co1=>I);u0:or_1 port map(a1=>i,b1=>sb,y=>a);u3:minute port map(clk2=>h,en2=>a,qc=>e,qd=>f,co2=>j);u30:anda port map(a1=>i,b1=>j,y=>b);u31:or_1 port map(a1=>b,b1=>sa,y=>c);u4:hour port map(clk3=>h,en3=>c,qe=>

38、u,qf=>v);u5:sst port map(h1=>u,h0=>v,m1=>e,m0=>f,s1=>k,s0=>l,clk4=>h,q500=>q1);u6:hhh port map(n1=>k,n2=>l,n3=>e,n4=>f,n5=>u,n6=>v,qqq=>t,a=>s);u7:ggg port map(b=>r,m=>s);u8:cnt6 port map(n=>s,clk5=>z);u9:decoder port map(x=>t,y=>q

39、0);end architecture main;2) 仿真波形:3)仿真结果分析:本次试验给出的频率是50MHZ,用QUARTUS-2软件把数字钟的全部工作过程记录下来不容易,故这幅图只是其工作的一小部分。将程序下载到FPGA芯片中,并与硬件部分对应连接好,可以验证到我们所预期的所有功能,故可知该顶层文件是正确的,每一个模块的功能也都是正确的,模块之间的连接也都是正确的。在软件调试仿真过程中,我们以参考资料上的程序为模板,依据个人的需要添加修改各个功能模块,尽管有模板作为参考,仿真过程中还是出了很多的问题,例如在做数码管动态显示中,我们采用了NPN型9013晶体三极管作为数码管的接地驱动,这

40、里的片选信号应该是高电平有效,我们原程序是低电平,经过多次的和其他组的学习交流中,找到了这个错误。解决分频问题中,我们也在分频模块中做了修改,得到我们所需要的频率。5、 硬件电路设计与安装电路(1) 按照电路功能设计好硬件部分安装图(电路安装图详见末页图b);(2) 焊接前应先排好线,再焊接电路,注意不能飞线,可正反穿线焊接;(3) 焊接过程中注意各引脚的功能,不能接错;(4) 焊接完后需要仔细检查后方能通电,电源电压为5V。所需元器件清单元器件规格数量元器件规格数量电阻1K11开关单刀双置4电阻20018杜邦线若干三极管90136插针50数码管共阴6导线若干万能板1蜂鸣器16、 硬件电路安装与调试1)借助杜邦线将芯片与所焊接硬件电路根据之前锁定好的引脚一 一连接好,在本设计中,各引脚锁定情况是:clk:17,q00q06 分别对应芯片引脚:65,63,59,57

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论