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

下载本文档

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

文档简介

实验名称:数字时钟设计姓名:杨 龙 成 班级: 电子与通信工程 学号: 3120302012 成绩: 一、实验目的1.掌握各类计数器及它们相连的设计方法;2.掌握多个数码管显示的原理与方法;3.掌握模块化设计方式;4.掌握用VHDL语言的设计思想以及整个数字系统的设计。二、实验内容 1. 设计要求 1)具有时、分、秒计数显示功能,在数码管显示00:00:0023:59:59,以24小时循环计时。 2)完成可以计时的数字时钟时钟计数显示时有LED灯的花样显示。 3)具有调节小时、分钟及清零的功能。 4)具有整点报时功能。 2. 性能指标及功能设计 1)时钟计数:完成时、分、秒的正确计时并且显示所计的数字;对秒、分60进制计数,时钟24进制计数,并且在数码管上显示数值。 2)时间设置:手动调节分钟、小时,可以对所设计的时钟任意调时间。可以通过实验板上的键7和键4进行任意的调整,因为时钟信号均是1HZ的,所以LED灯每变化一次就来一个脉冲,即计数一次。 3)清零功能:reset为复位键,低电平时实现清零功能,高电平时正常计数。 4)蜂鸣器在整点时有报时信号产生,产生“滴答.滴答”的报警声音。 5)根据进位情况,LED灯在时钟显示时有花样显示信号产生。 3. 系统方框图数字时钟 控制单元时调整分调整使能端信号CLK信号时显示分显示秒显示24进制60进制60进制LED显示整点报时花样显示三、设计原理和过程 3.1 硬件设计本设计使用VHDL硬件开发板,可编程逻辑器件EMP1270T144C5系列。设计过程中用到的外围电路的设计有电源部分,可编程器件EMP1270T144C5,CPLD JTAG接口,晶振和蜂鸣器,LED数码管显示,DIP开关与按键输入(具体电路见附录) 3.2 软件设计 3.2.1 程序包my_pkg的设计说明 为了简化程序设计增加可读性,系统采用模块化的设计方法,重复使用的组件以元件(component)的形式存在,以便相关块的调用。下面列出my_pkg组件包的代码。library ieee;use ieee.std_logic_1164.all;package my_pkg is component div40M-元器件1 Port( clk: in std_logic; f1hz : out std_logic); end component; component count60-元器件2 Port(clr,clk:in std_logic; one :buffer std_logic_vector(3 downto 0); ten :buffer std_logic_vector(3 downto 0); full:out std_logic; dout:buffer std_logic_vector(7 downto 0); end component; component count24-元器件3 Port(clr,clk:in std_logic; one :buffer std_logic_vector(3 downto 0); ten :buffer std_logic_vector(3 downto 0); full:out std_logic); end component; component scan6-元器件4 port (clr,clk : in STD_LOGIC; h_ten,h_one,m_ten,m_one,s_ten,s_one: in STD_LOGIC_vector(3 downto 0); cs: out STD_LOGIC_vector(5 downto 0); mux_out: out STD_LOGIC_vector(3 downto 0); end component; component bin2led-元器件5 port (bin : in std_logic_vector (3 downto 0); led : out std_logic_vector (7 downto 0) ); end component; component sh1k -元器件6 Port( clk: in std_logic;-from system clock(40MHz) f1hz : out std_logic);- 1Hz output signal end component; component alarm_set-元器件7Port(rst,hz1: in std_logic;-system clock 1Hz alarm,ok: in std_logic;-keep pushing to declare alarm set sec_tune: in std_logic; sec_one,sec_ten:out std_logic_vector(3 downto 0);end component;end my_pkg; 3.2.2 count60组件由此提供分(秒)计数值,当分计数器计数到59再来一个脉冲信号秒计数器清零从新开始计数,而进位则作为小时计数器的计数脉冲,使小时计数器计数加1,同时分计数器在分设置时钟信号的响应下设置分计数器的数值。在count60组件中,个位(one)和十位(ten)分别计数,都设为二进制四位矢量形式,当个位从0计到9时,在下一个clk上升沿来临后,十位进1,个位变0,十位从0到5计数,在十位为5,个位9的时候,下一个上升沿来临后,十位个位都变0,进位full加1。因此在程序设计中需要两个进程process来分别完成计数,秒计数以1Hz的输入为触发信号,分计数以秒的full信号为触发信号。具体的count60的组件代码如下:Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity count60 is Port(clr,clk:in std_logic; one :buffer std_logic_vector(3 downto 0); ten :buffer std_logic_vector(3 downto 0); full:out std_logic; dout:buffer std_logic_vector(7 downto 0);end count60;architecture behav of count60 is beginprocess(clr,clk) begin if(clr=0)then one=0000; elsif(rising_edge(clk)then if(one=1001)then one=0000; else one=one+1; end if; end if;end process; process(clr,clk) begin if(clr=0)then ten=0000; elsif(rising_edge(clk)then if(one=1001)then if(ten=0101)then ten=0000; else ten=ten+1; end if; end if; end if;end process ;dout=ten&one;process(clk)-满59进位(置full值beginif(rising_edge(clk)then if ten=0101then if one=1001then full=1; else full=0; end if; else full=0; end if;end if;end process;end behav; 设定clk与clr两个系统的输入后,课观察到one和ten的波形,在计数值达到59后,即ten为0101,one为1001以后,即进位到0000 0000,full进1,波形如下。 3.2.3 count24组件 由此提供时计数值,当时计数器计数到23再来一个脉冲信号秒计数器清零从新开始计数,而进位则作为小时计数器的计数脉冲,使小时计数器计数加1,同时分计数器在分设置时钟信号的响应下设置时计数器的数值。在count24组件中,个位(one)和十位(ten)分别计数,都设为二进制四位矢量形式,在ten小于2的时候,个位从0计到9时,满9ten加1,在ten为2的时候,one从0到3计数,one为3时候,在下一个clk上升沿来临后,ten与one都变0,进位full加1。因此在程序设计中需要多个个进程process来分别完成计数,时计数以分的full的输入为触发信号,分计数以秒的full信号为触发信号。具体的count24的组件代码如下:Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity count24 is Port(clr,clk:in std_logic; one :buffer std_logic_vector(3 downto 0); ten :buffer std_logic_vector(3 downto 0); full:out std_logic );end count24;architecture behav of count24 is beginprocess(clr,clk)-计数0到23 begin if(clr=0)then ten=0000; one=0000; elsif(rising_edge(clk)then if(ten0010)then if(one1001)then one=one+0001; end if; if one=1001then one=0000; ten=ten+0001; end if; end if; if(ten=0010) then if(one0011)then one=one+0001; end if; if one=0011then one=0000; ten=0000; end if; end if; end if; end process;process(clk)-满23进位beginif(rising_edge(clk)then if ten=0010then if one=0011then full=1; else full=0; end if; else full=0; end if;end if;end process;end behav; 小时计数模块图形分析:用来对时进行计数,当记到计数器的低四位小于2时,one从0到9 计数,ten 为2时,one从0到3计数,所以完成了24进制的计数,clk为系统时钟信号,具体波形如下: 3.2.4 div40M分频组件 为了便于时钟计数,需要1Hz的时钟信号。为了节省电力耗电,输出采用7段LED数码管来显示。要提供秒钟的源信号,以便正常的计数,另外,6个led数码管要都显示,利用人眼的视觉暂留效应,需要1000hZ的时钟扫描信号。在本系统中,时钟信号发生器的信号频率为40MHz,因此要将其进行分频,产生1HZ和1KHz的信号。代码如下:Library IEEE;Use IEEE.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Use IEEE.std_logic_arith.all;Entity div40M is Port( clk: in std_logic ; -from system clock(40MHz) f1hz: out std_logic);- 1Hz output signalend div40M;architecture arch of div40M issignal count : integer range 0 to 19999999;beginprocess (clk)begin if rising_edge(clk) then count= 10000000 then f1hz=1; else f1hz=0; end if; end if;end process;end arch;-本模块将40MHZ分频,分成1000HZ,提供扫描(片选)的时间-Library IEEE;Use IEEE.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Use IEEE.std_logic_arith.all;Entity sh1k is Port( clk: in std_logic; f1hz: out std_logic);end sh1k;architecture arch of sh1k issignal count : integer range 0 to 39999;beginprocess (clk)begin if rising_edge(clk) then count=20000 then f1hz=1; else f1hz=0; end if; end if;end process;end arch;波形分析:具体的分频波形如下,由于这里的40MHZ太大,仿真时不便观察这里我们以40KHZ来分频,效果如下: 3.2.5 scan6扫描组件 由于LED使用动态显示,因此要采用扫描的方式来点亮各个LED管,人眼的视觉延迟1/32秒。在本模块中,时、分、秒的每一位数都作为输入,同时提供一个片选(6位),每来一个clk 进行一次选位循环,即依次点亮6个LED灯管。在点亮的对应管上将该位的数字送给一个输出端口max_out.送到显示模块显示。具体的代码如下:library IEEE;use IEEE.std_logic_1164.all;use IEEE.std_logic_arith.all;use IEEE.std_logic_unsigned.all;entity scan6 is port (clr,clk : in STD_LOGIC; h_ten,h_one,m_ten,m_one,s_ten,s_one: in STD_LOGIC_vector(3 downto 0); cs: out STD_LOGIC_vector(5 downto 0);-片选 mux_out: out STD_LOGIC_vector(3 downto 0);-要显示的那一个时钟位end scan6;architecture arch of scan6 issignal sel : std_logic_vector(2 downto 0);begin process (clr,clk,h_ten,h_one,m_ten,m_one,s_ten,s_one) begin if clr=0 then sel=000; elsif rising_edge(clk) then sel mux_out = s_one; cs mux_out = s_ten; cs mux_out = m_one; cs mux_out = m_ten; cs mux_out = h_one; cs mux_out = h_ten; cs mux_out ledledledledledledledledledledNULL;END CASE;END PROCESS;end arch;仿真波形如下:3.2.7 alarm_set组件 为了设定闹钟,我们设计一个目标调整程序,以1Hz的显示速率来调整时分秒的显示。这里的alarm为指拨开关,当为on时,六个数字即显示00:00:00,以等待输入,当持续按键后,秒从0到59依次增加,再返回0,任何时刻松开按键,即为要显示的值。调分键和调时键的动作原理相同。此时OK指拨开关的然在off状态。代码如下:library IEEE; use IEEE.std_logic_1164.all;use IEEE.std_logic_arith.all;use IEEE.std_logic_unsigned.all;Entity alarm_set is Port(rst,hz1: in std_logic;-system clock 1Hz alarm,ok: in std_logic;-keep pushing to declare alarm set sec_tune: in std_logic; sec_one,sec_ten:out std_logic_vector(3 downto 0);End;-define the signal_structure and _flow of the device architecture arch of alarm_set is signal sec_one_tmp: std_logic_vector(3 downto 0) ; signal sec_ten_tmp: std_logic_vector(3 downto 0) ; begin tuning:process(rst,hz1,alarm,ok) begin if rst=1 then sec_one_tmp=0000;sec_ten_tmp=0000; elsif rising_edge(hz1) then if alarm=0 and ok=1 then if sec_tune=1 then if sec_one_tmp=1001 then sec_one_tmp=0000; if sec_ten_tmp0101 then sec_ten_tmp=sec_ten_tmp+0001; else sec_ten_tmp=0000 ; end if; else sec_one_tmp=sec_one_tmp +0001; end if; end if; else null; end if; end if; end process tuning; sec_one=sec_one_tmp; sec_tenclk,f1hz=hz1);-元件的调用 u1:count60 port map(clr=clr,clk=hz1,one=sec_one,ten=sec_ten,full=full_sec); u2:count60 port map(clr=clr,clk=full_sec,one=min_one,ten=min_ten,full=full_min); u3:count24 port map(clr=clr,clk=full_min,one=hour_one,ten=hour_ten,full=full_hour);end block normal_counting;scantime:block-扫描时间的设定,这里为1毫秒(1000Hz)begin u4:sh1k port map(clk=clk,f1hz=hz1k);end block scantime;scan_display:block-将4位二进制的时间转为BCD码,显示.begin u7:alarm_set port map(rst=clr,hz1=hz1,alarm=alarm,ok=ok,sec_tune=sec_button, sec_one=a_sec_one,sec_ten=a_sec_ten); u5:scan6 port map(clr=clr,clk=hz1k,s_one=a,s_ten=b, m_one=c,m_ten=d, h_one=e,h_ten=f, mux_out=time_bin, cs=cs); u6:bin2led port map(bin=time_bin,led=dout);-送到端口显示end block scan_display;beep:process(hz1,clr)-beginif rising_edge(hz1) then if sec_ten=0000and sec_one=0000and min_one=0000 and min_ten=0000 then if bb3 then bb=bb+1; beep_driver=hz1; else beep_driver=0; end if; end if; end if;end process; process(clr

温馨提示

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

评论

0/150

提交评论