Skip to content

Instantly share code, notes, and snippets.

@fbrosser
Created November 23, 2011 17:50
Show Gist options
  • Select an option

  • Save fbrosser/1389355 to your computer and use it in GitHub Desktop.

Select an option

Save fbrosser/1389355 to your computer and use it in GitHub Desktop.
Debounce State Machine
----------------------------------------------------------------------------------
-- Fredrik Brosser
-- Push-Button debouncer
-- EDA234, Group 2
--
-- FILE
-- TempModule.vhd
-- Last Updated: 2011-11-22
--
-- VERSION
-- Hardware ("production") v1.0
--
-- HARDWARE
-- Target Device: XC9572XL
-- I/O Pins Used:
-- Macrocells Used:
-- Product Terms Used:
--
-- DESCRIPTION
-- Debouncing a single input signal
--
----------------------------------------------------------------------------------
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
Entity debounce is
port( clk : in std_logic;
rstInt : in std_logic;
btnIn : in std_logic;
btnOut : buffer std_logic
);
end debounce;
Architecture debounce_bhv of debounce is
type stateType is (s0, s1, s2, s3);
signal state : stateType;
signal nextState : stateType;
begin
SyncP : process(clk, rstInt)
begin
if(rstInt = '1') then
state <= s0;
elsif(clk'Event and clk = '1') then
state <= nextState;
end if;
end process;
CombP : process(state, btnIn)
begin
nextState <= state;
case state is
when s0 =>
if(btnIn = btnOut) then
nextState <= s1;
end if;
when s1 =>
if(btnIn = btnOut) then
nextState <= s2;
end if;
when s2 =>
if(btnIn = btnOut) then
nextState <= s3;
end if;
when s3 =>
nextState <= s0;
if(btnIn = btnOut) then
btnOut <= not(btnIn);
end if;
end case;
end process;
end debounce_bhv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment