Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Tips for handling switch bounce?

Reply
Thread Tools

Tips for handling switch bounce?

 
 
Hillam Hillam is offline
Junior Member
Join Date: May 2012
Posts: 1
 
      05-08-2012
Hi everyone,

I was just wondering if anyone had any suggestions on how to accommodate for bounce on push button switches on an FPGA board. The boards are quite old (10+ years) and apparently the switches have reached the "pretty dodgy" stage (to quote the lecturer). I'm trying to implement some logic I came up with for a state machine that deals with a combination lock; pressing a series of buttons in the correct sequence unlocks a door, making a mistake sends it to an "alarm" state which remains in place until the reset switch is pushed. Problem is that the switches are so "pretty dodgy" that pushing the first button sends it straight to the alarm state (either that or my code implementation sucks; not dismissing that as an option either). I've tried using wait statements so far, but no success. Any ideas?
 
Reply With Quote
 
 
 
 
jeppe jeppe is offline
Senior Member
Join Date: Mar 2008
Location: Denmark
Posts: 346
 
      05-09-2012
Hi

Instead of depending on a single value from a "poor switch" must you collect several values. Could be done in a shiftregister with say 8 bits.

Shreg <= Shreg( 6 downto 0) & Switch;

00000000 => Steady 0
01101011 => Push down with bounces
01111111 => Accepted "rising edge"
11111111 => Steady 1
10110110 => Release with bounces
10000000 => Accepted "falling edge"

The best frequency for the detection could be around 1 kHz and the length of the shiftregister could be longer/shorter as well.

Your welcome
 

Last edited by jeppe; 05-09-2012 at 05:01 AM.. Reason: Added example
Reply With Quote
 
 
 
 
nitram nitram is offline
Junior Member
Join Date: May 2012
Posts: 1
 
      05-17-2012
Hi,

I'm using simple module which take care about metastability and debounce.

HTML Code:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;

ENTITY debounce IS
  GENERIC (
    width : NATURAL;
    active_level : STD_LOGIC
  );
  PORT (
    clk : IN STD_LOGIC;
    async_in : IN STD_LOGIC;
    sync_out : OUT STD_LOGIC
  );
END;

ARCHITECTURE rtl OF debounce IS
  SIGNAL dff1_q : STD_LOGIC := not active_level;
  SIGNAL dff2_q : STD_LOGIC := not active_level;
  SIGNAL cnt : UNSIGNED(width - 1 DOWNTO 0) := (OTHERS => '1');
BEGIN
  -- metastability remover
  PROCESS (clk)
  BEGIN
    IF rising_edge(clk) THEN
      dff1_q <= async_in;  -- first DFF
      dff2_q <= dff1_q;    -- second DFF
    END IF;
  END PROCESS;

  -- debouncer
  PROCESS (clk, dff2_q)
  BEGIN
    -- asynchronous reset
    IF dff2_q = active_level THEN
      cnt <= (OTHERS => '0');
      sync_out <= active_level;
    -- debounce counter
    ELSIF rising_edge(clk) THEN
      IF cnt = (2**width - 1) THEN
        sync_out <= NOT active_level;
      ELSE
        cnt <= cnt + 1;
      END IF;
    END IF;
  END PROCESS;
END;
Martin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.Net Tips, C# Tips : Get IP Address from host name with C# Examplesand VB.Net Examples jayeshsorathia@gmail.com ASP .Net 0 07-31-2012 07:25 AM
.Net Tips, C# Tips : Create a well formed URI using UriBuilder classwith C# Examples and VB.Net Examples jayeshsorathia@gmail.com ASP .Net 1 07-31-2012 01:03 AM
.Net Tips, C# Tips : Get list of all files of directory or folderusing LINQ using .Net Framework 4 with C# Examples and VB.Net Examples jayeshsorathia@gmail.com ASP .Net 0 07-27-2012 07:13 AM
balloon tips + aston or how to connect a bluetooth headset without ballon tips diesel Computer Support 0 05-31-2006 01:00 PM
Mozilla Tips reaches 100 Tips and 90,000 Visits Cornelius Fichtner Firefox 0 12-18-2003 11:50 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57