vhl课程设计电子钟闹铃.docx

上传人:罗晋 文档编号:11737716 上传时间:2021-09-02 格式:DOCX 页数:36 大小:39.77KB
返回 下载 相关 举报
vhl课程设计电子钟闹铃.docx_第1页
第1页 / 共36页
vhl课程设计电子钟闹铃.docx_第2页
第2页 / 共36页
vhl课程设计电子钟闹铃.docx_第3页
第3页 / 共36页
vhl课程设计电子钟闹铃.docx_第4页
第4页 / 共36页
vhl课程设计电子钟闹铃.docx_第5页
第5页 / 共36页
点击查看更多>>
资源描述

《vhl课程设计电子钟闹铃.docx》由会员分享,可在线阅读,更多相关《vhl课程设计电子钟闹铃.docx(36页珍藏版)》请在三一文库上搜索。

1、、系统功能概述一)、系统实现的功能:1、具有“时”、“分”、“秒”的十进制数字显示(小时从 00 23 )。2、具有手动校时、校分、校秒的功能。3、有定时和闹钟功能,能够在设定的时间发出闹铃声。4、能进行整点报时。从59分50秒起,每隔2秒发一次低音“嘟”的信号,连续5次,最后一次为高音“嘀”的信号。二)、各项设计指标:1、显示部分采用的6个LED显示器,从高位至低位分别显示时、分、秒。2、有一个设置调闹钟定时时间、正常时间的按钮,选择调的对象。3、有三个按钮分别调时、分、秒的时间。4、有一个按钮用作开启/关闭闹铃。5、另外需要两个时钟信号来给系统提供脉冲信号,使时钟和闹钟正常工作,分别为1H

2、z、1kHz的脉冲。二、系统组成以及系统各部分的设计1、系统结构描述要求:系统(或顶层文件)结构描述,各个模块(或子程序)的功能描述;一)系统的顶层文件:1、顶层文件图:(见下页)2、各模块的解释:1)、7 个输入量 clk_lkhz、clk_lhz、key_slt、key_alarm、 sec_set、 min_set 、hour set :其中clk_lkhz为闹铃模块提供时钟,处理后能产生“嘟”、“嘀”和变化的闹铃声音;clk_lhz为计时模块提供时钟信号,每秒计数一次;选择设置对 key_slt 象:定时或正常时间;key_alarm能够开启和关闭闹铃;sec_set 、min_set

3、、hour_set用于设置时间或定时,与key_slt相关联。各按键输出 为脉冲信号。(2)、CNT60_A_SE 模块:60进制计数,并产生一个分钟BCD码的格式输出。将该输出接通过a.larni_clk可以选择设置对象key上的一个输入脉冲可以将elkkey上的脉冲只修改定时值,不影响这个模块式将clk_lhz这个时钟信号进行的触发信号。该模块能将当前计数值实时按到两位LED数码后能时时显示秒的状态为时间还是定时值。在设置时间模式上,的输入信号加一。在设置定时模式上, 时间脉冲elk的状态。out_di来触发整点报时的“嘟”、“嘀”声音同时该模块具有两个输出口 out_do、CNT60 A

4、 MIN 模块:这个模块式将CNT60_A_SE的输出信号进行60进制计数,并产生一个时位的触发信号。该模块能将当前计数值实时按BCD码的格式输出。将该输出接到两位LED数码后能时时显示分的状态。通过alarm elk可以选择设置对象为时间还是定时值。在设置时间模式上,key上的一个输入脉冲可以将elk的输入信号加一。在设置定时模式上,key上的脉冲只修改定时值,不影响时间脉冲elk的 状态。同时该模块具有三个输出口 out_do、out_di、out_alarm来触发整点报时的“嘟”、“嘀“、闹铃声音。(4)、CNT24_A_H0UR 块:这个模块式将CNT60AMIN勺输出信号做24进制计

5、数。该模块能将当前 计数值实时按BCD码的格式输出。将该输出接到两位LED数码后能时时显示 时勺状态。通过alarm_clk可以选择设置对象为时间还是定时值。在设置时 间模式上,key上的一个输入脉冲可以将elk的输入信号加一。在设置定时 模式上,key上的脉冲只修改定时值,不影响时间脉冲elk的状态。同时该模块具有一个输出口 out_alarm来触发整点报时的闹铃声音。(5)、PWM_01 模块:该模块为PWM产生模块,通过EN可开启和关闭PWMt出。模块根据CLK 信号二分频产生的高低音,并组合,能输出三种声音状态嘟”闹铃。而该三种声音要被秒、分、时的输出触发才能输出PWo(二)系统各个模

