Button/switch debouncing


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    xnihilo's Avatar
    xnihilo Guest

    Smile Button/switch debouncing

    Hi guys,

    I was wondering what delay I should use in debouncing a switch.
    I'm using 100ms debouncing, but that seems like overkill.

    Would 1ms be enough? Or would 10ms be enough.
    I guess it depends on the switch/button I use but I have no mean of knowing the bouncing of a given switch.

    Thanks for any answer.

    Regards

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Some interesting (although Long) reading.

    A Guide to Debouncing
    http://www.ganssle.com/debouncing.pdf

    Pretend it's a Playboy magazine, and just look at the pictures.
    <br>
    DT

  3. #3
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Smile

    Yes, I've just finished to read that. Interesting. 10ms should be enough.

    Is this piece of code right? (a lever microswitch connects ground and RA0 of a PIC16F684 (input with WPU enabled for this pin)

    start:

    while trigger = 1
    pause 10
    wend

    Thanks

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    NO. It'll take more than that.

    You need to test it again after the pause to make sure it's the same, and you should debounce both edges.
    Or a single pulse of any length, could re-trigger another keypress.
    <br>
    DT

  5. #5
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    Hi xnihilo,

    in the past I have used something like:

    Code:
    Start:
    
    If Trigger = Pressed then
    For CountByte = 0 to 9
    Pause 1
    If Trigger = NotPressed then Start
    Next CountByte
    ' Trigger is still pressed so do code here........
    Endif
    
    End
    This approach works well for me, checking the button 10 times at 1ms intervals, and will give you a starting point.

    Of course, there is always the PBP Button command...

    Hope this helps

    Rob

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    I think in the simplest form it's overkill...

    Look, you're not trying to ignore static from a localised lightning strike, just trying to detect that a Button has been pressed... so simply...
    Code:
    	If UserButton=0 then
    		Pause 10
    		Goto ButtonPressed
    		endif
    The IF statement checks if your Button has been pressed... The PAUSE simply ensures that you don't check for the press again within a set time period (which should be longer than your worst-case anticipated debounce time). Now, for user entry, I like to have a 100mS pause, this gives a nice 10cps repitition rate if you keep your finger on the button. If you only want ONE keypress, then simply check that it's been released first before doing anything else...
    Code:
    	While UserButton=0:Wend
    If you have a scenario where you have problematic static, then check for a Button Press once, pause a while, and check it's still pressed some time later. Static is momentary, so you will eradicate an awful lot of false triggering with something like...
    Code:
    	If UserButton=0 then
    		Pause 10
    		If UserButton=0 then Goto ButtonPressed
    		endif

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Rob View Post
    Hi xnihilo,

    Of course, there is always the PBP Button command...

    Rob
    I have noticed quite a few Picbasic Pro programs which use a button de-bounce routine instead of the button command. If it's not a silly question, when and where should I not use the Button command?

    Thanks,
    Pat. Pending

Similar Threads

  1. What debouncing technicques do you know?
    By Humbleworker in forum General
    Replies: 4
    Last Post: - 30th March 2007, 15:55
  2. Debouncing
    By Demon in forum Documentation
    Replies: 0
    Last Post: - 24th October 2005, 18:40

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts