基于VHDL语言的数字钟设计

合集下载

基于VHDL的数字钟的设计

基于VHDL的数字钟的设计

基于VHDL的数字钟的设计一、设计目的1、掌握计数器,分频器的工作原理和设计方法;2、掌握数码管的动态扫描译码显示的工作原理和设计方法;3、掌握数字钟的设计方法;4、掌握在EDA开发软件QuartusII环境下基于FPGA/CPLD的数字系统设计方法,掌握该环境下系统的功能仿真、时序仿真、管脚锁定和芯片下载的方法。

二、设计要求1、基本要求(1)设计一个24小时制的数字钟;(2)利用板上数码管显示时、分、秒,要求显示格式为:小时—分钟—秒;(3)利用板上的按键作时钟调整,调整要求为:按下时调整键,“时”迅速增加,并按24小时制(0~~23)规律循环;按下分调整键,“分”迅速增加,并按60分钟制(0~59)规律循环;(4)数字钟可清零、可保持。

2、提高要求(1)能利用EDA系统上的蜂鸣器作整点报时。

从59分55秒时开始报时,每隔一秒报时一次;00分00秒时,进行整点报时。

整点报时声的频率应与其他的报时声频率有明显区别;(2)具有按12小时模式显示与24小时模式显示切换的功能;(3)具有闹钟功能。

三、系统框图四、底层模块设计1、时基产生电路由晶振产生的频率非常稳定的脉冲,经整形、分频电路后,产生一个频率为1Hz的、非常稳定的计数时钟脉冲。

(电子线路部分,不用VHDL语言描述。

)2、校时电路(二选一数据选择器)LIBRARY ieee;USE ieee.std_logic_1164.all;ENTITY MUX2_1 ISPORT(K,CLK,CI : IN STD_LOGIC;Y : OUT STD_LOGIC);END MUX2_1;ARCHITECTURE b OF MUX2_1 ISBEGINY<=CLK WHEN K='0' ELSE CI;END b;3、计数器(1)24进制计数器1)24进制的VHDL语言程序LIBRARY ieee;USE ieee.std_logic_1164.all;USE ieee.std_logic_unsigned.all;ENTITY COUNT24 ISPORT(CLR : IN STD_LOGIC;EN : IN STD_LOGIC;CLK : IN STD_LOGIC;QL : BUFFER STD_LOGIC_VECTOR(3 downto 0);QH : BUFFER STD_LOGIC_VECTOR(3 downto 0);CO : OUT STD_LOGIC);END COUNT24;ARCHITECTURE a OF COUNT24 ISBEGINPROCESS(CLR,EN,CLK)BEGINIF CLR='0' THENQH<="0000";QL<="0000";ELSIF CLK'EVENT AND CLK='1' THENIF(EN='1')THENIF QH=2 AND QL=3 THENQL<="0000";QH<="0000";ELSEIF QL=9 THENQL<="0000";QH<=QH+1;ELSEQL<=QL+1;END IF;END IF;END IF;END IF;END PROCESS;CO<='0'WHEN QH=2 AND QL=3 ELSE'1';END a;2)仿真波形图1、count24的时序仿真波形3)从设计文件创建模块,默任模块的名称为count24。

基于VHDL语言的数字时钟设计

基于VHDL语言的数字时钟设计

课程:CPLD与FPGA设计及应用实验:基于VHDL语言的数字时钟设计学号:*********姓名:**专业:信号与信息处理学院:电子与信息学院2011年12月基于VHDL语言的数字时钟设计一:主要功能1:具有时、分、秒计数显示功能,以24小时循环计时。

2:具有日期和星期显示功能。

3:具有秒表功能4:具有调节日期,星期,小时,分钟,清零的功能。

5:具有定时和闹铃的功能。

二:结构框图三:RTL图四:功能实现4.1分频模块设计本设计使用的输入时钟信号为50Mhz,经过分频产生两路时钟信号,其中一路为微秒计数时钟信号,一路为动态扫描时钟信号。

同时模块有一输入控制信号,其功能是停止微秒计数时钟信号,以实现定时的功能。

输入:clk_in 为50Mhz,setstop为微秒计数时能信号输出:clk_out1为1/60hzclk_out2为1khz源代码如下:library ieee;use ieee.std_logic_1164.all;entity div isport(clk_in,setstop: in std_logic;clk_out1,clk_out2: out std_logic);end entity div;architecture fun of div isconstant a:integer:=8333333;constant b:integer:=49999;signal c:integer range 0 to a;signal d:integer range 0 to b;beginprocess(clk_in,setstop)beginif(clk_in 'event and clk_in='1') thenif(( c+7500000)<a and setstop='1') then c<=c+1;clk_out1<='1';else c<=0;clk_out1<='0';end if;end if;end process;process(clk_in)beginif(clk_in 'event and clk_in='1') thenif d<=b then d<=d+1; clk_out2<='1';else d<=0;clk_out2<='0';end if;end if;end process;end fun;4.2计时模块设计4.2.1 微秒计时模块计数器的第一个模块为微秒计时模块,其实质为一个六十进制计数器。

基于VHDL语言的数字钟设计

基于VHDL语言的数字钟设计