6、块的VHDL程序:(1)、CNT60_A_SE 模块:程序源代码如下:library ieee;use ieee.std_logic_1164. all;use ieee.std_logic_unsigned. all;entity cnt60_a_sec isport (:清零端,elk, clr, enb: in std_logic;-elk:时钟输入信号,clrenb:使能端key: in std_logic;-输入按键脉冲,调整闹铃定时或时间alarm_clk: in std_logic;-1:alarmO:clk 一 设置模式选择:闹铃调节模式、时间调节模式qout_sl: out

7、std_logic_vector (3 down to显示输出秒的低位0); -qout_sh: out std_logic_vector (3 down to显示输出秒的高位0);-co: out std_logic;进位输出,触发分计数模块out_do: out在整点报时中输出“嘟”触发信号std_logic;-out_di: out std_logic在整点报时中输出“嘀”触发信号);一一end;architecture a of cnt60_a_sec is signal qout2_l:std_logic_vector(3downto 0);signal qout2_h:std_lo

8、gic_vector (3 downto 0);signal alarm_l:std_logic_vector(3 downto 0);signal alarm_h:std_logic_vector(3 downto 0);signal clkl, clk2, tclk, aclk, ac_slt: std_logic;begin process(alarm_clk) -当 该端口输入一个脉冲时,修改设置模式:时间调整或 闹铃模式切换beginif alarm_clk,event and alarm_clk=,1 thenif ac_slt=,0J then-如果为定时模式,将改为闹铃模式el

9、seac_slt=,O;end if;end if;end process;process (key, elk, ac_slt)-根据设置模式,处理key上的脉冲信号beginif ac_slt= 0,then 时间调整模式aclk= ;if elk=T and key=1 then -clk=l则 tclk=0 ,通过挖洞方式添加一个脉冲tclk= O;elsif elk=O and key=T then -clk=O,则 tclk=l,产生一个高电平,添加一脉冲tclk= f ;elsetclk=clk;end if;elsif ac_slt=,T then -闹铃调整模式tclk=clk

10、;aclk=key; -key上的脉冲直接修改闹铃定时值end if;end if;end if;end process;表示秒process (tclk, clr, enb)-60进制计数,个位、十位放在两个临时变量中,的状态beginif clr=1 then-clearing works at the state of high voltageqout2_l=,z0000/z;qout2_h=,z0000z,;elsif tclkevent and tclk=,1 thenif enb=1 then-enable works at high voltageif qout2_l=,/100

