VHDL课程设计-10kV新建小区电能计量及远程数据系统工程初步设计.doc_第1页
VHDL课程设计-10kV新建小区电能计量及远程数据系统工程初步设计.doc_第2页
VHDL课程设计-10kV新建小区电能计量及远程数据系统工程初步设计.doc_第3页
VHDL课程设计-10kV新建小区电能计量及远程数据系统工程初步设计.doc_第4页
VHDL课程设计-10kV新建小区电能计量及远程数据系统工程初步设计.doc_第5页
已阅读5页,还剩38页未读 继续免费阅读

下载本文档

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

文档简介

VHDL 课程设计题 目 多功能万年历的数字钟设计 专业名称 学生姓名 指导教师 完成时间 一: 课程设计的任务设计一个多功能的数字时钟,具有以下功能: 1. 正常的显示功能:显示AM、PM、时、分、秒(24进制或者12进制)。2. 手动校时功能:按动方式键,将电路置于校时状态,则计时电路可用手动方式校准,每按一下校时键,时计数器加1;按动方式键,将电路置于校分状态,以同样方式手动校分。按动按键有滴滴声,并且数码管显示的数字会闪动。3. 万年历功能:显示年、月、日、星期、是否闰年。4. 手动校正日历功能。按动方式键,将电路置于校年状态,则计时电路可用手动方式校准,每按一下校年键,时计数器加1;按动方式键,将电路置于校月状态,以同样方式手动校月。按动按键有滴滴声,并且数码管显示的数字会闪动。5. 闹钟功能:按动方式键进入闹钟设定模块,设定闹钟时间。闹铃信号到达播放音乐两只蝴蝶,按动停止键则立即停止播放音乐,若不按动停止键则自动播放音乐1分钟后停止。6. 整点播报功能,从59分50秒开始发出播报,每隔2秒发出一声(信号名叫持续时间1秒,间隙1秒)连续发出5次,到达整点时停止播报。7. 秒表功能:按动开始键开始计时,按动停止键数字保持不变,按动复位键从新计时二:系统设计根据以上对于多功能数字钟的功能的描述,可以将整个的电路设计分为以下几个模块:1. 分频模块:由于实验电路板上所能提供的只有1Khz和6Mhz的信号,而本设计过程的即时以及跑表模块需要1hz、100hz和4hz的时钟信号。2. 控制模块:为达到多动能数字钟在计时、校时、显示日历、跑表等不同的模块之间切换,需要控制模块产生时序要不相冲突的控制信号,保证各个模块的功能有序的执行。3. 计时模块:在输入的1hz时钟信号,产生显示的AM、PM、时、分、秒信号,由于要涉及到后面的校时模块,这里采用带有置数的计时模块,在load信号控制下将校时模块设定的时间转载至初始值,在初始值的基础上正常计时。4. 校时模块:当功能切换至校时模块时,本程序采用在外部按键的上升沿即:每按动一次校时键对应显示相应加1。5. 万年历模块:在计时模块的进位输出信号(每次跳动代表一年),产生显示的年、月、日、星期、是否闰年信号,同样类似于计时模块考虑到后面的校正日历模块,这里同样采用带有置数的计时模块,在load信号控制下将校正日历模块设定的日历转载至初始值,在初始值的基础上正常计时。6. 校正日历模块:切换至该模块时,采用外部按键的上升沿:每按动一次校正键对应的显示相应的加1。7. 闹钟模块:这里采用和校时模块同样的电路设定闹钟的时间,一旦触发信号为高电平,触发音乐播放模块,播放歌曲两只蝴蝶,不按停止键播放一分钟自动停止。8. 跑表模块:采用显示毫秒、秒、分的显示格式,并设有stop按钮和reset按钮。9. 显示模块:采用从控制模块中出来的mode 信号为变量,跟随该信号的变化,选着不同的模块的输出信号,通过两个译码器输出数据连接到数码管显示。以上简单的介绍了构成电路的几大模块,下面给出本设计电路的总的模块化示意图: 图 一 系统总模块化示意图三:模块实现根据以上的介绍可知闹钟的设计的组成模块:分频模块、控制模块、计时模块、校时模块、万年历模块、校正日历模块、闹钟模块(包块音乐模块)、跑表模块、显示模块。以下将就着上面的模块电路的各个模块加以详细的说明。对以上模块的实现进行具体的VHDL的设计。注:(在前面定义的子模块,后面不再定义而是直接的例化使用) 一:分频模块由于开发板系统提供的时钟只有1Khz和6Mhz(专用于音乐模块),而本实验的计时模块、音乐模块、跑表模块等需要1hz、100hz的时钟信号,故需要加以分频实现所需信号。分频电路的模块化示意图如下: 图 二 分频电路模块图下面给出分频模块的RTL级的描述:1)10分频模块:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity fenpin10 isport (clk_in:in std_logic;- - 输入时钟信号 clk_out:buffer std_logic);- -输出时钟信号end fenpin10;architecture rtl of fenpin10 issignal cnt:std_logic_vector(3 downto 0);- -定义计数器模值beginprocess (clk_in)beginif (clk_inevent and clk_in=1) then if (cnt=0100) then clk_out=not clk_out; cnt=0000; else cntclk_1khz,- - 时钟输入 clk_out=clk_100hz);- - 时钟输出u1: fenpin10port map (clk_in=clk_100hz, - - 时钟输入 clk_out=clk_10hz); - - 时钟输出u2: fenpin10port map (clk_in=clk_10hz, - - 时钟输入 clk_out=clk_1hz); - - 时钟输出end rtl;3)分频模块的仿真图 图 三 分频模块仿真图仿真图分析:输入信号为1Khz经过分频成功产生100hz和1hz时钟信号二:计时模块本计时完成时间输出功能,根据秒、分、时(24进制)计时原理故需要设计到60、24进制的BCD计数器,并在此基础上构成RTL级的计时描述,模块图如下所示: 图四 计时电路模块图下面给出计时模块的RTL级的描述:由于考虑到后面的跑表和校时模块的预置数,这里的模60、24BCD计数器均设计成带有预置数端口,和暂停计数功能。同时考虑到现实AM、PM,以及整点报时以及对于报时声音时宽的要求,加入实现上述功能的子模块。1)模60BCD计数器 循环的进行0-59计数,产生秒、分信号输出library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cnt60 isport (clk_in,reset,load,stop,en:in std_logic;-输入的时钟、清0、置数、暂停、使能信号 l_in,h_in:in std_logic_vector(3 downto 0);-预置数,高4位和低4位 enout:out std_logic;-输出地进位信号 h,l:out std_logic_vector(3 downto 0);-输出信号的高4位和低4位end cnt60;architecture rtl of cnt60 issignal h_temp,l_temp:std_logic_vector(3 downto 0)beginprocess (clk_in,en) -个位计数进程(0-9)循环计数beginif (reset=1) then-清0l_temp=0000;elsif (load=1) then-下载预置数l_temp=l_in;elsif (clk_inevent and clk_in=0) then-正常计数 if(en=1)and(stop=0) then if (l_temp=1001) then l_temp=0000; else l_temp=l_temp+1; end if; end if;end if;end process low_proc;l=l_temp;process (clk_in,en)-十位计数进程(05)循环计数beginif (reset=1) then-清0h_temp=0000;elsif (load=1) then-下载预置数h_temp=h_in;elsif (clk_inevent and clk_in=0) then-正常计数 if(en=1)and(stop=0) then if (l_temp=1001) then if (h_temp=0101) then h_temp=0000; else h_temp=h_temp+1; end if; end if; end if;end if;end process high_proc;h=h_temp;enout=1 when l_temp=1001 and h_temp=0101 else-计满60产生进位输出 0;end rtl;2)模24BCD计数器 循环进行0-23计数 产生时输出信号library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cnt24 isport ( clk_in,reset,load,stop,en:in std_logic; -输入的时钟、清0、置数、暂停、使能信号 h_in,l_in:in std_logic_vector(3 downto 0);-输入的预置数 enout:out std_logic;-输出进位信号 h,l:out std_logic_vector(3 downto 0);-输出信号的高4位和低4位end cnt24;architecture rtl of cnt24 issignal l_temp:std_logic_vector(3 downto 0);signal h_temp:std_logic_vector(3 downto 0);signal clr:std_logic:=0;-计满模24产生的清0信号beginprocess (clk_in,en,clr)-个位的计数进程(09)循环计数beginif (reset=1) then-清0信号l_temp=0000;elsif (load=1) then-下载预置数l_temp=l_in;elsif (clk_inevent and clk_in=0) then-正常计数 if (en=1)and(stop=0) then if (l_temp=1001) or (clr=1) then l_temp=0000; else l_temp=l_temp+1; end if; end if;end if;end process low_proc;l=l_temp;process (clk_in,en,clr)-十位计数进程(02)循环计数beginif (reset=1) thenh_temp=0000;elsif (load=1) thenh_temp=h_in;elsif (clk_inevent and clk_in=0) then if (en=1)and(stop=0) then if (clr=1) then h_temp=0000; elsif (l_temp=1001) then h_temp=h_temp+1; end if; end if;end if;end process high_proc;h=h_temp;clr=1 when l_temp=0011 and h_temp=0010 else-计满模24产生清0信号 0;enout=clr;-计满24产生进位信号end rtl;3)整点模块 时刻为59分50秒开始报时,知道00分00秒停止library ieee;use ieee.std_logic_1164.all;entity zd isport (clk_in,en:in std_logic;-输入时钟,使能信号 cmh,cml,csh,csl:in std_logic_vector(3 downto 0);-输入的分、秒 voiceon:out std_logic);-声音信号输出end zd;architecture rtl of zd issignal key:std_logic:=0;signal temp:std_logic_vector(3 downto 0);beginprocess (clk_in)-判断时间是否为59分50秒beginif (clk_inevent and clk_in=1) then if (csl=0000)and(csh=0101)and(cml=1001)and(cmh=0101)and(en=1) then voiceon=1; temp=0000; key=1; end if; if (temp=csl)and(key=1) then-声音持续十秒停止 voiceon=0; key=0; end if;end if;end process;end rtl;4)二分频电路因为整点报时10秒,为达到报时信号周期2s,每周期响铃1s,故需通过二分频电路library ieee;use ieee.std_logic_1164.all;entity fenpin2 isport (clk_1hz,en:in std_logic;-输入时钟信号、使能信号(整点报时信号) clk_out:buffer std_logic);-输出周期2s,闹铃1s闹钟信号end fenpin2;architecture rtl of fenpin2 isbeginprocess (clk_1hz)-模2计数beginif (en=1) then if (clk_1hzevent and clk_1hz=1) then clk_out=not clk_out; end if;end if;end process ;end rtl;5)AM、PM电路 当时信号的十进制值为011显示AM,1223显示PMlibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity duan isport (hh,hl:in std_logic_vector(3 downto 0);-输入的时信号的高4位和低4位 b:out std_logic_vector(3 downto 0);-输出的AM或PM信号end duan;architecture rtl of duan issignal temp1:std_logic_vector(7 downto 0);signal temp2:integer range 0 to 35;signal a_on:std_logic;signal b_on:std_logic;signal ab_on:std_logic_vector(1 downto 0):=00;begintemp1=hh&hl;-将高4位和低4位连接temp2=0)and(temp218) then-十进制值在(011)显示AM a_on=1; b_on=18)and(temp2=35) then-十进制值在(12-23)显示PM a_on=0; b_on=1;end if;end process ;ab_onbbbclk_in,reset=reset,load=load,stop=stop,en=en, l_in=sl_in,h_in=sh_in, enout=enout_temp1, l=sl,h=sh);u1: cnt60-下载预置分信号,并产生分时间信号port map (clk_in=enout_temp1,reset=reset,load=load,stop=stop,en=en, l_in=ml_in,h_in=mh_in, enout=enout_temp2, l=ml,h=mh);u2: cnt24-下载预置时信号,并产生时信号port map (clk_in=enout_temp2,reset=reset,en=en,load=load,stop=stop, l_in=hl_in,h_in=hh_in, enout=enout_temp, l=hl,h=hh);enouthl,hh=hh, b=b);u4: zd-根据产生的秒、分信号,在59分50秒开始报时,并持续10秒port map (clk_in=clk_in,en=en,csl=sl,csh=sh,cml=ml,cmh=mh, voiceon=voiceon_temp);u5: fenpin2-根据产生的报时信号,产生周期2s,报时信号1s的声音信号port map (en=voiceon_temp,clk_in=clk_in,clk_out=voiceon);end rtl;7)计时模块的仿真图: 图五 计时模块仿真图仿真图分析:图中reset、stop均处于失效,en有效,在load信号有效下,将预置数22时58分58秒预置给计时模块(相当于调时间),然后load信号失效,进行正常的计数,分、秒进行60进制,时进行24进制计数,当时间为59分50秒时进行整点报时,持续10秒,并按照要求分频产生周期为2s,闹铃时间为1s的声音信号。图中b代表AM、PM显示,图中时间显示应为PM,完全正确。三:校时模块本模块的功能是在外部按键的操作下,实现对计时器的设定初始的时、分、秒预置值,并在load信号的作用下,下载到计时器模块,由于这里涉及的任然是计数过程,过直接采用即时模块中的模60、24进制BCD计数器,AM、PM显示电路,整点报时电路。同时由于在校时过程中要求实时显示,并且呈现闪动的状态,这里采用沿触发的D触发器,将输出信号加以刷新,达到功能要求。下图为校时模块的模块图: 图 六 校时电路模块图下面给出给出校时电路的RTL级描述,由于模60、24计数器等电路在上述计时模块已经详细设计过了,这里不再加以详细介绍,只介绍D触发器1)D 触发器模块:在时钟沿跳变起到刷新输出值,同时设定输入之中为4hz,能达到闪动的目的。library ieee;use ieee.std_logic_1164.all;entity df isport (clk_in,en:in std_logic;-输入时钟,使能信号 d_in:in std_logic_vector(3 downto 0);-输入的时、分、秒预置值 d_out:out std_logic_vector(3 downto 0);-输出至显示模块的时、分、秒预置值end df;architecture rtl of df isbeginprocess (clk_in,en)beginif (clk_inevent and clk_in=1) then-时钟上升沿触发 if (en=1) then d_outsclock,reset=reset,load=0,stop=0,en=en, l_in=0000,h_in=0000, enout=enout_temp1, l=sl_temp,h=sh_temp);u1: cnt60-产生预置分信号port map (clk_in=mclock,reset=reset,load=0,stop=0,en=en, l_in=0000,h_in=0000, enout=enout_temp2, l=ml_temp,h=mh_temp);u2: cnt24-产生预置时信号port map (clk_in=hclock,reset=reset,en=en,load=0,stop=0, l_in=0000,h_in=0000, enout=enout_temp3,l=hl_temp,h=hh_temp);voiceonclk_in,d_in=sl_temp,en=en,d_out=sl);-刷新以及闪动显示功能u4: df port map (clk_in=clk_in,d_in=sh_temp,en=en,d_out=sh);-同上u5: df port map (clk_in=clk_in,d_in=ml_temp,en=en,d_out=ml); -同上u6: df port map (clk_in=clk_in,d_in=mh_temp,en=en,d_out=mh); -同上u7: df port map (clk_in=clk_in,d_in=hl_temp,en=en,d_out=hl); -同上u8: df port map (clk_in=clk_in,d_in=hh_temp,en=en,d_out=hh); -同上u9: duan port map(hl=hl_temp,hh=hh_temp,b=b);-产生AM、PM显示end rtl;3)校时模块的仿真图:图七 校时模块仿真图仿真结果分析:从以上仿真图可以明显的看出sclock、mclock、hclock 的每一次按动都会给相应的模块预置值加1,而且按键的同时伴有按键声音,sclock按动6次,mclock按动11次,hclock按动一次,最终显示的时间为01时11分06秒,显示为AM,同预期结果完全吻合。四:万年历模块本模块实现万年历功能,根据用户设定的初始的年、月、日,以后随着计时模块的计时,正常的显示年、月、日、星期、是否闰年。由于需要显示年、月、日、星期、闰年,故本模块需要有判断是否闰年电路,闰年以及非闰年对应的月天数的译码电路,12进制BCD计数器(用来月循环计数),100进制BCD计数(用来年循环计数),故先画出万年历的模块图如下,然后逐模块设计实现。由于同样涉及到后面的校正万年历模块,所以这里的计数器都采用的是带有置数端的计数器,在load信号的作用下,将校正日历模块(后面介绍)设定的年、月、日下载到万年历模块中,万年历模块在设定数据的基础上继续计时。下图为万年历电路的模块图: 图 八 万年历电路模块图1)闰年模块: 根据输入的年信号,确定改年是否为闰年, library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity run isport (reset,en,load,stop:in std_logic;-输入的重置、使能、暂停信号 yhh_in,yhl_in,ylh_in,yll_in:in std_logic_vector(3 downto 0);-预置的年信号 yhh,yhl,ylh,yll:in std_logic_vector(3 downto 0);-正常计时输出年信号 leap:out std_logic_vector(3 downto 0);-闰年是否信号end run;architecture rtl of run issignal yhh_temp,yhl_temp,ylh_temp,yll_temp:std_logic_vector(3 downto 0):=0000;signal temp:integer range 0 to 10000;beginprocess (load)beginif (reset=1) then-清0yll_temp=0000;ylh_temp=0000;yhl_temp=0000;yhh_temp=0000;elsif (load=1) then-下载预置数yll_temp=yll_in;ylh_temp=ylh_in;yhl_temp=yhl_in;yhh_temp=yhh_in;elsif (en=1)and(stop=0) then-判断正常计时年信号是否为闰年yll_temp=yll;ylh_temp=ylh;yhl_temp=yhl;yhh_temp=yhh;end if;end process ;process (temp)begintemp=conv_integer(yhh_temp)*1000+conv_integer(yhl_temp)*100+conv_integer(ylh_temp)*10+conv_integer(yll_temp);-判断能被4整除,能被400整除,但是不能被100整除 if (temp mod 4)=0) then if (temp mod 100)=0) then if (temp mod 400)=0) then leap=0001; else leap=0000; end if; else leap=0001; end if;else leap=0000; end if; end process ;end rtl; 2)月天数译码模块:根据输入的月数以及改年是否为闰年为条件计算出该月的天数library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity number isport (reset,en,load,stop,:in std_logic;-输入的重置、使能、置数、暂停信号 monh,monl,monh_in,monl_in,leap:in std_logic_vector(3 downto 0);-预置以及输出月数 dayh,dayl:out std_logic_vector(3 downto 0);-输出的对应月的天数end number;architecture rtl of number issignal temp:std_logic_vector(7 downto 0):=XXXXXXXX;beginprocess (load,reset,en,stop)beginif (reset=1) then temp=00000001;-清0elsif (load=1) then temp=monh_in&monl_in;-下载预置数elsif (en=1)and(stop=0) then tempdayl=0001;dayhdayl=1001;dayhdayl=0001;dayhdayl=0000;dayhdayl=0001;dayhdayl=0000;dayhdayl=0001;dayhdayl=0001;dayhdayl=

温馨提示

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

评论

0/150

提交评论