library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity debouncer is port (clk : in std_logic; reset : in std_logic; enable : in std_logic; enable_debounced : out std_logic ); end entity debouncer; architecture Behavioral of debouncer is signal count1000000 : integer range 0 to 999999; signal clk_1MHz : std_logic; signal enable_sampled : std_logic:='0'; --ENABLE push button pressed begin div_1MHz : process (clk, reset) is --Counts 1M clock ticks begin if reset = '1' then clk_1MHz <= '0'; count1000000 <= 0; elsif rising_edge(clk) then if count1000000 = 999999 then count1000000 <= 0; clk_1MHz <= '1'; else count1000000 <= count1000000 + 1; clk_1MHz <= '0'; end if; end if; end process div_1MHz; debounce_pb : process (clk) is begin if rising_edge(clk) then if clk_1MHz = '1' then if enable = enable_sampled then enable_debounced <= enable; end if; enable_sampled <= enable; end if; end if; end process debounce_pb; end Behavioral;