11、rz and qout2_h=0101 thenqout2_l(二0000;-afull mode is completed and acarryout is generatedqout2_h=,/0000/,;elsif qout2_l=1001 thenqout2_l=/0000,/;qout2_h=qout2_h+l;elseqout2_l=qout2_l+l;- in process of countingend if;end if;end if;end process;process (aclk, clr, enb)-修改闹铃的定时值beginif clr=1 then-cleari

12、ng works at the state of high voltagealarm=0000 ;alarm_h=,0000,/;elsif aclk,event and aclk=,1 thenif enb=1 then-enable works at high voltageif alarm_l=/l00l/z and alarm_h=0101 thenalarm二0000;-afull mode is completed and acarryout is generatedalarm_h=,0000/z;elsif alami_l=0101 thenalarm二 0000 ;alarm_

13、h=alarm_h+l;elsealarm_l=alarm_l+l;一- in process of countingend if;end if;process (qout2_l, qout2_h, alarm_l, alarm_h, alarm_clk) -产生进位 , 显示时间或闹铃定时值beginif qout2二0000 and qout2_h=0000 thenco=,V ;elseco=,O;end if;if ac_slt=O then -显示时间qout_sl=qout2_l;qout_sh=QOUt2_h;else显不定时值qout_sh=alarm_h;qout_sl=al

14、arm_l;end if;end process;process (qout2_l, qout2_h) -根据秒的状态输出“嘟”、“嘀”触发信号beginif qout2_h=/010rz thenif qout2_l=0000 thenout_do=, r ;elsif qout2_l=z/0010/z thenout_do=, r ;end e*if qout2_l=0100 thenend process;out_do=,1;elsif qout2_l=z,0110/z thenout_do=, r ;elsif qout2_l=/,1000z,thenout_do=,1;elseout

15、_do=,O;end if;elsif qout2_h=,0000/z thenif Qout2_l=/,0000z/ thenout_di=,1;out_do=,O;elseout_di=,O;end if;elseout_do=,O;out_di=,O;、CNT60 A Mir 模块:end if;library ieee;use ieee. std_logic_1164. all;use ieee. std_logic_unsigned.all;entity cnt60_a_min isport (elk, clr, enb: in std_logic; -elk:时钟输入信号,clr

16、:清零端,enb:使能端key: in std_logic; -输入按键脉冲,调整闹铃定时或时间alarm_clk: in std_logic; -1:alarm 0:clk- 设置模式选择:闹铃调节模式、时间调节模式qout_ml: out std_logic_vector (3 down to 0); -显示输出分的低位qout_mh: out std_logic_vector (3 down to 0); -显示输出分的高位co: out std_logic; -进位输出,触发时计数模块out_alarm:out std_logic;-闹铃触发信号,时间到后输出高电平触发闹铃out_do

17、, out_di : out Std_logic 在整点报时中输出“嘟”“嘀”触发信);end;architecture a of cnt60_a_min is signal qout2_l:std_logic_vector(3 downto0);signal qout2_h:std_logic_vector(3 downto 0);signal alarm_l:std_logic_vector(3 downto 0);signal alarm_h:std_logic_vector(3 downto 0);signal clkl,clk2,tclk, aclk, ac_slt: std_log

18、ic;beginprocess (alarm_clk) 当 该端口输入一个脉冲时,修改设置模式:时间调整或闹铃模式 切 换beginif alarm_clk,event and alarm_clk=,1 thenif ac_slt=,0,then 如果为定时模式,将改为闹铃模式ac_slt=,1;elseac_slt=,0:end if;end if;end process;process (key, elk, ac_slt) 一根据设置模式,处理key上的脉冲信号beginif ac_slt=,0,then 时间调整模式aclk= O;if elk=1 and key=T then-clk=

19、l则 tclk=0 ,通过挖洞方式添加一个脉冲tclk= O;则tclk=l,产生一个高elsif elk=O and key=1 then一一clk=O,电平,添加一脉冲tclk= f ;elsetclk=clk;end if;elsif ac_slt=,1? then - 闹铃调整模式tclk=clk;aclk=key; -key上的脉冲直接修改闹铃定时值end if;end process;process (tclk, clr, enb)-60进制计数,个位、十位放在两个临时变量中,表示分的状态beginif clr=,1 then-clearing works at the state

20、 of high voltageqout2_K=,0000,z;Qout2_h=,/0000/;elsif tclk? event and tclk=1 thenif enb=,1 then-enable works at high voltageif qout2_l=1001 and qout2_h=0101 thenqout2_l二0000;一一afull mode is completed and acarryout is generatedqout2_h=0000;elsif qout2_l=1001 thenqout2_l=,/0000/,;qout2_h=qout2_h+l;els

21、eqout2_K=qout2_l+l;- in process of countingend if;end if;end if;end process;process (aclk, clr, enb) -修改闹铃的定时值beginif clr=,1 then-clearing works at the state of high voltagealarm_l=/z0000z,;alarm_h=/0000,/;elsif aclkJ event and aclk=,1 thenif enb=,1 then-enable works at high voltageif alarm_l=z/100r

22、,and alarni_h=0101 thenalarm_l=z/0000/z;-afull mode is completed and acarryout is generatedalarm_h=zz0000,z;elsif alarm 1=”0101 thenalarm二”0000 ;a1arm_h=a1arm_h+1;elsealarm_l=alarm_l+l;一- in process of countingend if;end if;end if;end process;产生进位,显process(qout2_l, qout2_h, alarm_l, alarm_h, alarm_c

23、lk) -示时间或闹铃定时值of high voltagebeginif qout2_l=0000 and qout2_h=0000 thenco二1;elseco=,0,;end if;if ac_slt=,O thenqout_ml=Qout2_l;qout_mh=qout2_h;elseqout_mh=a1arm_h;qout_ml=alarm_l;end if;end process;-判断定时值与时间值相process(qout2_l, qout2_h, alarm_l, alarm_h)等,输出闹铃触发信号beginif qout2_l=alarm_l and qou12_h=a1

24、arm_h thenout_alarm=,1;elseout_alarm=,O;end if;end process;process (qout2_l, qout2_h) -根据分的状态输出“嘟”、“嘀”触发信号beginif qout2_l=/100r,and qout2_h=0101 thenout_do=,1;elseout_do=,O;end if;if qout2_l=zz0000z,and qout2_h=0000 thenout_di=,1;elseout di=O;end if;end process;end;(3)、CNT24_A_H0UR 块:library ieee;us

25、e ieee. std_logic_1164.all;use ieee. std_logic_unsigned. all;entity cnt24_a_hour isport (elk, clr, enb: in std_logic; -elk:时钟输入信号,clr :清零端,enb:使能端key: in std_logic; -输入按键脉冲,调整闹铃定时或时间alarm_clk: in std_logic;-1:alarm 0:clk一 设置模式选择:闹铃调节模式、时间调节模式qout_hl: out std_logic_vector (3 down to 0); -显示输出时的低位qout

26、_hh: out std_logic_vector (3 down to 0); -显示输出时的高位co: out std_logic; - 进位输出out_alarm:out std_logi-闹铃触发信号输出);end;architecture a of cnt24_a_hour issignal qout2_l:std_logic_vector(3 downto 0);signal qout2_h:std_logic_vector(3 downto 0);signal alarm_l:std_logic_vector(3 downto 0);signal alarm_h:std_logi

27、c_vector(3 downto 0);signal clkl,clk2,tclk, aclk, ac_slt: std_logic;begin process (alarm_clk) -当该端口输入一个脉冲时,修改设置模式:时间调整或闹铃模 式切换beginif alarm_clk,event and alarm_clk=,1 thenif ac_slt=,O then-如果为定时模式,将改为闹铃模式ac_slt=,1;elseac_slt=,O;end if;end if;end process;process (key, elk, ac_slt) -根据设置模式,处理key上的脉冲信号

28、beginif ac_slt=,0, then - 时间调整模式aclk= 0;if clk=,r and key=T then-clk=l则 tclk=0 ,通过挖洞方式添加一个脉冲tclk= O;elsif elk=O and key二T then-clk=O, 则 tclk=l,产生一个高电平,添加一脉冲tclk= f ;elsetclk=clk;end if;elsif ac_slt=,1? then - 闹铃调整模式tclk=clk;aclk=key; -key上的脉冲直接修改闹铃定时值end if;end process;process (tclk, clr, enb)-24进制计

29、数,个位、十位放在两个临时变量中,表示时的状态beginif clr=,1 then-clearing works at the state of high voltageQout2_l=,/0000,Qout2_h=z/0000/z;elsif tclk event and tclk=1 thenif enb=,1 then-enable works at high voltageif qout2_l=zz100r/ thenqout2=0000;一afull mode is completed and acarryout is generatedqout2_h=qout2_h+l;elsi

30、f qout2_l=00n and qout2_h=0010 thenqout2_K=,/0000z,;qout2_h二0000;elseqout2_K=Qout2_l+l;- in process of countingend if;end if;end if;end process;process (aclk, clr, enb) - 修改闹铃的定时值beginif clr=,1 then-clearing works at the state of high voltagealarm二 0000 ;alarm二 0000 ;elsif aclk5 event and aclk=1 the

31、nif enb=,1 then-enable works at high voltageif alarm_l=/z100r,thenalarm_l=zz0000,z;-afull mode is completed and acarryout is generatedalarm_h=qout2_h+l;elsif alarm_l=/OOir,and alarm_h=/z0010,z thenalarm二”0000 ;alarm_h=”0000;elsealarm_l=alarm_l+l;一一 in process of countingend if;end if;end if;end proc

32、ess;process (qout2_l, qout2_h, alarm_l, alarm_h, alarm_clk) -产生进位 , 显示时间或闹铃定时值of high voltage beginif qout2_l=/z0000,z and qout2_h=0000 thenco=,f ;elseco=O;end if;if ac_slt=,O thenqout_hl=qout2_l;qout_hh=qout2_h;elseQout_hh=alarm_h;qout_hl=alarm_l;end if;end process;process (qout2_l, qout2_h, alarm_

33、l, alarm_h) -定时值与时间值相等,贝U输出闹钟触发信号beginif Qout2_l=alarm_l and qou12_h=a1arm_h thenout_alarm=,1;elseout_alarm=,O;end if;end process;end;2、系统以及各个模块的仿真波形1)、系统仿真波形:注:由于下面的模块仿真存在毛刺,导致系统的仿真图有一定的问题。(2)、CNT60 A SE 模块:注:在50、52、54、56、58处有嘟触发输出,00处有嘀触发输出等。(3)、CNT60_A_Mir 模块:注:本图展示了按键调节时间值和定时值的仿真波形(部分仿真图)注:该模块的仿

