基于FPGA的语音数字时钟系统

  • 格式:doc
  • 大小:102.50 KB
  • 文档页数:23

基于FPGA的语音数字时钟系统设计1.设计要求:(1)计时功能:这是这个计时器设计的基本功能,每隔一分钟记一次时间并在屏幕上显示出当前时间。

(2)闹钟功能:如果当前时间与设置的闹钟时间相同,则扬声器会发出报时声音。

(3)设置新的计时器时间:用户用数字键0~9输入新的时间,然后按下TIME健确认。

(4)设置新的闹钟时间:用户用数字键0~9输入新的闹钟时间,然后按下ALARM健确认。

(5)显示所设置的闹钟时间:在正常记时显示状态下,用户直接按下ALARM健,则显示器上显示已经设置好的闹钟时间。

2.设计思路:控制器命名为Alarm_controller,外部端口各个端口定义:(1)Clk外部时钟信号(2)Reset复位信号(3)Alarm_botton闹钟信号,当其为高电平时,表示用户按下(4)Time_botton时间信号,当其为高电平时,表示用户按下(5)Key键盘信号,当其为高电平时,表示用户按下0~9(6)Load_new_a读取新的闹钟时间,高电平有效(7)Load_new_c控制设置新的时间,高电平有效(8)Show_new_time读取并显示新的时间,高电平有效(9)Show_a当Show_new_time为低电平时,根据Show_a控制当前是显示闹钟时间还是时钟时间根据端口的设置以及控制要求,设定如下5个状态S0:闹钟正常计数状态S1:键盘输入状态,当用户按下键盘,即进入此状态,当一段时间后用户没有按下Alarm或者Time确认,则自动返回S0状态S2:设定闹钟状态,当用户按完键盘,按下Alarm键时进入此状态S3:设定时间状态,当用户按完键盘,按下Time键时进入此状态S4:显示闹钟时间,当用户直接按下Alarm键时,进入此状态在S4状态下,用户按下Alarm键时钟即显示闹钟时间,经过一段延时之后,时钟从新恢复S0状态。

以下是程序流程表程序:程序包P_alarm封装定义library IEEE;use IEEE.std_logic_1164.all;package P_alarm issubtype t_digital is integer range 0 to 7;subtype t_short is integer range 0 to 65535;type t_clock_time is array(3 downto 0) of T_digital;type t_display is array(3 downto 0) of Std_logic_vector(6 downto 0); type seg7 is array(0 to 7) of Std_logic_vector(6 downto 0); constant Seven_seg:seg7:=("0000000001",--0"0000000010",--1"0000000100",--2"0000001000",--3"0000010000",--4"0000100000",--5"0001000000",--6"0010000000",--7"010*******",--8"1000000000",--9);end package P_alarm;--程序包体封装结束library IEEE;use IEEE.std_logic_1164.all;use WORK.P_alarm.all;ENTITY Alarm_contorller isport(Key,Alarm_botton,Time_botton,clk,reset:in std_logic;Load_new_a,Load_new_c,Show_new_time,Show_a:outstd_logic);end Alarm_controller;ARCHITECTURE art of Alarm_controller istype t_state is(s0,s1,s2,s3,s4);--5种工作状态constant key_timeout:t_short:=900;--键盘延时时间constant show_alarm_timeout:t_short:=900;--alarm jian yan shi 900ns signal curr_state:t_state;--zhuang tai ji dang qian zhuang tai wei signal next_state:t_state;--zhuang tai ji xia yi gong zuo weisignal counter_k:t_state;--jian pansignal enable_count_k:std_logic;--jian pan chao shi yun xusignal count_k_end:std_logic;--jian pan chao shisignal counter_a:t_short;--alarm jiansignal enable_count_a:std_logic;--alarm jian chao shi yun xusignal count_a_end:std_logic;--alarm jian chao shi jie shubeginp0:process(clk,reset)beginif reset='1'thencurr_state<=s0;elsif rising_edge(clk)thencurr_state<=next_state;end if;end process;p1:process(Key,Alarm_botton,Time_botton,curr_state,count_a_end,cou nt_k_end)begin --gei ge ge shu chu fu chu shi zhinext_state<=curr_state;load_new_a<='0';load_new_c<='0';show_a<='0';show_new_time<='0';enable_count_k<='0';enable_count_a<='0';case curr_state iswhen s0=>if(Key='1')thennext_state<=s1;Show_new_time<='1';elsif(Alarm_botton<='1')thennext_state<=s2;Show_a<='1';elsenext_state<=s0;null;end if;when s1=>if(key='1')thennext_state<=s1;Show_new_time<='1';elsif(Alarm_botton<='1')thennext_state<=s2;Load_new_a<='1';elsif(Time_botton<='1')thennext_state<=s3;Load_new_c<='1';if(count_k_end='1')thennext_state<=s0;null;elsenext_state<=s1;Show_new_time<='1'; end if;enable_count_k<='1'; end if;when s2=>if(Alarm_botton<='1')thennext_state<=s2;Load_new_a<='1';elsenext_state<=s0;null;end if;when s3=>if(Time_botton<='1')thennext_state<=s3;Load_new_c<='1';next_state<=s0;null;end if;when s4=>if(Alarm_botton<='1')thennext_state<=s4;elseif(count_a_end='1')thennext_state<=s0;null;elsenext_state<=s4;Show_a<='1';end if;enable_count_a<='1';end if;when others=>null;end case;end process;Count_key:process(Enable_count_k,clk)beginif (Enable_count_k<='0')thenCounter_k<='0';count_k_end<='0';elsif (rising_edge(clk))thenif(counter_k>=key_tinmeout)thencount_k_end='1';elsecounter_k<=Counter_k+1;end if;end if;end process Count_key;Count_alarm:process(Enable_count_a,clk) beginif(enable_count_a<='1')thencounter_a<='0';count_a_end<='0';elsif (rising_edge(clk))thenif (counter_a>=show_alarm_timeout)thencount_a_end<='1';elsecounter_a<=counter_a+1;end if;end if;end process Count_alarm;end art;二.闹钟系统译码器设计1.设计思路:每次按下闹钟系统的数字键盘后产生一个数字所对应的10位二进制数据信号转换为1位十进制整数信号,作为小时,分钟计数的4个数字之一。