---------------------------------------------------------------------------------- -- ---------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; use IEEE.NUMERIC_STD.ALL; entity debouncer is Port ( CLK : in STD_LOGIC; Kin : in STD_LOGIC; Kout : out STD_LOGIC); end debouncer; architecture Behavioral of debouncer is signal S1,S2,S3 : STD_LOGIC; signal CLK5 : STD_LOGIC; signal cntr : integer range 0 to 100000; begin process(CLK,cntr,CLK5) is begin -- debouncer clk if(rising_edge(CLK)) then if(cntr=100000) then cntr <= 0; CLK5 <= not(CLK5); else cntr <= cntr+1; end if; end if; end process; process(CLK5) is begin if(rising_edge(CLK5)) then S1 <= Kin; S2 <= S1; S3 <= S2; if(S1&S2&S3="000") then Kout <= '0'; elsif(S1&S2&S3="111") then Kout <= '1'; end if; end if; end process; end Behavioral;