Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: theory (not support) question: debouncing, 74hc14, and an oscope

  1. #1
    Junior Member
    Join Date
    Dec 2019
    Location
    the Bay
    Posts
    3

    theory (not support) question: debouncing, 74hc14, and an oscope

    This is a purely research question, not tech support, but I'm hoping it's interesting to someone on this forum. I've read the Bounce2 library and various others, and TBH, in practice I've found that a simple delay debounces well enough for my applications.

    But I wanted to play with hardware debouncing, and this is my progress. I've been trying to learn more about bouncy buttons and hardware debouncing.

    I wired a noisy button into my oscilloscope and a T4. The button is pulled up to 3.3v through 4.7K, with the other leg to gnd + the oscope's CH1 + pin14 on the T4 + and pin 1A on a 74HC14 inverting Schmitt trigger.

    The 74HC14's corresponding 1Y pin goes to the T4's pin15 + the oscope's CH2.

    In the sketch (attached), both pin14 and pin15 are attached to interrupts and count transitions; a third count puts a 200ms debouncing delay on the button's signal and counts.

    About half the time, a press results in an transition like the one in the image below and an increment of 1 on all 3 counts.

    Click image for larger version. 

Name:	DS1Z_QuickPrint1.png 
Views:	8 
Size:	35.8 KB 
ID:	18532

    But every 5-10 presses, the button goes bounce-tastic, like this:

    Click image for larger version. 

Name:	DS1Z_QuickPrint5.png 
Views:	7 
Size:	63.1 KB 
ID:	18533

    On that incident, in 14ms there were 36 rising edges counted on the button's pin and 34 falling edges on the pin connected to the 74HC14's output. The timescale is 200us/div, so only the first bounces can be seen in the image.

    I've attached a photo of my wiring and the code used to count button transitions.

    Questions:

    1) Am I setting up a test of debouncing correctly? what other stuff should I look at?
    2) The bounce patterns I'm seeing with this and other buttons don't look like other bouncy measures I've seen in various tutorials. In particular, the bouncing seems to happen much faster and settle more quickly -- on the order of us, not ms. This leads back to Q1: am I measuring correctly?
    3) I put an RC filter on the switch. I didn't show it here because it worked as expected: a single smooth rise, the 74HC14 creates a square transition exactly at the expected point, and the T4 counts each press only once.

    What other wiring + oscope study would illuminate contact noise? Thanks for any suggestions -- wylbur.

    Click image for larger version. 

Name:	IMG_1035.jpg 
Views:	7 
Size:	156.4 KB 
ID:	18534
    Code:
    /*
       testing button press counts 
       wylbur, 25 Dec 2019
    */
    
    const int BUTTON_PIN = 14; 
    const int CHIP_PIN = 15; 
    
    int chip_count = 0; 
    int button_count = 0; 
    int delay_button_count = 0; 
    int last_button_count = 0; 
    long time_at_last_press = 0; 
    
    void setup() {
      Serial.begin(57600);
    
      pinMode(BUTTON_PIN, INPUT_PULLUP);
      pinMode(CHIP_PIN, INPUT_PULLUP); 
    
      attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), isrButton, RISING);
      attachInterrupt(digitalPinToInterrupt(CHIP_PIN), isrChip, FALLING);
      
      time_at_last_press = millis(); 
      Serial.println("init complete."); 
    }
    
    void loop() {
    
      if (button_count != last_button_count) {
         Serial.print(millis()); 
         Serial.print(F(": button=")); 
         Serial.print(button_count);
         Serial.print(F(", delay_button_count=")); 
         Serial.print(delay_button_count); 
         Serial.print(F("; chip=")); 
         Serial.println(chip_count); 
    
         last_button_count = button_count; 
      }
    
    }
    
    void isrButton() {
      button_count++; 
      if (time_at_last_press + 200 < millis()) {
         delay_button_count++; 
         time_at_last_press = millis(); 
      }
    }
    
    void isrChip() {
      chip_count++; 
    }
    
    // done.

  2. #2
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,915
    With the different button behaviors, does how the buttons is pressed change anything? It is possible the button spring is ringing or resonating several times, where a different pressure/speed of press damps more quickly.

    The fun test would be to x-ray the switch while being toggled and see what is actually happening mechanically inside the thing but suspect (hope!) you are not setup to do that.

  3. #3
    Senior Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    135
    I think @GremlinWrangler is right on with the button rep rate issue. Tapping it slowly in your circuit will function well but nailing it willy nilly helter skelter will cause improper operation. Look into something like a Diodes APX811 POR reset generator chip and you will see there is a multi stage shift register taking periodic samples of the switch state. It then ANDs each register output, all of them, so when the switch bounce has settled down for several sampling periods the logic output goes active (stable). Another method would involve taking periodic samples of an input pin on Teensy and when 3-5 samples are in the same state, use that as your switch state.

Posting Permissions

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