blob: 286367d410ebe96291da75999a7d0b19b0615e81 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity debounce is
generic (stages : natural := 1);
port (clk : in std_logic;
i : in std_logic;
o : out std_logic);
end debounce;
architecture Behavioral of debounce is
signal flipflops : std_logic_vector(stages-1 downto 0) := (others => '0');
constant zero : std_logic_vector(stages-1 downto 0) := (others => '0');
constant one : std_logic_vector(stages-1 downto 0) := (others => '1');
signal output : std_logic := '0';
begin
o <= output;
process (clk, flipflops, i)
begin
if rising_edge(clk) then
flipflops <= flipflops(flipflops'high-1 downto 0) & i;
if flipflops = one and i = '1' then
output <= '1';
elsif flipflops = zero and i = '0' then
output <= '0';
end if;
end if;
end process;
end architecture;
|