这是0-5 counter,Q用来表示有没有数到5
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity count_0_to_5 is
port (clk : in std_logic;
count : buffer std_logic_vector(2 downto 0);
reset_n :in std_logic;
Q: out std_logic
);
end count_0_to_5;
architecture Behavior of count_0_to_5 is
begin
process(clk,reset_n)
begin
if(rising_edge(clk)) then
if (count="101")then
count<=(others=>'0');
else count<=count + '1';
end if;
end if;
if (count="101") then
Q<='1';
else Q<='0';
end if;
if(reset_n='1') then
count<=(others=>'0');
end if;
end process;