VHDL第3次作業(yè)題目數(shù)字頻率計_第1頁
VHDL第3次作業(yè)題目數(shù)字頻率計_第2頁
VHDL第3次作業(yè)題目數(shù)字頻率計_第3頁
VHDL第3次作業(yè)題目數(shù)字頻率計_第4頁
VHDL第3次作業(yè)題目數(shù)字頻率計_第5頁
已閱讀5頁,還剩10頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、西安電子科技大學VHDL數(shù)字系統(tǒng)設計與測試作業(yè) 題 目 數(shù)字頻率計 學 院 電子工程學院 專 業(yè) 電子與通信工程 學 號 學生姓名 授課教師 鐘樺 撰寫日期: 2015 年 6 月 9 日 數(shù)字頻率計題目要求:1.用VHDL完成12位十進制數(shù)字頻率計的設計及仿真。2.頻率測量范圍:1Hz10KHz,分成兩個頻段,即1999Hz,1KHz10KHz,用三位數(shù)碼管顯示測量頻率,用LED顯示表示單位,如亮綠燈表示Hz,亮紅燈表示KHz。3.具有自動校驗和測量兩種功能,即能用標準時鐘校驗、測量精度。4.具有超量程報警功能,在超出目前量程檔的測量范圍時,發(fā)出燈光和音響信號。問題分析:測量頻率的基本原理是

2、在單位時間內(nèi)檢測信號的脈沖個數(shù),計數(shù)器對CP1信號進行計數(shù),在1秒定時結(jié)束后,將計數(shù)器結(jié)果送鎖存器鎖存,同時將計數(shù)器清零,為下一次采樣測量做好準備。根據(jù)題目要求,將系統(tǒng)分為以下幾個模塊:1、測量/校驗選擇模塊(selett)2、測頻控制信號發(fā)生器(二分頻)(fenpin)3、與電路模塊(andd)4、計數(shù)器模塊(counter)5、送存選擇、報警模塊(tostore)6、鎖存模塊(lockstore)7、掃描顯示模塊(scann)通過以上分析,給出各模塊程序代碼,并對各個模塊進行分別敘述說明。1、 測量/校驗選擇模塊(selett)輸入信號:選擇信號selet被測信號meas測試信號test輸

3、出信號:cp1當selet=0時,為測量狀態(tài),cp1=meas;當selet=1時,為校驗狀態(tài),cp1=test。校驗與測量共用一個電路,只是被測信號cp1不同而已。-測量/校驗選擇library ieee;use ieee.std_logic_1164.all;entity selett is port(selet,test,meas:in std_logic; cp1:out std_logic);end selett;architecture behv of selett is -type statetype is(meas,test); -signal present_state,ne

4、xt_state:statetype:=meas; begin process(selet) begin case selet is when '1'=>cp1<=test; when '0'=>cp1<=meas; when others=>cp1<=null; end case; end process;end behv;仿真驗證其正確性從上圖可以看出,當selet=0時,cp1輸出信號為meas,當selet=1時,輸出信號為test,符合設計要求。2、測頻控制信號發(fā)生器(二分頻)(fenpin)輸入信號:1HZ時鐘信號

5、(clk)輸出信號:1秒定時信號(周期為2秒)(clk_out)此模塊實際上就是一個二分頻的計數(shù)器,代碼如下:-分頻library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity fenpin is port(clk:in std_logic; clk1:out std_logic);end fenpin;architecture behav of fenpin isbegin process(clk) variable count:integer:=1; begin if(clk'even

6、t and clk='1') then if count=1 then count:=0; clk1<='1' else count:=count+1; clk1<='0' end if; end if; end process;end behav;仿真驗證其正確性由仿真結(jié)果可以看出,二分頻電路正確,符合設計要求。3、與電路模塊(andd)輸入信號:二分頻時鐘(clk2), 測量/校驗選擇模塊輸出信號(cp2)輸出信號:與信號(cp)代碼如下:-與電路library ieee;use ieee.std_logic_1164.all;e

