多功能秒表VHDL_第1頁
多功能秒表VHDL_第2頁
多功能秒表VHDL_第3頁
多功能秒表VHDL_第4頁
多功能秒表VHDL_第5頁
已閱讀5頁,還剩12頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、評閱老師分 數數字電路課程設計班 級 06級 一班 專 業 信息工程 姓 名 苗捷 序 號 17 1 題目要求多功能秒表設計設計一個可以順計時和倒計時的秒表。要求計時的范圍為00.0S99.9S,用三位數碼管顯示。基本要求:(80分)(1) 倒計時:通過小鍵盤可以實現設定計時時間(以秒為單位,最大計時時間為99.9秒)。通過鍵盤實現計時開始、計時結束。當所設定的倒計時間到達0.00S后,自動停止倒計時,同時響鈴。(2) 順計時:初始值為0.00S,通過鍵盤實現開始計時和結束計時功能。計時結束后,顯示記錄的時間。(3) 用三個發光二極管正確顯示以下狀態:倒計時狀態、順計時狀態、待機狀態。(4)

2、每當接收到有效按鍵時,蜂鳴器發出提示聲。擴展功能:(20分)順計時在一次計時中可以記錄三個不同的結束時間,并能通過按鍵顯示三次所記錄的時間。說明:以上各項功能的功能鍵設置自定,不作統一規定,以簡單且使用靈活方便操作為原則。2 設計方案(或設計分析)經過對題目的分析和思考,我所確立的初步方案如下:控制器鍵盤輸入計數器數碼管LED蜂鳴器圖(1)初步邏輯功能分析框圖如上圖可見,需要一個核心控制器來對系統進行整體控制,按鍵輸入部分收到按鍵信號后傳遞給控制器,控制器根據當前狀態進行相應的動作,包括:控制計數器的運行和數碼管的顯示,控制蜂鳴器指示操作有效,控制LED顯示當前狀態。題目要求設計一個可以順計時

3、和倒計時的秒表,計時的范圍為00.0S99.9S,三位數碼管顯示。所以計數器部分是一個可以雙向選擇記時的3位10進制計數器,數碼管掃描顯示當前計數值,同時還要考慮在一定狀態時要讓數碼管閃爍。鍵盤部分可以使用通常使用的掃描法來實現。初步確定按鍵有五個,但是在實際編寫過程中為了節省系統資源,對案件功能進行了一定得復用,一共用了四個按鍵,所以就用不著對鍵盤進行掃描了,這樣節省了系統的資源,同時也減少了復雜性。考慮到要進行模塊化劃分,所以以上的邏輯功能劃分不能直接使用,所以再次進行了如下的模塊劃分。控制器鍵盤輸入計數器數碼管LED蜂鳴器圖(2)初步模塊劃分框圖3 模塊實現在實際編寫過程中,最終確定系統

