------------------------------------------------------------------------------- -- File: input_synchronizer.vhd -- Taken from the traffic light controller from Feng Gui, Taozhi Peng -- Khern Yang Tkwang(Keypad Application Note) 1999_w -- and modified different valid requirements -- -- -- Project: DPF -- Created by: Benjamin Talbot from Feng Gui, Taozhi Peng -- Khern Yang Tkwang(Keypad Application Note) 1999_w -- Date: 2/1/02 -- -- Purpose: To synchronize a asynchronous input to the system clock -- -- Inputs: button_in <- PushButton -- syn_clock <- System clock to synchronize to -- syn_reset <- reset for synchronizer -- -- Outputs: syn_button_out -> synchronized button signal -- -- External Connections: -- keypad_controller.vhd ------------------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; entity button_input_synchronizer1 is -- latch short pulses on button presses , and synchronize to the clock -- clear automatically after one clock or on a reset port( button_in : in std_logic; -- negative logic input button syn_clock : in std_logic;-- system clock to synchronize reset : in std_logic; syn_button_out : out std_logic ); end button_input_synchronizer1; architecture behavioural of button_input_synchronizer1 is component clkdiv IS -- default to .75H -- 25.175 MHz/ (2**24) /2 generic (Divisor: positive :=33554432); -- clock division rate port(fast_clock : in STD_LOGIC; reset : in STD_LOGIC; slow_clock : buffer STD_LOGIC); end component clkdiv; SIGNAL SHIFT_PB : STD_LOGIC_VECTOR(3 DOWNTO 0); signal pb_debounced : std_logic; signal check_clock : std_logic; begin slow_clock : clkdiv generic map(Divisor => 50) port map( fast_clock => syn_clock, reset => reset, slow_clock => check_clock); -- Debounce clock should be approximately 10ms or 100Hz debounce : process(check_clock) BEGIN if rising_edge(check_clock) then -- Use a shift register to filter switch contact bounce SHIFT_PB(2 DOWNTO 0) <= SHIFT_PB(3 DOWNTO 1); SHIFT_PB(3) <= not button_in; IF SHIFT_PB(3 DOWNTO 0)="0000" THEN pb_debounced <= '0'; ELSE pb_debounced <= '1'; END IF; end if; END PROCESS; syn_button_out <= pb_debounced; end behavioural;