-------------------------------------------------------------------------------- -- Company: UNC-Charlotte, ECE Department -- Engineer: A.L. Hege -- -- Create Date: 13:26:30 12/01/05 -- Module Name: debounce - Behavioral -- Description: This circuit will accept and debounce a signal; -- the output stays high for 10.5 msec. minimum -- or as long as the user holds the switch; -- The circuit will not be ready to accept a new input -- for 10.5 msec. after switch is released. -- Dependencies: None -- Revision: 1.0 -- Revision 0.01 - File Created -- Additional Comments: ------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity debounce is Port ( CLK_50M : in std_logic; SW : in std_logic; sglPulse : out std_logic; Sig : out std_logic); end debounce; ------------------------------------------------------------------------------- -- ARCHITECTURE ------------------------------------------------------------------------------- architecture Behavioral of debounce is type stateType is (Rest, Kounting, wait4zero, singlePulse, deadTime); signal state, nextState : stateType := Rest; signal k : std_logic_vector (19 downto 0); constant kountTime : std_logic_vector (19 downto 0) := (others => '1'); ------------------------------------------------------------------------------- -- BEGIN ------------------------------------------------------------------------------- begin -- stateMemory process (CLK_50M) begin if CLK_50M'event and CLK_50M = '1' then state <= nextState; if state = Kounting or state = deadTime then k <= k + 1; end if; if state = wait4zero or state = Rest then k <= (others => '0'); end if; end if; end process; -- nextState_logic process (k, state, SW) begin case state is when Rest => if SW = '1' then nextState <= Kounting; else nextState <= Rest; end if; when Kounting => -- wait for 10.5 msec.(kountTime * 20 nsec.) before going to wait4zero state if k < kountTime then nextState <= Kounting; else nextState <= wait4zero; end if; when wait4zero => -- wait for the user to release the switch if SW = '1' then nextState <= wait4zero; else nextState <= singlePulse; end if; when singlePulse => nextState <= deadTime; when deadTime => -- wait for 10.5 msec. (kountTime * 20 nsec.) before going to the Rest state if k < kountTime then nextState <= deadTime; else nextState <= Rest; end if; when others => nextState <= Rest; end case; end process; -- Output variables sig <= '1' when (state = Kounting or state = wait4zero) else '0'; sglPulse <= '1' when state = singlePulse else '0'; end Behavioral;