LIBRARY IEEE; USE IEEE.std_logic_1164.ALL; USE IEEE.STD_LOGIC_ARITH.all; USE IEEE.STD_LOGIC_UNSIGNED.all; entity counter is GENERIC (N : Integer := 10; CLIP : Integer := 1); port ( clk : in std_logic; clk_en : in std_logic; sclr : in std_logic; aclr_n : in std_logic; Q : out std_logic_vector(N-1 downto 0) ); end counter; -------------------------------------------------------------------------------------------------------- -- ARCHITECTURE -------------------------------------------------------------------------------------------------------- architecture a of counter is constant all1 : std_logic_vector(Q'range) := (others => '1'); signal Q_int : std_logic_vector(Q'range); signal ce : std_logic; begin ce <= clk_en when CLIP=0 else clk_en when q_int /= all1 else '0'; process(clk, aclr_n) begin if aclr_n='0' then q_int <= (others => '0'); elsif clk'event and clk='1' then if sclr='1' then q_int <= (others => '0'); elsif ce='1' then q_int <= q_int + 1; end if; end if; end process; q <= q_int; end;