34、真波形图,具有嘟、嘀声音触发输出,定时与时间相等时有闹铃触发输出等。(4) 、 CNT24_A_H0UR 块注:该模块的仿真图,包含按键调整时间、定时值,闹钟触发输出等。(5)、PWM/U模块(分三段剪切下来的,展示了三种声音的效果)(1)、“嘟”、“嘀”输出波形(只有在en有脉冲,打开PWM后,才有效)注:在打开输出后,当两路嘟、嘀触发输入同时有效时分别输出嘟、嘀声音。当两路闹铃触发同时有效时开始闹铃声音的输出。注:闹铃输出的变化情况(“嘀”、“嘟”交替发声)注:闹铃输出的变化情况。3、下载时选择的开发系统模式以及管脚定义表1 GW48-CK开发系统工作模式:3接口名称类型(输入/输出)结构

35、图上的信号名引脚号说明clk_lhz输入CLOCKO2时钟的计数脉冲clk_lkhz输入CL0CK583二种声音的脉冲信号源p wm_out输入SPEAKER3连接蜂鸣器,发出声音key_slt输入PI0716切换定时调整模式和时间调整模式key_alarm输入PI0611开启或关断声音的产生hour_set输入PI038修改定时或时间的小时数值min_set输入PI027修改定时或时间的分钟数值sec_set输入P1016修改定时或时间的秒的数值hour_h3. 0输出PI039-PI03665-61小时的高位输出hour_l3. 0输出PI035-PI03260-58,54小时的低位输出m

