uas_arduino

Debouncing - Working

May 18th, 2014
269
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     process(clk, rst)
  2.         variable counter : unsigned(31 downto 0) := (others => '0');
  3.         variable flipflops : std_logic_vector(1 downto 0) := (others => '0');
  4.     begin
  5.         if(rst = '1') then
  6.             counter := (others => '0');
  7.             flipflops := (others => '0');
  8.             leds_counter <= (others => '0');
  9.         elsif(rising_edge(clk)) then
  10.             flipflops(1) := flipflops(0);
  11.             flipflops(0) := button;
  12.            
  13.             if(flipflops(1) = '1' and flipflops(0) = '1') then
  14.                 counter := to_unsigned(100_000_000 / 20, counter'length);
  15.             elsif(counter > 0) then
  16.                 counter := counter - 1;
  17.             else
  18.                 if(button = '1') then
  19.                     leds_counter <= leds_counter + 1;
  20.                 end if;
  21.             end if;
  22.         end if;
  23.     end process;
RAW Paste Data