That notorious debouncing solution..
LoopyByteloose
Posts: 12,537
After years of reading all sorts of software debouncing solutions or special debouncing chips, I am back to a simple SPDT push button and a S-R flip-flop. (NO, not the J-K flip-flop)
Why? Simply no time delay.
http://www.electronics-tutorials.ws/sequential/seq_1.html
All the other debouncing options delay the response time of the microcontroller. This was never made clear to me before (Not even in 'The Art of Electronics' by Horowitz, et al.).
So if you must debounce, just as a 20 pin DIP for 4 switches and 8 pullup resistors. Skip all the other stuff as it under-performs (unless you find some really nice Hall-effect switches).
Why? Simply no time delay.
http://www.electronics-tutorials.ws/sequential/seq_1.html
All the other debouncing options delay the response time of the microcontroller. This was never made clear to me before (Not even in 'The Art of Electronics' by Horowitz, et al.).
So if you must debounce, just as a 20 pin DIP for 4 switches and 8 pullup resistors. Skip all the other stuff as it under-performs (unless you find some really nice Hall-effect switches).
Comments
How to wait for button state?
1) Use WAITPEQ. Do your stuff. Delay for 20 mSec. Repeat.
2) Regularly check pin state and do other stuff. If button pressed do your stuff and don't read button for next 20 mSec. Repeat.
That's a theoretical idea.
Sorry, I am going to party and example code snippets will follow later.
Well, i have nothing to program --- no Propeller involved inside the camera (a Canon SX-150).
I just need a bounceless push button that will plug into a mini USB interface. The examples I have seen for DIY devices (instead of the Ricoh CA-1 or CA-2), debounce with a capacitor and a pull-up. And many examples don't even add debounce.
http://hackaday.com/2012/04/30/adding-a-remote-shutter-to-a-cheap-digital-camera/
Software debouncing has been covered in depth with the Propeller. It is worth mentioning, but won't work here.
As soon you get a signal-change do what you want to do, but also disable any hardware IRQ/software check of button for the next 20ms as to ignore multiple "fake" button presses.
.
I can't quote the exact amount of time it takes for the MOSFET to turn on, guess it really depends on which one you use. It appears the turn on is instant but the turn off does show a slight curve as the resistor discharges the cap, somewhere around half a millisecond or so. If the switch you have has poor contacts this may not work because of added resistance to charging the cap.
Micro-switch come in SPDT, so for those this is a valid solution.
Besides S-R FF designs using SPDT, there is also a Pin-keep design, which has no static power drain and needs simpler logic ( 1G17 / 2G17 / 3G17 )
The feedback resistor gives the current threshold, and once driven past that, the output locks in that state, until driven the other way.
If your application lacks a SPDT, then you can get 'no time delay' on the leading edge with a simple re-triggerable Monostable (1G123 etc) - this allows use of a simpler SPNO switch, and any bounce extends the ON time.
The trailing edge does have delays, but that is less important in most applications.
Then. a purist may decide that their SPDT switch also needs a fail-detect check system, which moves a little beyond logic to a software solution.
If the cables are long, some designs may chose to add a RC filter to the trigger, and trade of a little delay (sub 1ms) for better noise immunity.
On small lcd clocks, when you set the time you hold the button down it will increment slowly at first, then it increases exponentially. That is a really good example of controlling debounce externally. It also leaves a lot to be desired. There are pros and cons to both but the thread started out as uC and turned into non-uC so I'm not sure this is relevant.
You seem to be thinking of only the first edge of the pulse (this would be rising edge in my situation). AND< I have nothing programable! I require a hardwire solution.
I need both the rising edge and the falling edge of the pulse to be under my control.
The rising edge has the camera seek focus, the falling edge activates the shutter.
Aye, ye olde 74123, among others. A few more components than a basic FF, but a good range of flexibility in these things. I've done projects with these for 30-odd years, including motor control PIDs, system master reset switches, and a few other things. Loopy is right that for basic pulse cleanup and stretch the simple hardware approaches are easier and cheaper if no MCU is part of the mix.
That still has delays, and normal retriggerable one-shot's are edge triggered, not level-holding.
The OP wants no delays, on either edge, but smarter bounce suppression would allow SPST contacts to be used.
This can be done with 2 tiny logic parts an EXOR + D-FF ( 1G58 + 1G80), and a RC
Leading edge _/= loads the FF, then after the settle delay, the XOR flips the clock, and the first release-edge =\_ clears the DD. ( D connects to the RC )
This gives SPST de-bounce on both edges, with no edge delays.
Canon has software called CHDK that modifies any Canon digital to use a remote shutter control and it offers three choices of configuration.
A. One pulse - button down focus, button up shutter
B. Two pulse - first pulse focus, second pulse shutter
C. Ricoh CA-1 format
http://chdk.wikia.com/wiki/CHDK
I am still working on getting a 4043 Quad RS flip-flop for option A, but it should work with option B as well.
The Ricoh CA-1 has been replaced by the Ricoh CA-2
+++++++++
These days, Hall Effect push buttons are not that easy to find. Digikey provides some in a price range from $14 to $50 USB, but nothing in stock.
The Ricoh CA-2 is available for $30 USD on Amazon. It is an interesting solution with 1.5v AAA for power stepped up to 5V to a microcontroller that provides precise pulses -- a bit of overkill (I suspect that Ricoh wanted to make their camera's dependent on a particular pulse format.)
=+==++===++
I might be wrong, but the SPDT push buttons are not that hard to find.
I went shopping locally today.
A SPDT push button was 75 cents and a 4043 RS flip flop was 30 cents.
On any state change, WAITPEQ for the new state. When the WAITPEQ falls out take 3-5 more measurements to make sure the state change holds. This will be imperceptible but will weed out microsecond noise pulses (I've seen this in the field). Once the new state is established run code for the state change, WAITCNT a few milliseconds for switch bounce to subside (it's not physically possible to press and release a switch in say 5 milliseconds), and repeat with a wait for the new state.
This will give you sub-millisecond level control of both the press and release with no hardware and no bounce.
Obvious there are situations where the hardware or software solutions prove more optimal.
In any event, managing to completely avoid a delay is an important criteria. After all, many of these switches are intended for robotic solutions or processes that can ill afford a latency.