7、ntity andd is port(clk2,cp2:in std_logic; cp:out std_logic);end andd;architecture behv of andd isbegin cp<=clk2 and cp2;end behv;仿真驗證其正確性由仿真結(jié)果可以看出,與電路正確,符合設計要求。4、計數(shù)器模塊(counter)由題目要求,計數(shù)的范圍應該是00009999,因此,計數(shù)器模塊的內(nèi)部應由四個十進制計數(shù)器q4,q3,q2,q1組成。另外,由于系統(tǒng)設置了溢出信號c。輸入信號:計數(shù)時鐘(cp)。 片選信號(rd)輸出信號:計數(shù)輸出信號千位:q4,百位:q3,十

8、位:q2,個位:q1溢出信號:c代碼如下-計數(shù)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity counter is port(rd,cp:in std_logic; c:out std_logic; q4,q3,q2,q1:out std_logic_vector(3 downto 0);end counter;architecture behv of counter is signal c1,c2,c3,c4:std_logic; begin cnt1:process(rd,cp)

9、 variable cn1:std_logic_vector(3 downto 0); begin if rd='1' then if cp'event and cp='1' then if cn1="1001" then cn1:="0000" c1<='1' else cn1:=cn1+1; c1<='0' end if; end if; end if; q1<=cn1; end process cnt1;cnt2:process(c1,rd) variable

10、 cn2:std_logic_vector(3 downto 0);begin if rd='1' then if c1'event and c1='1' then if cn2="1001" then cn2:="0000" c2<='1' else cn2:=cn2+1; c2<='0' end if; end if; - else -cn2:="0000" -c2<='0' end if; q2<=cn2;end pr

11、ocess cnt2;cnt3:process(c2,rd) variable cn3:std_logic_vector(3 downto 0);begin if rd='1' then if c2'event and c2='1' then if cn3="1001" then cn3:="0000" c3<='1' else cn3:=cn3+1; c3<='0' end if; end if; end if; q3<=cn3;end process cnt3;

12、cnt4:process(c3,rd) variable cn4:std_logic_vector(3 downto 0);begin if rd='1' then if c3'event and c3='1' then if cn4="1001" then cn4:="0000" c<='1' else cn4:=cn4+1; c<='0' end if; end if; end if; q4<=cn4;end process cnt4;end behv;仿真驗證

13、其正確性從仿真結(jié)果可以看出,rd=1時計數(shù),rd=0時不計數(shù)。設定rd的周期為1us,cp的周期為10ns,則在rd=1的時間內(nèi)應該計數(shù)50次,從圖中可以看出仿真結(jié)果符合預期。5、送存選擇、報警模塊(tostore)輸入信號:量程檔控制開關(guān)(k)四位十進制信號(qb4,qb3,qb2,qb1)溢出信號輸入(cc)輸出信號:三位十進制信號(dd3,dd2,dd1)報警信號(alert)當k=0時,選擇1999Hz量程,輸出信號為qb3,qb2,qb1,如果qb4>0,報警.當k=1時,選擇1K10KHz量程,輸出信號為qb4,qb3,qb2,如果c>0,報警。代碼如下:-存送選擇、報

14、警電路library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity tostore is port(qb4,qb3,qb2,qb1:in std_logic_vector(3 downto 0); cc,k:in std_logic; dd3,dd2,dd1:out std_logic_vector(3 downto 0); alert:out std_logic);end tostore;architecture behv of tostore is begin process(qb4,qb3,

15、qb2,qb1,cc,k) begin if k='0' then dd3<=qb3; dd2<=qb2; dd1<=qb1; if qb4>"0000" or cc>'0' then alert<='1' else alert<='0' end if; elsif k='1' then dd3<=qb4; dd2<=qb3; dd1<=qb2; if cc>'0' then alert<='1

16、9; else alert<='0' end if; else alert<='0' end if; end process;end behv; 仿真驗證其正確性仿真中設定qb4=4,qb2=2,qb3=3,qb1=1,從仿真結(jié)果圖中可以看出,當k=0時, dd3=qb3, dd2=qb2, dd1=qb1,應為qb4>0,所以報警信號alert=1;當k=1時,dd3=qb4,dd2=qb3,dd1=qb2,當cc=0時,報警信號alert=0,當cc>0時,報警,alert=1。因此,仿真結(jié)果符合要求。6、鎖存模塊(lockstore

17、)輸入端口:片選信號(ld)量程選擇開關(guān)(k)輸入數(shù)據(jù)(d3,d2,d1)輸出端口:輸出數(shù)據(jù)(data3,data2,data1) 綠燈(led_green)-表示單位hz 紅燈(led_red)-表示單位Khz代碼如下-鎖存電路library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity lockstore is port(ld,k:in std_logic; d3,d2,d1:in std_logic_vector(3 downto 0); data3,data2,data1:out std_

18、logic_vector(3 downto 0); led_green,led_red:out std_logic);end lockstore;architecture behv of lockstore is begin process(d3,d2,d1,ld,k) begin if(ld='1') then data3<=d3; data2<=d2; data1<=d1; if k='0' then led_green<='1' -led_green->hz led_red<='0' -l

19、ed_red-Khz else led_green<='0' -led_green->hz led_red<='1' -led_red-Khz end if; end if; end process;end behv;仿真驗證其正確性片選信號ld=1時,data3=d3,data2=d2,data1=d1,當k=0時綠燈亮,選擇的單位為hz;當k=1時,紅燈亮,選擇的單位為Khz。所以,由上圖可以,仿真結(jié)果符合要求。7、掃描顯示模塊(scann)此模塊要完成三件事情:(1) 通過掃描時鐘產(chǎn)生數(shù)碼管掃描信號。(2) 顯示小數(shù)點(3) 七段譯碼由于

20、顯示的數(shù)碼管要加上小數(shù)點,因此,要在譯碼產(chǎn)生的7位數(shù)之后加上一位point,point的值由k和掃描信號有關(guān),當k=1,掃描信號=110時,point=1,其他情況都為0。輸入端口:掃描時鐘(clkk) 單位選擇開關(guān)(k) 輸入數(shù)據(jù)(d_3,d_2,d_1)輸出端口:掃描信號(selout) 數(shù)碼管(led) 小數(shù)點(point)代碼如下:-掃描顯示電路library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity scann is port(clkk,k:in std_logic; d_3,d_2

21、,d_1:in std_logic_vector(3 downto 0); -qq:out std_logic_vector(3 downto 0); selout:out std_logic_vector(2 downto 0); led:out std_logic_vector(6 downto 0); point:out std_logic); end scann;architecture behv of scann is signal qq:std_logic_vector(3 downto 0); signal sel:std_logic_vector(1 downto 0); si

22、gnal selout2:std_logic_vector(2 downto 0); -signal point1:std_logic;begin p1:process(clkk,d_3,d_2,d_1) variable scannum:std_logic_vector(1 downto 0); variable qq1:std_logic_vector(3 downto 0); begin if clkk'event and clkk='1' then if scannum="10" then scannum:="00" el

23、se scannum:=scannum+1; end if; end if; case scannum is when "00"=>qq1:=d_1; when "01"=>qq1:=d_2; when "10"=>qq1:=d_3; when others=>qq1:=null; end case; sel<=scannum; qq<=qq1; end process p1; p2:process(sel) variable selout1:std_logic_vector(2 downto 0)

24、; -variable scannum:std_logic_vector(1 downto 0); begin -if clkk'event and clkk='1' then -if scannum="10" then - scannum:="00" - else - scannum:=scannum+1; - end if; - end if; case sel is when "00"=>selout1:="001" when "01"=>selout1

25、:="010" when "10"=>selout1:="100" when others=>selout1:=null; end case; selout2<=selout1; end process p2; selout<=selout2; p3:process(selout2,k) begin if(k='1' and selout2="100") then point<='1' else point<='0' end if;

26、 end process p3; p4:process(qq) begin case qq is when "0000"=>led<="0111111"&point; when "0001"=>led<="0000110"&point; when "0010"=>led<="1011011"&point; when "0011"=>led<="1001111"&am

27、p;point; when "0100"=>led<="1100110"&point; when "0101"=>led<="1101101"&point; when "0110"=>led<="1111101"&point; when "0111"=>led<="0000111"&point; when "1000"=>led&l

28、t;="1111111"&point; when "1001"=>led<="1101111"&point; when others=>led<="0000000"&point; end case; end process p4;end behv;仿真驗證其正確性仿真設定輸入d_1=4,d_2=5,d_3=6,從仿真結(jié)果可以看出掃描和譯碼正確;從圖中可以看出只有當selout=100,k=1同時成立時,小數(shù)點才顯示。因此,仿真結(jié)果符合要求。8、頂層模塊頂層模塊代碼-t

29、op circuit descriptionlibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity freqcounter is port(clk,clkk,meas,test,selet,k:in std_logic; led:out std_logic_vector(7 downto 0); selout:out std_logic_vector(2 downto 0); alert,led_green,led_red,point:out std_logic); -clk1,cp1:ou

30、t std_logic; -dd3,dd2,dd1:out std_logic_vector(3 downto 0); -data3,data2,data1:out std_logic_vector(3 downto 0); -q4,q3,q2,q1:out std_logic_vector(3 downto 0); end freqcounter;architecture behv of freqcounter is signal s1,s2,s3,s4:std_logic; signal sq1,sq2,sq3,sq4:std_logic_vector(3 downto 0); signa

31、l sd1,sd2,sd3:std_logic_vector(3 downto 0); signal sdd1,sdd2,sdd3:std_logic_vector(3 downto 0); signal sled:std_logic_vector(3 downto 0);component fenpin is port(clk:in std_logic; clk1:out std_logic);end component fenpin;component selett is port(selet,test,meas:in std_logic; cp1:out std_logic); end

32、component selett; component andd is port(clk2,cp2:in std_logic; cp:out std_logic); end component andd; component counter is port(rd,cp:in std_logic; c:out std_logic; q4,q3,q2,q1:out std_logic_vector(3 downto 0); end component counter; component tostore is port(qb4,qb3,qb2,qb1:in std_logic_vector(3 d

33、ownto 0); cc,k:in std_logic; dd3,dd2,dd1:out std_logic_vector(3 downto 0); alert:out std_logic); end component tostore; component lockstore is port(ld,k:in std_logic; d3,d2,d1:in std_logic_vector(3 downto 0); data3,data2,data1:out std_logic_vector(3 downto 0); led_green,led_red:out std_logic); end c

34、omponent lockstore; component scann is port(clkk,k:in std_logic; d_3,d_2,d_1:in std_logic_vector(3 downto 0); selout: out std_logic_vector(2 downto 0); led:out std_logic_vector(7 downto 0); end component scann; begin u1:fenpin port map(clk=>clk,clk1=>s1); u2:selett port map(selet=>selet,test=>test,meas=>meas,cp1=>s2); u3:andd port map(clk2=>s1,cp2=>s2,cp=>s3); u4:counter port map(rd=>s1,cp=>s3,c=>s4,q4=>sq4,q3=>sq3,q2=>sq2,q1=>sq1); u5:tostore port map(qb4=>sq4,qb3=>sq3,qb2=>sq2,qb1=>sq1,cc=>s4,k=>k,dd3=>sd3,dd2=&g

溫馨提示

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

評論

0/150

提交評論