信息与通信工程学院数字电路与逻辑设计实验题目:基于VHDL语言的数字钟设计班级:姓名:学号:日期:指导教师:一.摘要数字钟是一个将“时”、“分”、“秒”显示于人的视觉器官的计时装置。

它的基本功能是计时,计时周期为24小时,显示满刻度23时59分59秒;或者计时周期为12小时并配有上下午指示,显示满刻度为11时59分59秒,通过六个七段数码管显示出来。

本实验主要在理论分析和具体的软硬件实现上,基于VHDL语言编写源代码,使用软件Quartus II 进行处理,再配合具体电路连接,实现一个多功能的数字钟。

关键词:数字钟;VHDL语言;七段数码管二.设计任务要求设计实现一个数字钟。

1.24小时制,显示刻度从0:0:0到23:59:59 。

2.12小时制,显示刻度从0:0:0到11:59:59 。

3.12/24小时制可切换,12小时制下上下午有不同显示(上午发光二极管不亮,下午发光二极管亮)。

4.可手动校对时间,能对时和分进行校正。

5.整点报时功能。

6.闹铃功能,可设置闹铃时间,当计时到预定时间时,蜂鸣器发出闹铃信号,闹铃时间为5秒,可提前终止闹铃。

7.可认为设置时间为倒计时模式8.可切到屏保模式,六个数码管显示为“supper”字样。

三.设计思路和总体设计框图1.设计思路程序设计主要分为四个模块,第一部分,做分频器,分出一秒的时钟用来计数,再分出一个中频时钟用来扫描显示数码管,我选择的频率是50kHZ;第二部分,做计数器,秒随时钟沿计数进1,分钟随着秒计数60次进一,而小时,由于有12/24小时制的切换,时的计数有两个信号来进行,一个信号hour1是分60进一在0到23循环计数,另一个信号hour2是分60进一在0到11循环计数;第三部分,做扫描显示六个七段数码管,通过选通信号6矢量cat来依次使六个数码管亮,数码管每两位对应相应的时分秒;第四部分,其他输入输出单元,比如数字钟的时间修正,闹铃等,这些都是基于前三个部分,做起来难度不大。

基于VHDL语言的数字钟设计

基于VHDL语言的数字钟设计

基于VHDL语言的数字钟设计摘要:我们现在是在第二十一世纪,是电子信息时代,EDA技术推广。

尤其在电子信息,各行业的通信方面,自动控制方面,在计算机等方面的重要性越来越起到举足轻重的地位。

作为一个学习电子科学与技术专业的学生,我们必须不断的了解更多的关于硬件描述语言等产品的信息,这就要求我们对VHDL语言有个全面的认识。

本设计采用VHDL语言,在QuartusII为操作平台,该软件可以调试,也可以实现软件的模拟仿真,初步实现了设计目标。

这个程序使用的语言为VHDL,这是一种硬件描述语言。

