summaryrefslogtreecommitdiffstats
path: root/fpga/hp_lcd_driver/debounce.vhdl
diff options
context:
space:
mode:
Diffstat (limited to 'fpga/hp_lcd_driver/debounce.vhdl')
-rw-r--r--fpga/hp_lcd_driver/debounce.vhdl32
1 files changed, 32 insertions, 0 deletions
diff --git a/fpga/hp_lcd_driver/debounce.vhdl b/fpga/hp_lcd_driver/debounce.vhdl
new file mode 100644
index 0000000..286367d
--- /dev/null
+++ b/fpga/hp_lcd_driver/debounce.vhdl
@@ -0,0 +1,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;