---------------------------------------------------------------------------------- -- Company: FMAC -- Engineer: Craig and Naveen -- -- Create Date: 17:17:28 12/23/2008 -- Design Name: Brainless uProcessor -- Module Name: sw_Buffer - Behavioral -- Description: -- This buffer is designed to debounce the Spartan 3E buttons. -- Without a buffer the buttons will "bounce" when pressed. This will send -- 2 maybe 3 high signals each time the button is pressed. Using a counter -- that is triggered off the Spartan 3E's 50MHz oscillator, each time the -- button is pressed a delay of 0.23 seconds is introduced to allow the -- signal to stop "bouncing". -- ---------------------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity debounce is port ( clk : in std_logic; switch_input : in std_logic; debounced_output : out std_logic := '0' ); end debounce ; architecture behavioral of debounce is type states is (noPushButton, ButtonPushed); signal state : states; signal stop_counter : std_logic := '0'; signal run_counter :std_logic; signal counter :std_logic_vector(23 downto 0); begin state_machine: process (clk) begin if clk'event and clk='1' then case state is when noPushButton => if (switch_input = '1' and stop_counter = '0') then state <= ButtonPushed; debounced_output <= '0'; run_counter <= '1'; else state <= noPushButton; debounced_output <= '0'; run_counter <= '0'; end if; when ButtonPushed => if stop_counter = '1' then state <= noPushButton; debounced_output <= '1'; run_counter <= '0'; else state <= ButtonPushed; debounced_output <= '0'; run_counter <= '1'; end if; when others => debounced_output <= '0'; run_counter <= '0'; state <= noPushButton; end case; end if; end process state_machine; -- When the state machine goes 'high', it starts the counter (run_counter = 1). -- The counter will count off from 0 to 11,500,000. When it is -- done it will give stop_counter a '1', which will output 1 and change -- state to 'low'. count_machine: process(clk, run_counter) begin if run_counter = '1' then if clk'event and clk = '1' then if counter = x"AF79E0" then--x"AF79E0" then -- this hex value is 11,500,000 stop_counter <= '1'; -- each cycle is 20 ns else -- total time of counter is stop_counter <= '0'; -- 11,500,000 * 20 ns = 0.23 sec end if; counter <= counter + 1; end if; else counter <= x"000000"; end if; end process count_machine; end behavioral;