Hardware switch debouncing (mod) - Overclock.net - An Overclocking Community

Forum Jump: 

Hardware switch debouncing (mod)

Reply
 
Thread Tools
post #1 of 29 (permalink) Old 11-06-2018, 05:37 PM - Thread Starter
New to Overclock.net
 
TranquilTempest's Avatar
 
Join Date: Aug 2011
Posts: 1,683
Rep: 78 (Unique: 63)
Hardware switch debouncing (mod)

Every couple years my switches wear to the point where my mouse's switches stop working properly. This is caused by the mouse only using the NO contact of the switch, relying on delays to debounce instead of connecting the NC contact to a second input and using a set-reset type debouncing.

So this last time I got a bit fed up with it, and decided to mod in some hardware debouncing:

I went with option 1, because I had a quad opamp on hand, and was only going to do the 3 main buttons. If you want to mod more than 4 buttons, I'd suggest using a buffer instead of opamp. Fewer pins to solder, and you don't have to worry about the threshold voltage. I used 3.3v because my mouse already had that rail for the sensor, but you can use a resistor divider to get any threshold voltage you want. As long as it's between the microcontroller's VCC and ground it should work. You also want to drive the high side of the switches and opamp/buffer from the same voltage the microcontroller uses.

To implement it first I had to score the PCB to cut through the existing switch traces and ground plane(both top and bottom), then rewired the switches manually. I also had to carefully scrape the solder mask away from part of the original traces and solder a wire to it from the output of the opamp. If you haven't done this kind of modification before, practice on something you are willing to destroy. While I had it open I also replaced the switches and mouse wheel encoder(which was starting to lose pulses).

In the photos, blue is a switch's common contact, white is connected to the original switch trace to the microcontroller, and yellow is the threshold voltage. First photo is partway done, second photo is done.

P.S: Is it possible to modify the firmware on a CM Storm Spawn to completely get rid of the software debounce delay?




TranquilTempest is offline  
Sponsored Links
Advertisement
 
post #2 of 29 (permalink) Old 11-07-2018, 01:51 AM
New to Overclock.net
 
gipetto's Avatar
 
Join Date: Jun 2017
Posts: 492
Rep: 9 (Unique: 7)
That's interesting. I've carried out that mod before but it always ended up much larger using a digispark or dip sr latch ic. That is an improvement in size and current consumption. None of my mods stood the test of time though. I think it's better to use a multibutton programmable mouse and program set/reset on separate buttons with jumper wires, less messy and more reliable. I gave up modding though, too many disasters.
There was an article on hackaday about mouse firmware modding for the stm32 but given you would need to replace the entire firmware it would be biting off more than you could chew. your mouse is a cypress mcu in any event.
gipetto is offline  
post #3 of 29 (permalink) Old 11-07-2018, 03:15 AM
Overclocker
 
JackCY's Avatar
 
Join Date: Jun 2014
Posts: 9,519
Rep: 319 (Unique: 231)
Or you can spray a contact cleaner into the switches and they are good for another year or even two. I have switches that last over 10 years of heavy every day use that way.

Sure it would be nice if they implemented the switches proper using both contacts and not only 1. But it has it's disadvantage especially on light force switches as well as you won't be able to tap until you hit the 2nd reset contact.

Some mice also use non mechanical switches to solve these issues instead.
JackCY is offline  
Sponsored Links
Advertisement
 
post #4 of 29 (permalink) Old 11-07-2018, 04:23 AM
New to Overclock.net
 
gipetto's Avatar
 
Join Date: Jun 2017
Posts: 492
Rep: 9 (Unique: 7)
>ut it has it's disadvantage ... you won't be able to tap until you hit the 2nd reset contact
I beg to differ. I've measured the speed on my mouse in the picture http://instantclick.io/click-test . thats more than an order of magnitude lower than the debounce period of any other mouse. In this picture for a fast click I flicked a screwdriver handle at the button and got mousedown to 2ms! I've even crashed the tester by getting below 1ms
Attached Thumbnails
Click image for larger version

Name:	oneclick.jpg
Views:	26
Size:	104.9 KB
ID:	229882  


Last edited by gipetto; 11-07-2018 at 04:29 AM.
gipetto is offline  
post #5 of 29 (permalink) Old 11-07-2018, 09:49 AM - Thread Starter
New to Overclock.net
 
TranquilTempest's Avatar
 
Join Date: Aug 2011
Posts: 1,683
Rep: 78 (Unique: 63)
Quote: Originally Posted by JackCY View Post
Or you can spray a contact cleaner into the switches and they are good for another year or even two. I have switches that last over 10 years of heavy every day use that way.

Sure it would be nice if they implemented the switches proper using both contacts and not only 1. But it has it's disadvantage especially on light force switches as well as you won't be able to tap until you hit the 2nd reset contact.

Some mice also use non mechanical switches to solve these issues instead.
If you hit the snap action, you hit the second contact. Considering how noisy these switches are on release, it's a lot faster than a reliable delay based debounce. That's why the switches start clicking extra times in the first place, the delay is insufficient to cover it. With this, or SR latch based debouncing, you can trigger on the first edge. No waiting any delay.


Last edited by TranquilTempest; 11-07-2018 at 12:51 PM.
TranquilTempest is offline  
post #6 of 29 (permalink) Old 11-07-2018, 01:26 PM - Thread Starter
New to Overclock.net
 
