計數(shù)器簡介:
計數(shù)器是數(shù)字系統(tǒng)中用得較多的基本邏輯器件。它不僅能記錄輸入時鐘脈沖的個數(shù),還可以實現(xiàn)分頻、定時、產(chǎn)生節(jié)拍脈沖和脈沖序列等。例如,計算機中的時序發(fā)生器、分頻器、指令計數(shù)器等都要使用計數(shù)器。 計數(shù)器的種類很多。按時鐘脈沖輸入方式的不同,可分為同步計數(shù)器和異步計數(shù)器;按進位體制的不同,可分為二進制計數(shù)器和非二進制計數(shù)器;按計數(shù)過程中數(shù)字增減趨勢的不同,可分為加計數(shù)器、減計數(shù)器和可逆計數(shù)器。
以下是VHDL代碼和仿真:
- library ieee;
- use ieee.std_logic_1164.all;
- use ieee.std_logic_arith.all;
- use ieee.std_logic_unsigned.all;
- --------------------------------------------------------------------
- entity exp3 is
- port( clk,ret,en : in std_logic; --定義時鐘、異步復(fù)位、同步使能信號
- cq : out std_logic_vector(3 downto 0); --計數(shù)結(jié)果
- cout : out std_logic --進位信號
- );
- end exp3;
- --------------------------------------------------------------------
- architecture behave of exp3 is
- begin
- process(clk,ret,en)
- variable cqi : std_logic_vector(3 downto 0);
- begin
- if ret='0' then cqi:=(others =>'0');-- 計數(shù)器異步復(fù)位
- elsif clk'event and clk='1' then--檢測時鐘上升沿
- if en='1' then--檢測是否允許計數(shù)(同步使能)
- if cqi<15 then cqi:=cqi+1;
- else cqi:=(others =>'0');
- end if;
- end if;
- end if;
- if cqi>9 then cout<='1';--輸出進位信號
- else cout<='0';
- end if;
- cq<=cqi;--計數(shù)值向端口輸出
- end process;
- end behave;
復(fù)制代碼
代碼下載:
16位計數(shù)器.7z
(188.25 KB, 下載次數(shù): 10)
2024-6-27 15:26 上傳
點擊文件名下載附件
|