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

Status
Not open for further replies.

wylbur

New member
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.

DS1Z_QuickPrint1.png

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

DS1Z_QuickPrint5.png

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.

IMG_1035.jpg
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.
 
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.
 
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.
 
Status
Not open for further replies.
Back
Top