对QUARTUSII有更深的了解,对今后工作、学习等都会有所帮助]1[。

与传统的硬件设计方法相比,传统的硬件设计所实用的芯片比较多,有太多的电路图要连接,所以连线较多,会很麻烦,并且在设计的过程中出现错误后也很难检查出来。

使用汇编语言来实现对数字钟的控制相对来说比较容易,并且连线也很简单,出错后易于校验。

使用VHDL语言设计仿真技术,可以在计算机上实现,所以它可以大大缩短系统开发的时间。

可以来尝试使用VHDL作为进行数字钟的设计。

设计一个数字时钟,能够以24小时循环显示小时、分钟,秒计数;具有时间清零,时、分设置功能;也具有整点报时的功能。

要求我的论文分为秒模块,分模块,以及与时模块,并且也有显示扫描模块,还有整点报时模块,译码器等。

在Quartus上可以进行编译仿真波形。

如果接到EDA平台上也可以进行仿真]2[。

通过本次的论文设计,不仅巩固了我所学到的专业知识,而且对数字系统的理解也随之加深,从刚开始接触到论文的时候慢慢的学习才渐渐的了解VHDL语言,更加深了对以前EDA的掌握,现在也对QUARTUSII软件也能够完成许多的操作。

并且能完成仿真。

关键词:EDA技术; QUARTUSII; VHDL语言; 数字时钟The design of digital clock based on VHDL languageAbstract:Now we are in the 21st century,which is not only the high-tech era, but also the era of electronic information.EDA technology continues to in-depth and extension.Especially in electronic information, ,automatic control, Playing a pivotal position,which is more and more importance.As a study of electronic science and technology major students, we must constantly learn more information about the hardware description language, and other products, This requests us to have a comprehensive understanding of the language of VHDL]3[.This project design using VHDL language, as for the HDL( hardware description language), QUARTUSII as program operation platform, the development of program debugging and running, through waveform simulation, Design goal was preliminarily realized.The use of the program for the VHDL language, which is a kind of HDL(hardware description language),Let us had a deeper step in the comprehensive application of QUARTUSII use, my future study and work to bring a lot of guidance from this paper design. Compared with the traditional design method of hardware, the traditional hardware design practical chip is more, there are too many circuit diagram to connect, so the attachment is more, it will be very troublesome, and after an error in the process of design is to check ing assembly language to achieve control of the digital clock is relatively easy, and the attachment is simple, which easy to check.It can use VHDL language design simulation technology, which can be implemented on the computer, so it can greatly shorten the time of the system development.It also can try to use VHDL as for the design of digital clock.It design a digital clock, with 24 hours display hours, minutes, seconds count;With time, hours, minutes setting function;It also has the function of the hour.For my thesis is divided into second module, module, and module, and that also have show scanning module, and hour module, decoder, etc.It depend on Quartus compile the simulation waveform.If received the EDA platform can also be simulated.Deepen understanding of the digital system, from the beginning when in contact with the paper slowly learning to gradually understand the VHDL language, punctuate the grasp of the EDA before, now also the software QUARTUSII is also able to complete the operation of many.And can complete the simulation.Keywords: EDA technology; QUARTUSII; VHDL language; Digital clock安徽三联学院毕业论文目录第一章引言 (1)1.1 设计背景 (1)1.2 设计目的 (1)1.3 设计的内容 (2)第二章主要方案介绍 (4)2.1 方案一 (4)2.2 方案二 (4)第三章系统硬件描述语言............................ 错误!未定义书签。

利用VHDL语言设计的数字钟

利用VHDL语言设计的数字钟

一、题目:数字钟二、设计目的掌握各类计数器和分频器以及它们相连的设计方法;掌握多个数码管的原理与方法;掌握CPLD技术的层次化设计的方法;掌握使用VHDL语言的设计思想;对整个系统的设计有一个了解。

三、设计系统环境(1)一台PC机;(2)一套GW48型EDA实验开发系统硬件;(3)X+PLUS Ⅱ集成化的开发系统硬件。

四、设计要求(1)能进行正常的时、分、秒计时功能,分别由6个数码管显示24h、60min、60s。

(2)按下sa键时,计时器迅速递增,并按24h循环,计时满23h后回00。

(3)按下sb键时,计时器迅速递增,并按60min循环,计时满59min后回00。

(4)输入的时钟信号为3MHz。

五、总体框图六、模块及模块功能(1)模块CNT60_2 该模块为60进制计数器,计时输出为秒的数值,在计时到59时送出进位信号CO,因为硬件有延时,所以模块CNT60_2在此模块变为00时加1,符合实际。

A、模块B、程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cnt60_2 isport(clk:in std_logic;s1,s0:out std_logic_vector(3 downto 0);co:out std_logic);end cnt60_2;architecture behav of cnt60_2 isbeginprocess(clk)variable cnt1,cnt0:std_logic_vector(3 downto 0);beginif clk'event and clk='1' thenif cnt1="0101" and cnt0="1000" thenco<='1';cnt0:="1001";elsif cnt0<"1001" thencnt0:=cnt0+1;else cnt0:="0000";if cnt1<"0101" thencnt1:=cnt1+1;else cnt1:="0000";co<='0';end if;end if;end if;s1<=cnt1;s0<=cnt0;end process;end behav;C、流程图D、波形仿真(2)模块CNT60_1 该模块为60进制计数器,计时输出为分的数值,在EN信号有效且时钟到来时,计数器加1。

基于VHDL的多功能数字钟设计报告

基于VHDL的多功能数字钟设计报告

基于VHDL的多功效数字钟设计陈述021215班卫时章02121451一.设计请求1.具有以二十四小时制计时.显示.整点报时.时光设置和闹钟的功效.2.设计精度请求为1秒.二.设计情况:Quartus II三.体系功效描写1.体系输入:时钟旌旗灯号clk采取50MHz;体系状况及较时.准时转换的控制旌旗灯号为k.set,校时复位旌旗灯号为reset,均由按键旌旗灯号产生.2.体系输出:LED显示输出;蜂鸣器声音旌旗灯号输出.3.多功效数字电子钟体系功效的具体描写如下:(一)计时:正常工作状况下,每日按24h计时制计时并显示,蜂鸣器无声,逢整点报时.(二)校时:在计时显示状况下,按下“k”键,进入“小时”待校准状况,若此时按下“set”键,小时开端校准;之后按下“k”键则进入“分”待校准状况;中断按下“k”键则进入“秒”待复零状况;再次按下“k”键数码管显示闹钟时光,并进入闹钟“小时”待校准状况;再次按下“k”键则进入闹钟“分”待校准状况;若再按下“k”键恢复到正常计时显示状况.若校时进程中按下“reset”键,则体系恢复到正常计数状况.(1)“小时”校准状况:在“小时”校准状况下,显示“小时”的数码管以2Hz闪耀,并按下“set”键时以2Hz的频率递增计数.(2)“分”校准状况:在“分”校准状况下,显示“分”的数码管以2Hz闪耀,并按下“set”键时以2Hz的频率递增计数.(3)“秒”校准状况:在“秒复零”状况下,显示“秒”的数码管以2Hz闪耀,并以1Hz的频率递增计数.(4)闹钟“小时”校准状况:在闹钟“小时”校准状况下,显示“小时”的数码管以2Hz闪耀,并按下“set”键时以2Hz的频率递增计数.(5)闹钟“分”校准状况:在闹钟“分”校准状况下,显示“分”的数码管以2Hz闪耀,并按下“set”键时以2Hz的频率递增计数.(三)整点报时:蜂鸣器在“59”分钟的第“51”.“53”.“55”.“57”秒发频率为500Hz的低音,在“59”分钟的第“59”秒发频率为1000Hz的高音,停止时为整点.(四)显示:采取扫描显示方法驱动4个LED数码管显示小时.分,秒由两组led灯以4位BCD 码显示.(五)闹钟:闹钟准不时光到,蜂鸣器发出频率为1000Hz的高音,中断时光为60秒.四.各个模块剖析解释1.分频器模块(freq.vhd)(1)模块解释:输入一个频率为50MHz的CLK,应用计数器分出1KHz的q1KHz,500Hz的q500Hz,2Hz的q2Hz和1Hz的q1Hz.(2)源程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity freq isport (CLK: in std_logic ; --输入时钟旌旗灯号q1KHz: buffer std_logic;q500Hz: buffer std_logic;q2Hz: buffer std_logic;q1Hz: out std_logic);end freq;architecture bhv of freq isbeginP1KHZ:process(CLK)variable cout:integer:=0;beginif CLK'event and CLK='1' thencout:=cout+1; --每来个时钟上升沿时cout开端计数if cout<=25000 then q1KHz<='0'; --当cout<=25000时,q1KHz输出“0”elsif cout<50000 then q1KHz<='1'; --当25000<cout<=50000时,q1KHzelse cout:=0; --输出“1”,完成1KHz 频率输出end if;end if;end process;P500HZ:process(q1KHz) --q1KHz作为输入旌旗灯号,分出q500Hzvariable cout:integer:=0;beginif q1KHz'event and q1KHz='1' thencout:=cout+1;if cout=1 then q500Hz<='0'; --二分频elsif cout=2 then cout:=0;q500Hz<='1';end if;end if;end process;P2HZ:process(q500Hz)variable cout:integer:=0;beginif q500Hz'event and q500Hz='1' then cout:=cout+1;if cout<=125 then q2Hz<='0';elsif cout<250 then q2Hz<='1';else cout:=0;end if;end if;end process;P1HZ:process(q2Hz)variable cout:integer:=0;beginif q2Hz'event and q2Hz='1' thencout:=cout+1;if cout=1 then q1Hz<='0';elsif cout=2 then cout:=0;q1Hz<='1'; end if;end if;end process;end bhv;(3)模块图:2.控制器模块(contral.vhd)(1)模块解释:输入端口k,set键来控制6个状况,这六个状况分离是:显示计不时光状况,调计时的时.分.秒的3个状况,调闹铃的时.分的3个状况,reset键是复位键,用往返到显示计不时光的状况.(2)波形仿真图:(3)模块图:3、二选一模块(mux21a.vhd)(1)源程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity mux21a isport(a,b,s:in bit;y:out bit);end entity mux21a;architecture one of mux21a isbeginprocess(a,b,s)beginif s='0' theny<=a; --若s=0,y输出a,反之输出b. else y<=b;end if;end process;end architecture one;(2)仿真波形图:(3)模块图:4、计时模块a.秒计时(second.vhd)(1)仿真波形图:(2)模块图:b.分计时(minute.vhd)(1)仿真波形图:(2)模块图:c.小时计时(hour.vhd)(1)仿真波形图:(2)模块图:d.闹钟分计时(cntm60b.vhd)(1)仿真波形图:(2)模块图:e.闹钟小时计时(cnth24b.vhd)(1)仿真波形图:(2)模块图:5.闹钟比较模块(compare.vhd)(1)模块解释:比较正常计数时光与闹钟准不时光是否相等,若相等,compout输出“1”,反之输出“0”.(2)仿真波形图:(3)模块图:6.报时模块(bell.vhd)(1)模块解释:该模块既实现了整点报时的功效,又实现了闹铃的功效,蜂鸣器经由过程所选频率的不合,而发出不合的声音.(2)仿真波形图:(3)模块图:7.控制显示模块(show_con.vhd)(1)模块解释:该模块实现了数码管既可以显示正常时光,又可以显示闹钟时光的功效;调时进程的准时闪耀功效也在此模块中真正实现.(2)源程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity show_con isport(th1,tm1,ts1:in std_logic_vector(7 downto 4);th0,tm0,ts0:in std_logic_vector(3 downto 0);bh1,bm1:in std_logic_vector(7 downto 4);bh0,bm0:in std_logic_vector(3 downto 0);sec1,min1,h1: out std_logic_vector(7 downto 4);sec0,min0,h0: out std_logic_vector(3 downto 0);q2Hz,flashs,flashh,flashm,sel_show:in std_logic); end show_con;architecture rtl of show_con isbeginprocess(th1,tm1,ts1,th0,tm0,ts0,bh1,bm1,bh0,bm0,q2Hz,flas hs,flashh,flashm,sel_show)beginif sel_show='0'thenif ( flashh='1'and q2Hz='1')thenh1<="1111";h0<="1111"; --显示小时数码管以2Hz闪耀min1<=tm1;min0<=tm0;sec1<=ts1;sec0<=ts0;elsif (flashm='1'and q2Hz='1')thenh1<=th1;h0<=th0;min1<="1111";min0<="1111";sec1<=ts1;sec0<=ts0;elsif (flashs='1'and q2Hz='1')thenh1<=th1;h0<=th0;min1<=tm1;min0<=tm0;sec1<="1111";sec0<="1111";elseh1<=th1;h0<=th0;min1<=tm1;min0<=tm0;sec1<=ts1;sec0<=ts0;end if;elsif sel_show='1'then--若sel_show为“1”,数码管显示闹钟时光if(flashh='1' and q2Hz='1')thenh1<="1111";h0<="1111";min1<=bm1;min0<=bm0;sec1<="0000";sec0<="0000";elsif ( flashm='1' and q2Hz='1')thenh1<=bh1;h0<=bh0;min1<="1111";min0<="1111";sec1<="0000";sec0<="0000";elseh1<=bh1;h0<=bh0;min1<=bm1;min0<=bm0;sec1<="0000";sec0<="0000";end if ;end if;end process;end rtl;(3)模块图:8.动态扫描显示模块(scan_led.vhd)(1)模块解释:由4组输入旌旗灯号和输出旌旗灯号进而实现了时钟时.分的动态显示.(2)源程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity scan_led isport(clk1:in std_logic;h0:in std_logic_vector(3 downto 0);h1:in std_logic_vector(7 downto 4);min0:in std_logic_vector(3 downto 0);min1:in std_logic_vector(7 downto 4);ML:out std_logic_vector(7 downto 0);MH:out std_logic_vector(7 downto 0);HL:out std_logic_vector(7 downto 0);HH:out std_logic_vector(7 downto 0));end scan_led;architecture one of scan_led issignal cnt4:std_logic_vector(1 downto 0);signal a: std_logic_vector(3 downto 0) ;beginp1:process(clk1)beginif clk1'event and clk1 ='1' thencnt4<=cnt4+1;if cnt4=3 thencnt4<="00";end if;end if;end process p1;p2:process(cnt4,h1,h0,min1,min0)begincase cnt4 is --控制数码管位选when "00"=>case min0 iswhen "0000"=>ML<="11000000";when "0001"=>ML<="11111001";when "0010"=>ML<="10100100";when "0011"=>ML<="10110000";when "0100"=>ML<="10011001";when "0101"=>ML<="10010010";when "0110"=>ML<="10000010";when "0111"=>ML<="11111000";when "1000"=>ML<="10000000";when "1001"=>ML<="10010000";when others=>NULL;end case;when "01"=>case min1 iswhen "0000"=>MH<="11000000"; when "0001"=>MH<="11111001";when "0010"=>MH<="10100100";when "0011"=>MH<="10110000";when "0100"=>MH<="10011001";when "0101"=>MH<="10010010";when "0110"=>MH<="10000010";when "0111"=>MH<="11111000";when "1000"=>MH<="10000000";when "1001"=>MH<="10010000";when others=>NULL;end case;when "10"=>case h0 iswhen "0000"=>HL<="11000000"; when "0001"=>HL<="11111001";when "0010"=>HL<="10100100";when "0011"=>HL<="10110000";when "0100"=>HL<="10011001";when "0101"=>HL<="10010010";when "0110"=>HL<="10000010";when "0111"=>HL<="11111000";when "1000"=>HL<="10000000";when "1001"=>HL<="10010000";when others=>NULL;end case;when "11"=>case h1 iswhen "0000"=>HH<="11000000"; when "0001"=>HH<="11111001";when "0010"=>HH<="10100100";when "0011"=>HH<="10110000";when "0100"=>HH<="10011001";when "0101"=>HH<="10010010";when "0110"=>HH<="10000010";when "0111"=>HH<="11111000";when "1000"=>HH<="10000000";when "1001"=>HH<="10010000";when others=>NULL;end case;when others =>null;end case;end process p2;end one;(3)模块图:五、端口设定k:button2 ,set:button1 ,reset:button0 ;Bell:SW1 用于开关蜂鸣器;六.顶层电路图七、心得领会此次的数字钟设计重在于按键的控制和各个模块代码的编写,固然能把键盘接口和各个模块的代码编写出来,并能正常显示,但对于各个模块的优化设计还有必定的缺点和缺少,比方对按键消抖等细节处并未作出优化.经由此次数字钟的设计,我确切从中学到许多的器械.起首,经由过程VHDL硬件说话的进修,我充分熟悉到了功效模块若何用说话实现,让我初步懂得到了一个数字电路用硬件说话设计的方法和设计思惟.其次,也让我深深地领会到实践的主要性,起先我学VHDL说话的时刻,只是学得书本上的常识,经由此次课程设计,经由过程对模块的说话实现,对于VHDL说话我有了更深的熟悉.并且在程序错误的发明和纠正的进程中,我得到了更多的收成,也确切让我提高了许多.再次,当我碰到一些问题的时刻,就教先生,和同窗们一路评论辩论,令我受益颇多!最后,这个多功效数字电子钟是自我创造与汲取借鉴配合感化的产品,是自我尽力的成果.这让我对数字电路的设计充满了信念.固然课程设计已经停止,但这其实不代表着我已经真正控制了VHDL说话,仍需中断进修!。

基于VHDL的数字时钟设计

基于VHDL的数字时钟设计

目录1 概述...................................................................... 错误!未定义书签。

1.1数字时钟的工作原理 (1)1.2设计任务 (1)2 系统总体方案设计 (2)3 VHDL模块电路设计 (3)3.1模块实现 (3)3.1.1分频模块pinlv (3)3.1.2按键去抖动模块qudou (5)3.1.3按键控制模块self1 (6)3.1.4秒、分六十进制模块cantsixty (7)3.1.5时计数模块hourtwenty (9)3.1.6秒、分、时组合后的模块 (9)3.1.7数码管显示模块 (10)3.2数字时钟的顶层设计原理图 (13)3.3系统仿真与调试 (14)结束语 (16)参考文献 (17)致谢 (18)附录源程序代码 (19)1 概述1.1数字时钟的工作原理数字钟电路的基本结构由两个60进制计数器和一个24进制计数器组成,分别对秒、分、小时进行计时,当计时到23时59分59秒时,再来一个计数脉冲,则计数器清零,重新开始计时。

秒计数器的计数时钟CLK为1Hz的标准信号,可以由晶振产生的50MHz信号通过分频得到。

当数字钟处于计时状态时,秒计数器的进位输出信号作为分钟计数器的计数信号,分钟计数器的进位输出信号又作为小时计数器的计数信号,每一秒钟发出一个中断给CPU,CPU采用NIOS,它响应中断,并读出小时、分、秒等信息。

CPU对读出的数据译码,使之动态显示在数码管上。

1.2 设计任务设计一个基于VHDL的数字时钟,具体功能要求如下:1.在七段数码管上具有时--分--秒的依次显示。

2.时、分、秒的个位记满十向高位进一,分、秒的十位记满五向高位进一,小时按24进制计数,分、秒按60进制计数。

3.整点报时,当计数到整点时扬声器发出响声。

4.时间设置:可以通过按键手动调节秒和分的数值。

此功能中可通过按键实现整体清零和暂停的功能。

基于VHDL的数字时钟课程设计

基于VHDL的数字时钟课程设计

数字时钟设计1.设计要求(1)能显示周、时、分、秒,精确到0.1秒(2)可自行设置时间(3)可设置闹铃,并且对闹铃时间长短可控制2.设计分析(1)根据题目要求可分解为正常计时、时间设置和闹铃设置三大模块(2)正常计时模块可分解为周、时、分、秒等子模块(3)时间设置模块分别进行秒置数、分置数、时置数和周置数(4)闹铃设置模块分解为闹钟判定和闹铃时长设定3.设计结构图4.设计流程图否是否--Second1(秒计数6进制和10进制)Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity second1 isPort( clks,set:in std_logic;s1,s0:in std_logic_vector(3 downto 0);Secs,Secg: buffer std_logic_vector(3 downto 0);cout1:out std_logic);End second1;Architecture a of second1 isBeginProcess(clks,set)variable ss,sg: std_logic_vector(3 downto 0);--(ss:秒十位;sg秒个位) variable co: std_logic;BeginIf set='1' then ss:=s1; sg:=s0;Elsif clks'event and clks='1' thenif ss="0101" and sg="1001" then ss:="0000"; sg:="0000";co:='1'; elsif sg<"1001" then sg:=sg+1;co:='0';elsif sg="1001" then sg:="0000";ss:=ss+1;co:='0';end if;end if;cout1<=co;-- (进位信号)Secs<=ss;Secg<=sg;end process;End a;仿真波形图:--Min1(分计数器6进制和10进制alm实现整点报时)Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity min1 isPort(clkm,set:in std_logic;m1:in std_logic_vector(3 downto 0);m0:in std_logic_vector(3 downto 0);mins,ming:out std_logic_vector(3 downto 0);enmin,alarm: out std_logic);End;Architecture a of min1 isBeginProcess(clkm,set)variable ms,mg :std_logic_vector(3 downto 0);variable so,alm :std_logic;Beginif set='0' then ms:=m1;mg:=m0;Elsif clkm'event and clkm='1' thenif ms="0101" and mg="1001" then ms:="0000";mg:="0000"; so :='1'; alm:='1'; elsif mg<"1001" then mg:=mg+1; so :='0';alm:='0';elsif mg="1001" then mg:="0000";ms:=ms+1; so :='0';alm:='0';end if;end if;alarm<=alm;enmin<= so;mins<=ms;ming<=mg;End process;End a;仿真波形图:--Hour1(时计数器4进制与2进制)Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity hour1 isPort(clkh,set:in std_logic;h1,h0:in std_logic_vector(3 downto 0);hours,hourg:buffer std_logic_vector(3 downto 0);enhour: out std_logic);End;Architecture a of hour1 isBeginProcess(clkh,set)variable hs,hg :std_logic_vector(3 downto 0);variable ho:std_logic;BeginIf set='1' then hs:=h1; hg:=h0;Elsif clkh'event and clkh='1' thenif hs="0010"and hg="0011" then hs:="0000";hg:="0000"; ho :='1'; elsif hg<"1001" then hg:=hg+1; ho :='0';elsif hg="1001" then hg:="0000";hs:=hs+1; ho :='0';end if;end if;hours<=hs;hourg<=hg;enhour<=ho;End process;End a;仿真波形图:Library ieee; (星期计数器,7进制)Use ieee.std_logic_1164.all;Use ieee.std_logic_arith.all;Use ieee.std_logic_unsigned.all;Entity week isPort(clkd,set,reset:in std_logic;d1:in std_logic_vector(3 downto 0); -- ――置数端(星期)day:buffer std_logic_vector(3 downto 0)); -- ――星期输出端end;Architecture a of week isBeginProcess(clkd,reset,set,d1)BeginIf reset='0' then day<="0000"; -- ――对星期计时器清0 Elsif set='0' then day<=d1; -- ――对星期计时器置d1的数Elsif clkd'event and clkd='1' thenIf day=6 then day<="0000"; -- ――重复计数Else day<=day+1;End if;End if;End process;End;仿真波形图:--Second2(秒置数模块,6进制和10进制)Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity second2 isPort( clks1:in std_logic;Secs,Secg: out std_logic_vector(3 downto 0));End;Architecture a of second2 isBeginProcess(clks1)variable ss,sg: std_logic_vector(3 downto 0);--(ss:秒十位;sg秒个位) Beginif clks1'event and clks1='1' thenif ss="0101" and sg="1001" then ss:="0000"; sg:="0000";elsif sg<"1001" then sg:=sg+1;elsif sg="1001" then sg:="0000";ss:=ss+1;end if;end if;Secs<=ss;Secg<=sg;end process;End a;仿真波形图:--Min2(分置数模块,6进制和10进制)Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity min2 isPort(clkm1:in std_logic;mins,ming:buffer std_logic_vector(3 downto 0));End;Architecture a of min2 isBeginProcess(clkm1)variable ms,mg :std_logic_vector(3 downto 0);Beginif clkm1'event and clkm1='1' thenif ms="0101" and mg="1001" then ms:="0000";mg:="0000"; elsif mg<"1001" then mg:=mg+1;elsif mg="1001" then mg:="0000";ms:=ms+1;end if;end if;mins<=ms;ming<=mg;End process;End a;仿真波形图:--Hour2(时置数模块,4进制与2进制)Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity hour2 isPort(clkh1:in std_logic;hours,hourg:buffer std_logic_vector(3 downto 0)); End;Architecture a of hour2 isBeginProcess(clkh1)variable hs,hg :std_logic_vector(3 downto 0);Beginif clkh1'event and clkh1='1' thenif hs="0010"and hg="0011" then hs:="0000";hg:="0000"; elsif hg<"1001" then hg:=hg+1;elsif hg="1001" then hg:="0000";hs:=hs+1;end if;end if;hours<=hs;hourg<=hg;End process;End a;仿真波形图:Library ieee; (星期置数模块,7进制)Use ieee.std_logic_1164.all;Use ieee.std_logic_arith.all;Use ieee.std_logic_unsigned.all;Entity week2 isPort(clkd1:in std_logic;day:buffer std_logic_vector(3 downto 0)); -- ――星期输出端end;Architecture a of week2 isBeginProcess(clkd1)Beginif clkd1'event and clkd1='1' thenIf day=6 then day<="0000"; -- ――重复计数Else day<=day+1;End if;End if;End process;End;仿真波形图:library ieee; (闹钟设置模块)use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity nz isport(ml,mh:in std_logic_vector(3 downto 0);hl,hh:in std_logic_vector(3 downto 0);mlo,mho:in std_logic_vector(3 downto 0);hlo,hho:in std_logic_vector(3 downto 0);set:in std_logic;output:out std_logic);end nz;architecture behav of nz issignal opt:std_logic;beginprocess(set,ml,mh,hl,hh,mlo,mho,hlo,hho)beginif set='1' thenif(ml=mlo and mh=mho and hl=hlo and hh=hho)then opt<='1';else opt<='0';end if;end if;output<=opt;end process;end behav;library ieee; (闹钟响铃时长设置)use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all; entity timeset isport( nz:in std_logic;sj:in integer range 0 to 1200;clk:in std_logic;ring:out std_logic);end timeset;architecture behav of timeset is signal count:integer range 0 to 1200; beginprocess(clk)variable co1:std_logic;beginif(clk'event and clk='1') thenif(nz='1') and (count/=sj) thencount<=count+1;co1:='1';else co1:='0';end if;end if;ring<=co1;end process;end behav;闹钟功能模块测试波形图:时间重置模块测试波形图。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
hour2<=hour2+1;
if(hour2=11) then
hour2<=0;
end if;
else
minute<=minute+1;
end if;
else
second<=second+1;
end if;
end if;
if(change='1')then--12/24 style change
if (hour2=23 and minute=59 and second=59) then
clk2<='0';
end if;
end process;
p1:process(clk1)
begin
if(clk1'event and clk1='1') then
if(last='1') then--back to the time ......
if (second=0) then
second<=59;
alarm:in std_logic;
cat:out std_logic_vector(5 downto 0);
spk:out std_logic;
light:out std_logic_vector(6 downto 0));
end memclock;
architecture behave of memn
tmp2<=0;
else
tmp2<=tmp2+1;
end if;
end if;
end process;
p5:process(tmp1)
begin
clk1<='1';
else
clk1<='0';
end if;
if tmp2=999 then
clk2<='1';
else
if(min=59) then
min<=0;
else
min<=min+1;
end if;
end if;
if(hfix='1') then--alarm ho change
if(ho=23) then
ho<=0;
else
ho<=ho+1;
end if;
end if;
end if;
if(minute=0 and second<3) then--right time ring
when 2=>cat<="101111";temp<=m0;
when 3=>cat<="110111";temp<=m1;
when 4=>cat<="111011";temp<=s0;
when 5=>cat<="111101";temp<=s1;
when 0=>cat<="111110";temp<=h0;
基于VHDL语言的数字钟设计
信息与通信工程学院
数字电路与逻辑设计
实验题目:基于VHDL语言的数字钟设计
班级:
姓 名:
学号:
日期:
指 导 教 师:
一.摘要
数字钟是一个将“时”、“分”、“秒”显示于人的视觉器官的计时装置。它的基本功能是计时,计时周期为24小时,显示满刻度23时59分59秒;或者计时周期为12小时并配有上下午指示,显示满刻度为11时59分59秒,通过六个七段数码管显示出来。
when others =>light<="0000000";
End case;
end if;
end process;
end behave;
--made by liaoning
7.时序仿真波形图
仿真的部分,之前已经说过,计数器和数码管显示是本实验核心的部分,所以将这两部分做下仿真,仿真得到预期的效果,再加入分频器下载到实验板上进行调试,之后再加入其他输入输出的功能。
24小时制可切换,12小时制下上下午有不同显示(上午发光二极管不亮,
下午发光二极管亮)。
4.可手动校对时间,能对时和分进行校正。
5.整点报时功能。
6.闹铃功能,可设置闹铃时间,当计时到预定时间时,蜂鸣器发出闹铃信号,
闹铃时间为5秒,可提前终止闹铃。
7.可认为设置时间为倒计时模式
8.可切到屏保模式,六个数码管显示为“supper”字样。
else
second<=second-1;
end if;
else
if (second=59) then--normal time rules
second<=0;
if(minute=59) then
minute<=0;
hour1<=hour1+1;
if(hour1=23) then
hour1<=0;
end if;
fix
ch
clarm
ch
逻辑流程图




是是

6.完整的源程序
6数码管显示时钟,带调时功能,能设置闹钟,闹钟响可人为停止,整点报时,12/24小时制手动切换,可人为设置时间为倒计时,并修正了一个11:59:59(或23:59:59)跳变到00:00:00的bug(即11:59:59跳变到00:00:00时会先跳到11:00:00再跳到00:00:00的错误),不足是防抖动设计缺少经验。
signal hour,hour1:integer range 0 to 23;
signal hour2:integer range 0 to 11;
signal h0,h1,m0,m1,s0,s1:integer range 0 to 15;
signal tmp2:integer range 0 to 999;
计数器仿真:观察时分秒的进制是否正确。
数码管仿真:观察数码管的显示是否正确。
8.故障和故障分析
故障1:验收时出现的bug,在11:59:59跳到00:00:00时会先显示11::00:00再显示00:00:00。
本实验主要在理论分析和具体的软硬件实现上,基于VHDL语言编写源代码,使用软件Quartus II进行处理,再配合具体电路连接,实现一个多功能的数字钟。
关键词:数字钟;VHDL语言;七段数码管
2.设计任务要求
设计实现一个数字钟。
小时制,显示刻度从0:0:0到23:59:59。
小时制,显示刻度从0:0:0到11:59:59。
spk<='1';
elsif(minute=min and hour=ho and second <5) then--alarm clock
if(alarm='1') then
spk<='0';
elsif(alarm='0')then
spk<='1';
end if;
else
spk<='0';
end if;
signal temp:integer range 0 to 15;
signal j:integer range 0 to 5;
signal clk1,clk2:std_logic;
signal minute:integer range 0 to 59;
signal second:integer range 0 to 59;
--made by supper
library ieee;
use memclock is
port(
clk:in std_logic;
mfix,hfix:in std_logic;
change:in std_logic;
last:in std_logic;
ld0:out std_logic;
name :in std_logic;
3.设计思路和总体设计框图
1.设计思路
程序设计主要分为四个模块,第一部分,做分频器,分出一秒的时钟用来计数,再分出一个中频时钟用来扫描显示数码管,我选择的频率是50kHZ;第二部分,做计数器,秒随时钟沿计数进1,分钟随着秒计数60次进一,而小时,由于有12/24小时制的切换,时的计数有两个信号来进行,一个信号hour1是分60进一在0到23循环计数,另一个信号hour2是分60进一在0到11循环计数;第三部分,做扫描显示六个七段数码管,通过选通信号6矢量cat来依次使六个数码管亮,数码管每两位对应相应的时分秒;第四部分,其他输入输出单元,比如数字钟的时间修正,闹铃等,这些都是基于前三个部分,做起来难度不大。
if(minute=0) then
minute<=59;
hour1<=hour1-1;
if(hour1=0) then
hour1<=23;
end if;
hour2<=hour2-1;
if(hour2=0) then
hour2<=11;
end if;
else
minute<=minute-1;
end if;
h0<=(hour-h1)/10;
H1<=hour rem 10;
M0<=(minute-m1)/10;
M1<=minute rem 10;
S0<=(second-s1)/10;
相关文档
最新文档