TranquilTempest's Avatar
 
Join Date: Aug 2011
Posts: 1,683
Rep: 78 (Unique: 63)
Quote: Originally Posted by gipetto View Post
None of my mods stood the test of time though.
What were the failure modes?
Quote:
I gave up modding though, too many disasters.
It was already broken, so no harm in trying. I was almost to the point of just buying a new mouse.

However it did take me a lot of time. I think I'd only repeat the mod on a mouse with open source firmware.

TranquilTempest is offline  
post #7 of 29 (permalink) Old 11-07-2018, 05:01 PM
New to Overclock.net
 
gipetto's Avatar
 
Join Date: Jun 2017
Posts: 492
Rep: 9 (Unique: 7)
The digispark mod I think was drawing too much current so the voltage would drop down to around 3v and make the mouse unusable.( I was drawing 500 ma through a 100ma mouse) It worked fine when I made it, the issue developed over time. I could have changed out the cable but it was only a 400dpi mouse so why bother. I used a nano as an earlier version and the mouse became quite hot to use. it added a fair amount of weight also. The bst/qsxcv 3360 mice I made would fail for unrelated reasons, scroll wheel would jam, sensor wouldn't track correctly in one mouse for some reason.
The switches were never an issue though. electronics is a money pit I find, especially when I let the smoke out which happens often as I become more forgetful with age. I asked bst about making the astrum open source but he disabled that feature so that it would not be blocked from tournaments. I'm not quite sure how that works, is there an md5 sum or a password in the hex firmware?
There is arm c code for the stm32 for mechanical keyboards around. any usb communication is routed through chibios though because nobody knows how to program arm in bare metal. I played around with the arm teensylc for a while but it has too little ram to handle chibios and a full keyboard matrix. I guess if you wanted to diy mouse firmware the choice is to port the bst3360 code to chibios or to use the example code that comes with the tindie sensor and the terrible arduino libraries.

https://hackaday.com/2017/07/29/inje...our-next-hack/
gipetto is offline  
post #8 of 29 (permalink) Old 11-07-2018, 06:20 PM - Thread Starter
New to Overclock.net
 
TranquilTempest's Avatar
 
Join Date: Aug 2011
Posts: 1,683
Rep: 78 (Unique: 63)
Quote:
I was drawing 500 ma through a 100ma mouse
That's quite a lot. Was the microcontroller drawing that much, or other parts on the dev board? The microcontroller itself has a maximum rating of 200mA on the VCC and ground pins, so if it was drawing 500, that's probably what killed it.

TranquilTempest is offline  
post #9 of 29 (permalink) Old 11-07-2018, 07:46 PM
Overclocker
 
JackCY's Avatar
 
Join Date: Jun 2014
Posts: 9,519
Rep: 319 (Unique: 231)
Quote: Originally Posted by gipetto View Post
>ut it has it's disadvantage ... you won't be able to tap until you hit the 2nd reset contact
I beg to differ. I've measured the speed on my mouse in the picture http://instantclick.io/click-test . thats more than an order of magnitude lower than the debounce period of any other mouse. In this picture for a fast click I flicked a screwdriver handle at the button and got mousedown to 2ms! I've even crashed the tester by getting below 1ms
That measures how long you hold a button pressed down and is affected by software debounce. Not what I was saying, I can press a switch without clicking it back up, as in you click down +down_event lower the force on a button +up_event no click switch doesn't reset fully up to hit the second contact now press down again +down_event. But because you're now relying on both contacts you can't do this. Sure it's not useful to most people but when you have a soft old switch and a mouse you're used to for a very very long time, it is easy to do and use.

Sure software debounce sucks and should not be used, no argument there. Most mice at least old were 16ms (125Hz USB), newer are 22ms (1000Hz USB) or more maybe some less but who cares if they are otherwise unusable.

What do you use to disable the debounce in firmware? Or have a firmware with no debounce from someone else for specific mice and simply load it (ie not write it etc. not an author only a "monkey")?
JackCY is offline  
post #10 of 29 (permalink) Old 11-07-2018, 08:01 PM
bst
Hardware Rep
 
bst's Avatar
 
Join Date: Sep 2011
Posts: 831
Rep: 89 (Unique: 49)
You can't edit the FW in the MCU afaik, I think the only way you could do it is if you add another MCU (like the teensy 2.0) to handle the mouse clicks, so it would end up as if you have two mice plugged in where you use the buttons on one and the sensor on the other.

You'd need to make a paracord, I'm not sure how many wires you'd need. Maybe you can share the +5V and GND from one USB port, and just have one extra D+ and D- each for the buttons. I've never done it before so I don't know the best practice with that kind of thing. The safest way to do it would be to run them completely separately, but it'd be 8 wires then.

Maybe you can take the D+ and D- from the original mouse, run it through the new MCU somehow, and add on the button clicks, I have no idea if that's even possible, but it would bring the cable down to 4 wires.
bst is offline  
Reply

Tags
dead bug , debounce , latency , mouse mod , Switches

Quick Reply
Message:
Options

Register Now

In order to be able to post messages on the Overclock.net - An Overclocking Community forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.
User Name:
If you do not want to register, fill this field only and the name will be used as user name for your post.
Password
Please enter a password for your user account. Note that passwords are case-sensitive.
Password:
Confirm Password:
Email Address
Please enter a valid email address for yourself.
Email Address:

Log-in



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page


Forum Jump: 

Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off