36、in_h3. . 0输出PI031-PI02853-50分钟的高位输出min_l 3. . 0输出PI027-PI02449-47,39分钟的低位输出sec_h3. . 0输出PI023-PI02038-35秒的高位输出sec_I 3. . 0输出PI019-PI01630-27秒的低位输出三、课程设计过程中遇到的问题以及解决方法主要是在“调整时间”和“调整定时”的上面遇到非常大的困难。与开始想象的不一样,一个进程中不能加入时钟信号,没能够将按键脉冲直接与时钟脉冲进行累加。同时,在对VHDL的语法的熟悉上也花费了大量的时间。最后的解决方法是,通过另一个进程,先将这两个信号进行处理后,分别产生a

37、cik和tcik分别为定时调整部分、和时间调整部分提供时钟信号。调整按键的脉冲信号和正常的时钟信号不是按照简单的或运算来处理的。1)、如果要调整时间:1、当时钟信号是高电平,按键信号也是高电平时,则给tcik赋值0。2、当时钟信号是高电平,按键信号是低电平时,则给tcik赋值lo3、当时钟信号是低电平,按键信号是高电平时,则给tdk赋值lo4、当时钟信号是低电平,按键信号是低电平是,则给tcik赋值0。这样无论按键脉冲是在高电平还是低电平,或者是在高低电平两种状态下出现,其最终结果都是会多产生一个脉冲信号,导致计数值变化,达到修 改时间的目的。期间,acik始终不变。2)、如果要调整定时:1、时钟输入信号赋值给tclk2、按键输入信号赋值给aclk这样,当按键脉冲结束时,定时调整信号会出现一个脉冲。而时钟信号不受影响。另外,在闹铃产生上也遇到了一些小问题,最后,通过在产生周期较长的信 号,切换输出 值的内容“嘟”还有“嘀”,最后的效果就是“嘟”、“嘀”声音交替发出。在仿真时,大多数模块会出现毛刺,会导致最后的总仿真结果不是很乐观,会把脉冲的几 个干扰加上去。这方面,我试图调了很久也没解决。不过由于在实际下载后还是相对比较正常 的,仿真中的毛刺最后没有消除掉。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1