基於vhdl語言的8位數字頻率計的設計?手機使用者858310264912019-06-21 10:15:18

實驗目的: 設計一個4位十進位制頻率計,學習複雜數字系統的設計方法。實驗原理:根據頻率的定義和頻率測量的基本原理,測定訊號的頻率必須有一個脈寬為1秒的脈衝計數允許訊號,1秒計數結束後,計數值(即所測訊號頻率)鎖入鎖存器,併為下一次測頻作準備,即將計數器清零。試驗內容:1、根據頻率計的工作原理,將電路劃分成控制器、計數器、鎖存器和LED顯示幾個模組, 控制器――產生1秒脈寬的計數允許訊號、鎖存訊號和計數器清零訊號計數器――對輸入訊號的脈衝數進行累計鎖存器――鎖存測得的頻率值LED顯示――將頻率值顯示在數碼管上頂層檔案框圖如下: 2、用元件例化語句寫出頻率計的頂層檔案。提示:十進位制計數器輸出的應是4位十進位制數的BCD碼,因此輸出一共是4×4bit。實驗結果:各模組電路的VHDL描述:10進位制計數器library ieee;use ieee。std_logic_1164。all;use ieee。std_logic_unsigned。all;entity cnt10 is port (rst,fx,ena:in std_logic; cout: out std_logic; outy :out std_logic_vector(3 downto 0));end cnt10;architecture behv of cnt10 isbegin process (rst,ena,fx) variable cqi :std_logic_vector(3 downto 0);begin if rst=‘1’ then cqi :=(others =>‘0’); elsif fx‘event and fx=’1‘ then if ena =’1‘ then if cqi < 9 then cqi:=cqi+1;cout<=’0‘; elsif cqi=9 then cqi :=(others =>’0‘); cout<=’1‘; end if; elsif ena=’0‘ then cqi:=(others =>’0‘); end if;end if; outy <=cqi;end process;end behv;4位10進計數器library ieee;use ieee。std_logic_1164。all;entity cnt10_4 isport(fx,rst,ena:in std_logic; d:out std_logic_vector(15 downto 0));end entity;architecture one of cnt10_4 iscomponent cnt10 port (rst,fx,ena:in std_logic; cout: out std_logic; outy :out std_logic_vector(3 downto 0));end component;signal e:std_logic_vector(3 downto 0);beginu1:cnt10 port map(fx=>fx,rst=>rst,ena=>ena,cout=>e(0),outy=>d(3 downto 0));u2:cnt10 port map(fx=>e(0),rst=>rst,ena=>ena,cout=>e(1),outy=>d(7 downto 4));u3:cnt10 port map(fx=>e(1),rst=>rst,ena=>ena,cout=>e(2),outy=>d(11 downto 8));u4:cnt10 port map(fx=>e(2),rst=>rst,ena=>ena,cout=>e(3),outy=>d(15 downto 12));end architecture one;16位鎖存器library ieee;use ieee。std_logic_1164。all;use ieee。std_logic_unsigned。all;entity latch4 isport(d:in std_logic_vector(15 downto 0);ena,clk:in std_logic;q:out std_logic_vector(15 downto 0));end latch4;architecture one of latch4 isbeginprocess(clk,ena,d)variable cqi:std_logic_vector(15 downto 0);beginif ena=’0‘ then cqi:=cqi;elsif clk’event and clk=‘1’ then cqi:=d;end if;q<=cqi;end process;end one;LED控制模組library ieee;use ieee。std_logic_1164。all;use ieee。std_logic_unsigned。all;entity led_controller isport(d:in std_logic_vector(3 downto 0);a:out std_logic_vector(6 downto 0));end led_controller;architecture one of led_controller isbegin process(d)begincase d iswhen “0000”=> a<=“0111111”;when “0001”=> a<=“0000110”;when “0010”=> a<=“1011011”;when “0011”=> a<=“1001111”;when “0100”=> a<=“1100110”;when “0101”=> a<=“1101101”;when “0110”=> a<=“1111101”;when “0111”=> a<=“0000111”;when “1000”=> a<=“1111111”;when “1001”=> a<=“1101111”;when “1010”=> a<=“1110111”;when “1011”=> a<=“1111100”;when “1100”=> a<=“0111001”;when “1101”=> a<=“1011110”;when “1110”=> a<=“1111001”;when “1111”=> a<=“1110001”;when others=> null;end case;end process;end;控制模組library ieee;use ieee。std_logic_1164。all;use ieee。std_logic_unsigned。all;entity control is port (clk:in std_logic; rst,ena: out std_logic);end control;architecture behv of control isbegin process (clk) variable cqi :std_logic_vector(2 downto 0);begin if clk‘event and clk=’1‘ then if cqi <1 then cqi:=cqi+1;ena<=’1‘;rst<=’0‘; elsif cqi=1 then cqi :=(others =>’0‘); ena<=’0‘;rst<=’1‘; end if; end if; end process;end behv;總體例化語句:library ieee;use ieee。std_logic_1164。all;use ieee。std_logic_unsigned。all;entity cntf isport(rset,clk:in std_logic; fx:in std_logic; ledout:out std_logic_vector(27 downto 0));end entity;architecture one of cntf iscomponent control port (clk:in std_logic; rst,ena: out std_logic);end component;component cnt10_4port(fx,rst,ena:in std_logic; d:out std_logic_vector(15 downto 0));end component;component latch4port(d:in std_logic_vector(15 downto 0);ena,clk:in std_logic;q:out std_logic_vector(15 downto 0));end component;component led_controllerport(d:in std_logic_vector(3 downto 0);a:out std_logic_vector(6 downto 0));end component;signal x,z:std_logic;signal g,h:std_logic_vector(15 downto 0);signal leds:std_logic_vector(27 downto 0);beginu1: control port map(clk=>clk,ena=>x,rst=>z);u2: cnt10_4 port map(fx=>fx,rst=>z,ena=>x,d=>g);u3: latch4 port map(clk=>clk,ena=>x,d=>g,q=>h);u4: led_controller port map(d(3 downto 0)=>h(3 downto 0),a(6 downto 0)=>leds(6 downto 0));u5: led_controller port map(d(3 downto 0)=>h(7 downto 4),a(6 downto 0)=>leds(13 downto 7));u6: led_controller port map(d(3 downto 0)=>h(11 downto 8),a(6 downto 0)=>leds(20 downto 14));u7: led_controller port map(d(3 downto 0)=>h(15 downto 12),a(6 downto 0)=>leds(27 downto 21));ledout<=leds;end; 這是我當時做的一個4位頻率計,CLK為一個1HZ的時鐘訊號。可用數碼管顯示出頻率數的。只要你能讀懂原理,是很容易改成八位的。 如果要圖文混合設計,即各模組設計好後,頂層檔案用原理圖設計即可。給你參考一下吧。