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

下载本文档

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

文档简介

数字时钟 课程设计适用年级: 二年级 所属课程: 课程设计 姓名: 张隆喜 学号: 20093100121 可编程数字系统课程设计题目一、课程设计目的: 熟悉EDA工具;掌握用VHDL语言进行数字系统设计的基本方法和流程。二、设计任务:任选以下两道题目中的一道,用VHDL语言描述,用QuartusII工具编译和综合,仿真,并在实验板上实现,同时提交实验报告。1、 设计一数字钟,用数码管显示基本功能要求:(1) 可以分屏显示时、分、秒,可用数码管的小数点“.”代替时、分、秒的分隔符“:”,分屏显示是指由于数码管只有4个,不能同时显示时、分、秒,但可以只显示时、分,或只显示分、秒,通过按键来切换这两种显示方式。(2)可设置时钟的开始时间。设置时,相应的数码管要闪烁,指示当前设置的位置(内容)。(3)具有闹铃功能,可以设定闹铃时间。闹铃时间到,LED闪烁进行指示,说明:项目必须在一周内独立完成,发现抄袭者,一律不及格;1、 以上题目的要求为必须完成的基本功能,在此基本功能的基础上,鼓励学生增加更多功能(可加分);2、 提交的实验报告必须包含但不限于以下基本内容:设计原理、系统分析、程序设计、仿真结果、实验结果(可附上实验板运行时的照片)、结论或分析3、 验收方式:实物验收,需演示,并答辩。4、 评分标准:以完成上述的基本功能为基准,第一道题目的基准分为75,第二道题目的基准分为85分,根据完成设计的具体情况以及设计报告的质量,综合得分上下浮动。 5、 实验套件要妥善使用和保管,如有损坏或丢失,按情节轻重处理。设计思路:1状态的确定根据功能,输出,对按键的响应可将时钟设计为16个状态,分别为: 第一大类:s0 计时状态,显示高4 位s1 计时状态,显示低4 位 第二大类:s2 设置当前时间,小时数高位状态s3 设置当前时间,小时数低位状态s4 设置当前时间,分钟数高位状态s5 设置当前时间,分钟数低位状态s6 设置当前时间,秒数高位状态s7 设置当前时间,秒数低位状态第三大类:s8 设置闹钟时间,小时数高位状态s9 设置闹钟时间,小时数低位状态s10 设置闹钟时间,分钟数高位状态s11 设置闹钟时间,分钟数低位状态s12 设置闹钟时间,秒数高位状态s13 设置闹钟时间,秒数低位状态第四大类:s14 调节数码管亮度,音量大小状态第五大类:s15 切换歌曲 ,调节闹钟响应时间状态由于状态较多,如果按循环来切换的划,比较繁琐,所以先将他分成5大类,如上所示,然后根据按键实现 大类与大类直接的转换,大类内 类与类间的转换。2 重要信号的确定 要实现计时与闹钟功能,当前时间 和 闹钟时间 这两个信号是必须的,同时为了方便输出给数码管,采取将 当前时间 和 闹钟时间 都分解成6个独立的数字位的方法,分开计数个调节。为了实现音乐,调节数码管亮度和实现闪烁等功能,各种对应的强度信号,以及各种频率的时钟信号也是很重要的。3 端口的确定时钟输入端口,4个按键输入端口, 4个位选输出端口,led灯输出端口,蜂鸣器输出端口 4模型的建立:1 、模块设置 由于所设计时钟功能及逻辑比较复杂,为了是设计直观,采用模块化的设计方法。分别设计如下模块:时钟分频模块: 产生各种频率的时钟 状态转化模块: 负责状态的转换时钟逻辑模块:负责计时,设置时间,设置闹钟时间 ,设置声音强度,设置数码管亮度,切换歌曲功能数码管显示模块:显示数字,显示闪烁,实现数码管亮度的变化音乐模块: 自动播放音乐按键消抖模块:用于按键的消抖2、 各模块最终合成图5 设计过程中遇到的问题问题一键盘消抖问题:由于键盘噪声的问题,再未消抖的情况下,时钟对按键的响应很混乱首先 对消抖问题进行抽象:消抖无法就是去除掉那些频率很高的脉冲。其次 算法设计要去掉频率高的脉冲,首先要检测该脉冲的持续时间,及要有个计数器是记录任意两个相邻的上升或下降边沿的时间,当它大于某一个时间长度时,改变输出状态,同时根据实验板上按键默认为高电平的事实,将按键初始化为高电平,进而在此前提下对按键进行响应。第三 源程序设计library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity xiaodou isPort ( clk:in std_logic; keyin :in std_logic;keyout :out std_logic); end xiaodou;architecture xiaodou1 of xiaodou issignal n: integer range 0 to 20000;signal m: integer range 0 to 20000;signal a: std_logic;signal b: std_logic;beginprocess(keyin)beginif keyinevent and keyin=1 then a = not a;end if;if keyinevent and keyin=0 then b = not b;end if;end process;process(a,b,clk)begin if clkevent and clk=1 thenif a=b and m=20 then n=0;elsif a/=b then if n=20 thenn=20; else n=n+1; end if;end if; end if; if clkevent and clk=1 thenif a/=b and n=20 then m=0;elsif a=b then if m=20 thenm=20; else m=m+1; end if;end if; end if;end process;process(n)begin if m=20 then keyout=1; elsif n=20 then keyout=0; else keyoutclk, clk1Hz =mclk1Hz, clk2Hz=mclk2Hz, clk4Hz=mclk4Hz, clk8Hz=mclk8Hz, clk1000=mclk1000 );u0: xianshi port map( clk1 =clk, clk1Hz =mclk1Hz, clk8Hz =mclk8Hz, clk1000 =mclk1000, shuju0 =sj0, shuju1 =sj1, shuju2 =sj2, shuju3 =sj3, light =light1, s =ss, q =q, w =w );u1: jishi port map( clk4Hz =mclk4Hz, state =sta, lef =key1(1), righ=key1(2), change=key1(0), hold =hol, denjis=sound1, denjil=light1, shuju00 =sj0, shuju10 =sj1, shuju20 =sj2, shuju30 =sj3, s0 =ss, clock =clo, gequ = gequ2 ); u2: change port map( lef =key1(1), righ=key1(2), change=key1(0), state =sta);u3: yinyue port map( clk =clk, clock1 =clo, sound =sound1, gequ1 =gequ2, spkout =speaker, led = led);u4: keyxiaodou port map( clk =clk,keyin =key,keyout1=key1 ); process(mclk1Hz)begin end process;process(key1)begin if key1(3)event and key1(3)=1 then hol= not hol; end if;end process;end shizhong1; 2 分频模块library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity clkdiv isport( clk :IN std_logic;clk1Hz :out std_logic;clk2Hz :out std_logic;clk4Hz :out std_logic;clk8Hz :out std_logic;clk1000:out std_logic;clkyinyue :out std_logic);end clkdiv;architecture behav of clkdiv issignal cnt1 : integer range 0 to 50000000;signal cnt2 : integer range 0 to 50000000;signal cnt4 : integer range 0 to 50000000;signal cnt8 : integer range 0 to 50000000;signal cnt1000 : integer range 0 to 50000000;signal cntyinyue : integer range 0 to 50000000;-constant precnt :std_logic_vector(23 downto 0) := xd00000; -13631488beginprocess(clk)beginif clkevent and clk=1 thenif cnt1 = 49999999 then cnt1 = 0;clk1Hz = 1;elsecnt1 = cnt1 + 1;clk1Hz = 0;end if;end if; end process;process(clk)beginif clkevent and clk=1 thenif cnt2 = 24999999 then cnt2 = 0;clk2Hz = 1;elsecnt2 = cnt2 + 1;clk2Hz = 0;end if;end if; end process;process(clk)beginif clkevent and clk=1 thenif cnt4 = 12499999 then cnt4 = 0;clk4Hz = 1;elsecnt4 = cnt4 + 1;clk4Hz = 0;end if;end if; end process;process(clk)beginif clkevent and clk=1 thenif cnt8 = 6249999 then cnt8 = 0;clk8Hz = 1;elsecnt8 = cnt8 + 1;clk8Hz = 0;end if;end if; end process;process(clk)beginif clkevent and clk=1 thenif cnt1000 = 1000 then cnt1000 = 0;clk1000 = 1;elsecnt1000 = cnt1000 + 1;clk1000 = 0;end if;end if; end process;process(clk)beginif clkevent and clk=1 thenif cntyinyue = 13631488 then cntyinyue = 0;clkyinyue = 1;elsecntyinyue = cntyinyue + 1;clkyinyue shuju0 ,en=ss(0) ,xiaoshudian=fuhao, w=ww(0),q=qq0);u1:shumaguan port map(shuju=shuju1 ,en=ss(1) ,xiaoshudian=fuhao, w=ww(1),q=qq1);u2:shumaguan port map(shuju=shuju2 ,en=ss(2) ,xiaoshudian=fuhao, w=ww(2),q=qq2);u3:shumaguan port map(shuju=shuju3 ,en=ss(3) ,xiaoshudian=fuhao, w=ww(3),q=qq3);process(clk1)begin if clk1event and clk1=1 then if jishu = 1000 then jishu=0; else jishu=jishu+1; end if; end if;end process; process(clk1000,clk8Hz)begin if clk1000event and clk1000=1 then if weixuan = 7 then weixuan=0; else weixuan=weixuan+1; end if; end if; if clk8Hzevent and clk8Hz=1 then shanshuo = not shanshuo; end if;end process;process(weixuan)begin if weixuan=2 then fuhao=1; else fuhao=0; end if; end process;process(jishu)begin if jishu if s(0)=1 and shanshuo=0 then ss(0)=0; else ss(0)=1; end if; w=ww; q if s(1)=1 and shanshuo=0 then ss(1)=0; else ss(1)=1; end if; w=ww; q if s(2)=1 and shanshuo=0 then ss(2)=0; else ss(2)=1; end if; w=ww; q if s(3)=1 and shanshuo=0 then ss(3)=0; else ss(3)=1; end if; w=ww; q ss=0000; w=ww; q=11111111; end case; else ss=0000; w=ww; q qiandu qiandu qiandu qiandu qiandu qiandu qiandu qiandu qiandu qiandu=1000;end case;end process;end xianshi1;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity shumaguan isport( shuju: in integer range 0 to 9; en: in std_logic; xiaoshudian: in std_logic; w: out std_logic; q: out std_logic_vector(0 to 7) );end shumaguan;architecture liucheng of shumaguan isbeginprocess(shuju, en)beginif en=1 then w q q q q q q q q q q q q q q q q q q q q=00001000 ;end case;end if;else w=1;end if;end process;end liucheng;4 计时模块library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity jishi isport( clk4Hz :in std_logic;state :in std_logic_vector(0 to 3);lef :in std_logic;righ:in std_logic;change:in std_logic;hold :in std_logic;denjis: out integer range 0 to 9;denjil: out integer range 0 to 9;shuju00: out integer range 0 to 9;shuju10: out integer range 0 to 9;shuju20: out integer range 0 to 9;shuju30: out integer range 0 to 9;s0 : out std_logic_vector(0 to 3);clock : out std_logic;gequ : out integer range 0 to 9);end jishi;architecture jishi1 of jishi is signal hh: integer range 0 to 9;signal hl: integer range 0 to 9;signal mh: integer range 0 to 9;signal ml: integer range 0 to 9;signal sh: integer range 0 to 9;signal sl: integer range 0 to 9;signal hh1: integer range 0 to 9;signal hl1: integer range 0 to 9;signal mh1: integer range 0 to 9;signal ml1: integer range 0 to 9;signal sh1: integer range 0 to 9:=3;signal sl1: integer range 0 to 9;signal rl:std_logic_vector(0 to 1);signal n: integer range 0 to 3;signal denjis1: integer range 0 to 9:=5;signal denjil1: integer range 0 to 9:=9;signal gequ1 : integer range 0 to 9;signal tim : integer range 0 to 9:=1;signal tim1 : integer ;signal tim2 : integer ;signal add:std_logic:=1;beginprocess(hold)beginif holdevent and hold=1 then add = not add;end if;end process;process(lef,righ)beginif state=1110 thenif lefevent and lef=1 then if add=1 thenif denjis1=9 then denjis1=0;else denjis1=denjis1+1;end if; else if denjis1=0 then denjis1=9;else denjis1=denjis1-1;end if; end if;end if;if righevent and righ=1 then if add=1 thenif denjil1=9 then denjil1=0;else denjil1=denjil1+1;end if; else if denjil1=0 then denjil1=9;else denjil1=denjil1-1;end if; end if;end if;denjil=denjil1;denjis=denjis1;end if;end process;process(lef,righ,clk4Hz)beginif state=1111 thenif righevent and righ=1 then if gequ1=9 then gequ1=0;else geq

温馨提示

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

评论

0/150

提交评论