Author Topic: ESP8266 - Pushbuttons, debounce & how to easy debounce story  (Read 17071 times)

0 Members and 1 Guest are viewing this topic.

Offline mrkev

  • Regular Contributor
  • *
  • Posts: 214
  • Country: cz
Re: ESP8266 - Pushbuttons, debounce & how to easy debounce story
« Reply #25 on: April 02, 2015, 08:26:36 pm »
And you can go to ultra low power mode for longer times ( than 20 ms), but you can use the same pin you use for scanning as the ext. int. pin, so no extra pin needed.
Sure, everything has its advantages. Anyway, what do you mean by that second sentence? Many uC have just one pin that can be used for external interruption...
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 5779
  • Country: nl
Re: ESP8266 - Pushbuttons, debounce & how to easy debounce story
« Reply #26 on: April 02, 2015, 08:30:13 pm »
Anyway, what do you mean by that second sentence? Many uC have just one pin that can be used for external interruption...
The microcontrollers I worked with till now like the stm8 and arms for instance can have interrupts on most if not all of its GPIO pins.  :-//
 

Offline mrkev

  • Regular Contributor
  • *
  • Posts: 214
  • Country: cz
Re: ESP8266 - Pushbuttons, debounce & how to easy debounce story
« Reply #27 on: April 02, 2015, 09:54:16 pm »
Anyway, what do you mean by that second sentence? Many uC have just one pin that can be used for external interruption...
The microcontrollers I worked with till now like the stm8 and arms for instance can have interrupts on most if not all of its GPIO pins.  :-//
:D Well, here we go again. Everything can be great in a specific application, and everything has advantages/disadvantages... Something that really good solution (like two RC filtered buttons going to ext. int. pins at low consumption device) can be almost wrong solution in other case (trying to fit whole matrix of buttons with RC filters on two int. pin that you have available on your uC)...
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 14718
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: ESP8266 - Pushbuttons, debounce & how to easy debounce story
« Reply #28 on: April 03, 2015, 02:12:52 am »
I like this one, it's ultra robust. It works even if input never stabilizes and consists of never ending bounce.
<snip>


This method is equivalent to the method I detailed above, and similar or equivalent to those others have mentioned.  The difference is practically semantic: my exact wording uses more shift registers (exactly N) and less logic (a handful of full adders); the above uses fewer registers (one for the input, and Lg(N) for the state) and more complicated logic (full Lg(N) bit adder/subtractor, plus comparators and mux to implement the saturating arithmetic).  A sufficiently powerful compiler/synthesizer should be able to generalize more-or-less the same logic from either method, although I don't know if they are quite *that* powerful yet.

So as you can see, it's a pretty good way to do it. :)

Thanks to the Lg(N) state, and relatively modest logic requirement (loads of combinatorial logic often come for free, e.g. the huge macrocells of a CPLD, or the word-sized addition and conditional statements of software programs), this implementation is much better suited to large N, which through many variations, might be used for debouncing, timers, delay/phase shifter chains, missing pulse detectors, etc.

For the small N counts used for simple debounce, it's not usually worth it, but there might be reasons to do it this way regardless.  For example, if your processor has SIMD "packed" instructions, you can do a whole pile of these additions and stuff at once.  (True SIMD instructions often use saturating arithmetic anyway, so you don't even have to implement that, it comes for free!)  Probably not likely to be relevant on a microcontroller, but a possibility to be aware of. :)

Tim
« Last Edit: April 03, 2015, 02:14:53 am by T3sl4co1l »
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 14718
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: ESP8266 - Pushbuttons, debounce & how to easy debounce story
« Reply #29 on: April 03, 2015, 02:17:28 am »
I usually just use a really simple scheme that works perfectly and doesn't require any hardware or tricky code.

- Set up a timer at say 10Hz
- Scan buttons on timer interrupt, set "pressed" bit RAM when detected
- Increment repeat counter if key repeat needed once every second or so

That's a poor way to do it, because humans can press buttons way faster than 10Hz, and see responses much faster than 100ms.  You'll have buggy-feeling, laggy, sloppy interfaces doing it like that.

I would say 30Hz is an absolute minimum (which is also the minimum speed of most video games), and 100-200Hz (which allows for suitable filtering down to an equivalent 50-100Hz bandwidth) as recommended.

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 5779
  • Country: nl
Re: ESP8266 - Pushbuttons, debounce & how to easy debounce story
« Reply #30 on: April 03, 2015, 08:09:56 am »
:D Well, here we go again. Everything can be great in a specific application, and everything has advantages/disadvantages
Oh absolutely, no argument about that.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf