'Double-Click' switch detector circuit ?

Discussion in 'The Projects Forum' started by timetec, Oct 12, 2009.

  1. timetec

    Thread Starter New Member

    May 10, 2009
    2
    0
    Interesting problem [​IMG] :

    I need to create a latching output from the 'double-click' of a momentary push-button switch, but only within a fixed time period, say 2 seconds....

    Think of double-clicking a mouse button - you must do it within a fixed period of time for the action to take place.

    Here's the idea :

    1/ A momentary switch is pressed once.

    2/ After pressing the switch, a timer starts, with a duration of 2 seconds.

    3/ If no further switch press is detected within the 2 second limit, no further action is taken - the output of the latch remains OFF / low.

    4/ If the switch IS pressed again before the 2 second time limit is reached, the output is latched ON / high.

    5/ A further single switch press simply resets the latch output to it's OFF / low state.

    I've thought of using 555's, AND gates & counters, but am now really pulling my hair out....

    Any circuit suggestions / sketches or tips would be greatly appreciated.

    Thanks all [​IMG]
     
  2. JDT

    Well-Known Member

    Feb 12, 2009
    658
    85
    Not too difficult to do either using some CMOS logic and a monostable timer or could be done in a simple micro-controller.

    What you have got to be careful of is "switch bounce". On a normal mechanical switch (using contacts), every ON to OFF and OFF to ON will be a multitude of edges over a short time. You can see this if you have an oscilloscope. So be very careful of using "edge-triggered" logic.

    In a discrete component solution you will need to filter the switch with a CR network. Then apply to your logic with schmitt-trigger gates.

    In a micro-controller system, the switch is normally "de-bounced" by looking at its state over an over again at a fairly high speed (say 1000 times per sec). If the last n readings were all the same (16 say), then it is assumed to be stable. A number less is ignored. Then you apply your timer and double-click logic.

    This is actually a kind of digital filtering.
     
  3. CDRIVE

    Senior Member

    Jul 1, 2008
    2,223
    99
    The 08M (8 pin Dip) Picaxe microcontroller could do this easily. ;)
     
  4. timetec

    Thread Starter New Member

    May 10, 2009
    2
    0
    I really like the idea of using a dedicated 8-pin PIC to do the donkey-work, instead of using a handful of CMOS IC's and many, many headaches !

    How big a job would it be to create a routine to do this ?

    Many thanks
     
  5. CDRIVE

    Senior Member

    Jul 1, 2008
    2,223
    99
    In Picaxe Basic it would be a snap. ;)
     
  6. CDRIVE

    Senior Member

    Jul 1, 2008
    2,223
    99
    You can download the free and very slick Programmer/Editor here.
    http://www.rev-ed.co.uk/picaxe/

    Here are othe Picaxe sources.
    http://www.world-educational-servic...h=picaxe&search_button.x=15&search_button.y=8

    http://www.hippy.freeserve.co.uk/picaxeqa.htm

    http://www.sparkfun.com/commerce/product_info.php?products_id=8322

    The programming editor has a Simulation Mode that enables the developer to write and test a program without any connection to the chip, though some programs really need real time for a true test of your code. This is because the simulator intentionally runs in adjustable slow motion and does not run in real time.
     
  7. erikspan

    New Member

    Feb 29, 2016
    4
    0
    Hi, I realize this is an old thread, but I came across it searching for a solution for exactly the same problem! So I was wondering how you fixed it in the end?
     
  8. JohnInTX

    Moderator

    Jun 26, 2012
    2,345
    1,028
    It is usually best to start a new thread with your question but since you indicate that your problem is exactly the same, the thread can continue.
    I like the others' idea of using a small uC instead of a lot of logic. Personally, I'd use a small PIC coded with XC8 but we'll see what other good ideas are offered. Its unlikely that the original members will answer since the thread is so old.
    You should post a sketch of what you want to control with a detailed description of how you want to do it.
    Good luck.
     
  9. erikspan

    New Member

    Feb 29, 2016
    4
    0
    Thanks! I'll start a new thread about this sometime soon. A uC would be the most elegant solution, I agree!
     
  10. Sensacell

    Well-Known Member

    Jun 19, 2012
    1,130
    266
    Another way to accomplish this is with a capacitor charge pump.
    One button press doesn't reach the trigger threshold, but two in rapid succession does.

    It's a simple analog solution.
     
  11. erikspan

    New Member

    Feb 29, 2016
    4
    0
    Thanks! That is an interesting approach. I hadn't think of an analog solution before. I'm definitely going to try that. Combined with a Schmitt-trigger for instance this could do the trick.
     
  12. blocco a spirale

    AAC Fanatic!

    Jun 18, 2008
    1,438
    368
    Here's one way of doing it:
     
    absf likes this.
  13. crutschow

    Expert

    Mar 14, 2008
    13,009
    3,233
    Below is my take on doing the charge pump approach suggested by Sensacell.
    It's operation is shown for two push button presses 0.5s apart with multiple contact bounce pulses per press.
    The signal is converted to a digital pulse at the second button press by a NAND Schmitt trigger.
    The values of R1 and R2 can be varied to control the time between pulses, and the time to reset.

    upload_2016-3-19_13-27-34.png
     
    Sensacell likes this.
  14. blocco a spirale

    AAC Fanatic!

    Jun 18, 2008
    1,438
    368
    But it doesn't meet the criteria defined by the TS. i.e. double click = latch on, single click = off.
     
  15. dannyf

    Well-Known Member

    Sep 13, 2015
    1,806
    361
    Check out ladder logic: it can program AVR / PIC graphically for something like this.

    As to analog solution, it shouldn't be difficult to do so with a resistor + capacitor.
     
  16. blocco a spirale

    AAC Fanatic!

    Jun 18, 2008
    1,438
    368
    How would that work?
     
  17. crutschow

    Expert

    Mar 14, 2008
    13,009
    3,233
    Yes, I didn't include that.
    My interest was in how to detect the double click with an analog circuit.
    It may not be that amenable to the double-click, single-click requirement. :confused:
     
  18. WBahn

    Moderator

    Mar 31, 2012
    17,743
    4,795
    I think this would be used to detect the double-click case and a separate circuit would detect the single-click case and reset the latch. The single-click detection would have to be filtered by the double click circuit to prevent resetting the latch on the first click of a double-click event.
     
  19. WBahn

    Moderator

    Mar 31, 2012
    17,743
    4,795
    I was curious how it would respond to the bounces, too. Thanks for the doing the sim.
     
  20. erikspan

    New Member

    Feb 29, 2016
    4
    0
    Thanks so much for your input guys! Very interesting. I'll let you know how things worked out!
     
Loading...