Saturday, September 23, 2023

Eliminate SPST Debounce Delay with an SR Latch


I was looking into switch debounce problems for a project I was working on that required a foot switch. I solved that problem satisfactorily but that got me looking into articles on switch bounce. I came across an 8 part series by Max Maxfield that went into the problem in depth. What I came away with from that article series is that the only reliable way to detect a switch change quickly is with a SPDT switch and an S/R Flip-Flop. Which got me to thinking - why not do that for a SPST N.O. switch? After considerable (a few hours) of intense thinking and scribbling I came up with a workable circuit using an analog gate to route the switching signal. I later reduced that to a two output digital selector. You will note that as long as the changes take place after the debounce time, both the rising and falling edges will be indicated after a short "deglitch" delay.

The final circuit looks like this. If you need a name, call it "Simon De Bouncer" or if you need something a little more descriptive "Simon 'Zero Delay' De Bouncer"

Click on image to enlarge

There is a PDF of the schematic also.

Pretty fool proof eh? An SPST switch is made to act like a SPDT by selecting the SR Latch terminal that will drive it to the opposite state when the switch changes position. The XNOR insures the logic is correct in each state. The latch terminal selected doesn't change until after debounce time.

I'm multiplexing the switch between /PRESET and /CLR. So it acts like a SPDT. When the SR Q = 1 the switch is connected to /CLR and when the SR Q = 0 the switch is connected to /PRE. After a debounce delay.

The routing of the latch control signal doesn't change until after the bouncing stops. Simulating a SPDT switch. And the XNOR insures the logic is correct (ready for an input state change) after the bouncing stops. When I priced the logic out it was under $1.50 for all the chips at single piece prices. And if you put all the logic on a chip with a lot of other circuits? Almost free.

What does that give you? A switch logic indicator that responds in about 20 micro seconds to a change in switch position. The 20 micro second delay (glitch filter) eliminates noise pulses and ESD events from changing the indicated switch position. You may be able to shorten that time or may have to lengthen it as environmental requirements dictate.

So I was discussing all this with my esteemed first mate and I said it could also be done in software. (That's what they all say, isn't it?) That gave me the idea to write up some Forth code to show how it could be done. My buddy Clyde reviewed the code and made some suggestions. It looks like this: Switch Debounce Software.

Obviously there are some (not too difficult) details yet to be filled in.

I plan to run that code on my LPC1115 board with a Forth operating system also done by my buddy Clyde. The current version of that board uses a USB C connector. The compiled Forth code for the LPC1115 is available to anyone who wants to use it. You can find it here.

So that leaves us with VHDL for the deeply embedded. An exercise best left to the reader.

You can find me on LinkedIN at M. Simon.

You can see the beginnings of my thinking for the design at Sketch A and Sketch B.



Updated 28 Sept 2023 1945z - To give a better explanation of how the circuit works.


Updated 3 Oct 2023 1153z - Jack Ganssle's switch debounce experiments ==> A Guide to Debouncing

To clarify: Simon's Law of Switch Debounce.

Updated 16 Oct 2023 1759z A trackback from Jack Ganssle's Embedded Muse.



Space-Time Productions is a participant in the Amazon Services LLC Associates Program. We earn advertising fees when you use this link Amazon.com and other Amazon links we provide.

Engineering is the art of making what you want from what you can get at a profit.