4、分為三個模塊,分別如下:模塊1:keyboard圖(3)模塊1:keyboard鍵盤模塊,把鍵盤信號發送給控制器。具體源代碼如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity keyboard isport(clk : in std_logic; key_out : out std_logic_vector(3 downto 0); key_in : in std_logic_vector(3 downto 0); key : out std_logic_vector(2 down

5、to 0);end entity;architecture behav of keyboard istype type_state is (s0,s1);beginkey_out <= "0111" proc1:process(clk) begin if rising_edge(clk) thencase key_in iswhen "1110"=> key<="000"when "1101"=> key<="001"when "1011"=&g

6、t; key<="010"when "0111"=> key<="011"when others=> key<="111"end case; end if; end process;end behav;模塊2:counter圖(4)模塊2:counter最主要的部分,采用單進程法實現,主要部分是一個三位十進制計數器,接收keyboard的鍵盤信號后進行相應的響應,控制LED和蜂鳴器并輸出顯示信號。具體源代碼如下:library ieee;use ieee.std_logic_1164.

7、all;use ieee.std_logic_unsigned.all;entity counter isport(clk : in std_logic; key : in std_logic_vector(2 downto 0); bcd1 : out std_logic_vector(3 downto 0); bcd2 : out std_logic_vector(3 downto 0); bcd3 : out std_logic_vector(3 downto 0); flash_mask : out std_logic_vector(2 downto 0); bell : out st

8、d_logic; led_up : out std_logic; led_down : out std_logic; led_pause : out std_logic; key_beep : out std_logic);end entity;architecture behav of counter issignal cnt1 : std_logic_vector(3 downto 0);-10signal cnt2 : std_logic_vector(3 downto 0);-1signal cnt3 : std_logic_vector(3 downto 0);-0.1type ty

9、pe_mode is (reset,pause,up,down,ov_down,buf,set1,set2,set3);signal mode : type_mode;constant key_sp : std_logic_vector := "000"-start pause incconstant key_set : std_logic_vector := "001"-setconstant key_dir : std_logic_vector := "010"constant key_reset : std_logic_vect

10、or := "011"constant key_null : std_logic_vector := "111"begin proc1:process(clk) variable key_tri : std_logic := '0' variable dir : std_logic := '0'-0=up, 1=down variable tick : integer range 0 to 50; variable buf1,buf2,buf3 : std_logic_vector(11 downto 0); variab

11、le buf_cnt1,buf_cnt2 : integer range 0 to 2; begin if (rising_edge(clk) then if key=key_null then key_tri := '0' end if; case mode is when reset =>- tick := 0; key_tri := '1' cnt1 <= (others => '0'); cnt2 <= (others => '0'); cnt3 <= (others => 

12、9;0'); dir := '0' bell <= '0' mode <= pause; when pause =>- led_pause <= '0' flash_mask <= "111" if dir='0' then-up led_up <= '0' led_down <= '1' else-down led_up <= '1' led_down <= '0' end if; i

13、f key_tri='0' thenkey_tri := '1' case key is when key_sp => led_pause <= '1' flash_mask <= "000" if dir='0' then mode <= up; else mode <= down; end if; when key_set => mode <= buf; when key_dir => tick := 0; if dir='0' then di

14、r :='1'-down led_up <= '1' led_down <= '0' else dir :='0'-up led_up <= '0' led_down <= '1' end if; when key_reset => mode <= reset; when others => key_tri := '0' end case; end if; when up =>- if key_tri='0' then

15、key_tri := '1' case key is when key_sp => mode <= pause; when key_set =>case buf_cnt1 iswhen 0 =>buf1:=cnt3&cnt2&cnt1;when 1 =>buf2:=cnt3&cnt2&cnt1;when 2 =>buf3:=cnt3&cnt2&cnt1;mode <= pause;end case;buf_cnt1:=buf_cnt1+1; when key_dir => null;

16、 when key_reset => null; when others => key_tri := '0' end case; end if; tick := tick + 1; if tick=49 then tick := 0; cnt3 <= cnt3 + 1; if cnt3="1001" then cnt3 <= "0000" cnt2 <= cnt2 + 1; if cnt2="1001" then cnt2 <= "0000" if cnt1=&q

17、uot;1001" then- cnt3 <= "1001"- cnt2 <= "1001" mode <=reset; elsecnt1 <= cnt1 + 1; end if; end if; end if; end if; when down =>- if key_tri='0' then key_tri := '1' case key is when key_sp => mode <= pause; when key_set =>null; when key

18、_dir => null; when key_reset => null; when others => key_tri := '0' end case; end if; tick := tick + 1; if tick=49 then tick := 0; cnt3 <= cnt3 - 1; if cnt3="0000" then cnt3 <= "1001" cnt2 <= cnt2 - 1; if cnt2="0000" then cnt2 <= "1001&

19、quot; if cnt1="0000" then cnt3 <= "0000" cnt2 <= "0000" mode <= ov_down; elsecnt1 <= cnt1 - 1; end if; end if; end if; end if; when ov_down =>- bell <= '1' if (key/=key_null) then mode <= reset; end if; when buf =>- flash_mask <= "

20、;000" case buf_cnt2 iswhen 0 =>cnt3 <= buf1(11 downto 8);cnt2 <= buf1(7 downto 4);cnt1 <= buf1(3 downto 0);when 1 =>cnt3 <= buf2(11 downto 8);cnt2 <= buf2(7 downto 4);cnt1 <= buf2(3 downto 0);when 2 =>cnt3 <= buf3(11 downto 8);cnt2 <= buf3(7 downto 4);cnt1 <=

21、 buf3(3 downto 0);end case; if key_tri='0' then key_tri := '1' case key is when key_sp => buf_cnt2 := buf_cnt2 + 1; when key_set => mode <= set1; when others =>key_tri := '0' end case; end if; when set1 =>- flash_mask <= "001" if key_tri='0'

22、; then key_tri := '1' case key is when key_sp => cnt1 <= cnt1 + 1; if cnt1="1001" then cnt1 <= "0000" end if; when key_set => mode <= set2; when key_dir => null; when key_reset => null; when others =>null; key_tri := '0' end case; end if; w

23、hen set2 =>- flash_mask <= "010" if key_tri='0' then key_tri := '1' case key is when key_sp => cnt2 <= cnt2 + 1; if cnt2="1001" then cnt2 <= "0000" end if; when key_set => mode <= set3; when key_dir => null; when key_reset => n

24、ull; when others => key_tri := '0' end case; end if; when set3 =>- flash_mask <= "100" if key_tri='0' then key_tri := '1' case key is when key_sp => cnt3 <= cnt3 + 1; if cnt3="1001" then cnt3 <= "0000" end if; when key_set =>

25、 mode <= pause; when key_dir => null; when key_reset => null; when others => key_tri := '0' end case; end if; end case; key_beep <= key_tri; end if; end process;bcd1 <= cnt1;bcd2 <= cnt2;bcd3 <= cnt3; end architecture;模塊3:display圖(5)模塊3:display顯示模塊,接收counter模塊的顯示信號,并在

26、數碼管上進行掃描輸出,同時還具有控制顯示閃爍的功能。具體源代碼如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity display is port(clk:in std_logic; flash_mask : in std_logic_vector(2 downto 0); bcd1 : in std_logic_vector(3 downto 0); bcd2 : in std_logic_vector(3 downto 0); bcd3 : in std_logic_vector

27、(3 downto 0); bcd : out std_logic_vector(3 downto 0); lsd : out std_logic_vector(2 downto 0); point : out std_logic);end display;architecture behav of display isbegin pro_lsd:process(clk) variable cnt : integer range 1 to 3; variable tick : integer range 0 to 127; begin if rising_edge(clk) then tick

28、 := tick + 1; lsd<="000" case cnt is when 1 => bcd <= bcd1; cnt := 2; point <= '0' if flash_mask(0)='1' and tick>63 then lsd(0) <= '0' else lsd(0) <= '1' end if; when 2 => bcd <= bcd2; cnt := 3; point <= '1' if flash_mas

29、k(1)='1' and tick>63 then lsd(1) <= '0' else lsd(1) <= '1' end if; when 3 => bcd <= bcd3; cnt := 1; point <= '0' if flash_mask(2)='1' and tick>63 then lsd(2) <= '0' else lsd(2) <= '1' end if; end case; end if; end pro

30、cess;end architecture;總連接圖:程序最終使用了125個宏單元和25個管腳。4 仿真分析首先進行每個模塊的獨立仿真。模塊一:keyboard顯然,模塊的輸出信號key隨著鍵盤信號key_in而變化,模塊功能正常。這一部分主要是防止多個按鍵被按下。同時,單獨劃分一個模塊也可以使以后的擴展變得更加容易。模塊二:counter輸入1KHz的clk信號,再輸入開始記時的信號,計數器開始記時,記時正常。模塊三:display掃描顯示正常,同時可以進行正常的閃爍顯示功能。系統整體:整體仿真結果基本正確。5 設計中遇到的問題整個設計過程一共用了半個多月的時間,其中有一大半的時間都是用來完

31、成擴展功能的,而基本功能比較順利的就完成了。最開始的時候進行了邏輯上的模塊劃分,按照功能仔細的劃分了模塊,但是發現這樣對設計造成很大的麻煩,在程序編寫到一半的時候整個推翻重寫。第二次寫這個程序較為順利,但是由于前期規劃沒有做好,在操作和程序邏輯上有一些混亂,雖然勉強能夠運作但是效果不能讓人滿意。于是就有了第三次編寫。這一次進行了比較詳細的規劃,對程序也有了比較準確的把握,寫起來較為順利。尤其是對操作方法進行了重新調整,還詳細的畫出了程序的流程圖。按照流程圖和一定的程序結構,順利的完成了程序基本功能的編寫,這一次只用了幾個小時就完全完成了程序的編寫和調試,整個過程非常順利。在編寫基本功能的過程中

32、由于整體較為順利,兩次推翻重新進行所有工作,到了第三次全部完成,一共花了大概一周的時間。開始的時候不熟悉VHDL設計的設計思想,走了不少彎路。而且在開始的時候抱著寫寫看的想法,對程序的功能沒有進行仔細的分析,所以寫程序的時候思路不是非常清晰,而且經常出現混亂。后來,經過探索,我總結出了“操作狀態”的模式,細致的劃定了各個狀態和操作,每個狀態該進行什么樣的寄存器操作,什么樣的按鍵響應,按鍵或是寄存器變化之后會有什么樣的狀態變化。在畫出了相應的狀態流程圖之后發現編寫程序基本上就是照著圖“抄”程序,整個過程非常簡單。雖然在按鍵方面出了一些問題,但是很快經過改進之后就好了。之后就是對基本功能的擴展,擴展功能花了很大的力氣才完成,經過不斷次對程序的修

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論