Switch debouncing

Discussion in 'Embedded Systems and Microcontrollers' started by helloeveryone, Nov 27, 2013.

  1. helloeveryone

    Thread Starter Active Member

    Apr 8, 2011
    51
    0
    Hello,

    how much of a role does the oscillator frequency play in switch bouncing and debouncing? For example if I used a 16MHz oscillator and then switched to a 1MHz oscillator would the bouncing problem be A LOT less of an issue?
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Not much at all. A switch might take 20ms to stop bouncing, that's still 5000 instruction cycles at 1MHz, if you get 1 instruction cycle per 4 clock cycles.
     
  3. helloeveryone

    Thread Starter Active Member

    Apr 8, 2011
    51
    0
    What about from 8MHz down to 500KHz? Still no difference?
     
  4. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    If you use a 32 KHz crystal you don't need I2C delay anymore.

    :):):):):):)

    But there is still a chance to see a switch bounce.

    Why worry it is only a few lines C to get rid of the bouncing.
     
  5. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Switch bounce has nothing to do with the oscillator ( whatever that means...). The bounce occurs for a time and settles to make firm electrical contact.

    Where the oscillator may come into play is it you attempt to debounce this button using a digital system, then you will need to determine how many clock periods occur before you count a switch as changing states ..
     
  6. helloeveryone

    Thread Starter Active Member

    Apr 8, 2011
    51
    0
    When using the counting method of software debouncing what is the most important thing?

    i) that a defined amount of time passes between readings
    ii) we precisely know the switch characteristic
    iii) that the readings are done successively without any unnecessary waiting

    I think it's i) but I'm not sure.
     
  7. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    You need a lowpass, the exact frequency is not so important, normally 50 mS or so, and not based on delays.

    Most softwares use a timer interrupt and a simple scheduler, so you need to learn about that.

    There is not really a thing such as exact switch characteristics, at least it is not important to know.

    Some websites eventually offer a datasheet for buttons but it is not really needed except for a commercial circuit.
     
  8. helloeveryone

    Thread Starter Active Member

    Apr 8, 2011
    51
    0
    How many thresholds does a digital software low pass filter use?
    a) none
    b) one
    c) two
    d) multiple, depending on the application.
     
  9. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Is there a more direct answer you are looking for, or are we going to continue beating around the bush with arbitrary questions?
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Homework questions should be put in the homework section. <g>

    Is seems your teacher has some specific method in mind when posing this question.

    It is NOT (ii) as that is never known about any part ever.

    (iii) seems to be continuously polling the switch which is definitely not to be done.

    As some minimum time should pass between readings (i) is the best answer.
     
  11. nigelwright7557

    Senior Member

    May 10, 2008
    487
    71
    I have done this loads of times using a pic.
    If the switch is active low.
    I take any low as the switch being pressed.
    Then I wait for no zeroes for 20ms before accepting switch is off.
    This has worked for 20 years worth of projects with no problems.
     
Loading...