# How to eliminate the forbidden state in an SR latch?

I'd like a latch where the output only changes when both inputs have changed. If only one input has changed, the latch output should stay constant.

Here's the state table I want:

S R | Qnext
----+------
0 0 |   Q
0 1 |   0
1 0 |   1
1 1 |   Q


The above looks just like a standard SR latch, except that the (1, 1) forbidden state is replaced with a hold state.

How can I design the above latch? I could add some logic to convert the (1, 1) inputs to (0, 0) (e.g., S' = S(~R), R' = R(~S)), but I'm worried about glitches.

Background/motivation:

I have a double pole single throw (DPST) switch (one normally open, one normally closed). I assumed that when the switch is toggled, the pole that is closing would bounce while the pole that is opening would not. If this assumption had been correct, I would have been able to debounce the switch with the above latch.

If my assumption had been correct, then the main challenge would have been the fact that the two poles are racy: pole #1 might change before or after pole #2 changes. This would mean that during a transition the poles could be in any state: (0,0), (0,1), (1,0), or (1,1). But, there would be a property I could rely on: Once the switch went from (0,1) to (1,0) (or vice-versa), it wouldn't bounce back. This property would have allowed the above latch to debounce the switch.

• Your latch definition doesn't address the problem. If the switch is as unpredictable as you say, then all four input combinations could occur during the bouncing period. You'll have to define a time interval that starts at the first transition on either input, and then declare the new state at the end of the interval. – Dave Tweed Jan 1 '13 at 22:49
• First, sounds like the switch is really DPDT. Second, sounds like you are trying to detect the final position of a switch that has two positions. I recommend using the switch as a SPST and debounce that signal. – Michael Pruitt Jan 2 '13 at 4:02
• @DaveTweed: Yes, all four input combinations can occur before the switch settles. However, because one pole is normally open and the other is normally closed, there is a temporal restriction. Suppose the switch is in the (0,1) state. When the switch is toggled, it can jump around between the (0,1), (1,1), and (0,0) states before hitting (1,0). However, once the switch hits (1,0) it can't bounce back to (0,1). The same goes for the opposite case. I believe this means that the latch I described can be used to debounce the switch. – Richard Hansen Jan 2 '13 at 6:21
• @DaveTweed: I'm assuming that a pole only bounces when contact is being made---that it opens cleanly. Maybe that's a flawed assumption; if so then this switch can't be debounced with a latch. But I'm still curious to know how to construct the described latch. – Richard Hansen Jan 2 '13 at 6:23
• @MichaelPruitt: The switch is a DPST, with one pole normally open and the other pole normally closed. It has four terminals. When the switch is in the off position, terminals A and B are not connected and terminals C and D are connected---(0,1). When the switch is in the on position, terminals A and B are connected and terminals C and D are not connected---(1,0). The switch has two positions---on and off---but there are four possible pole states: When the switch has settled, it is either in (0,1) or (1,0), but during a transition it can also be in (0,0) or (1,1). – Richard Hansen Jan 2 '13 at 6:32

First of all, your assumption that mechanical switches open cleanly is false. They bounce on both make and break.

However, to address the specific question of the latch, it's simply a matter of creating an S-R latch that only switches on the "final" states (0,1) and (1,0). The latch will change state the first time the new final state is reached. If the make occurs first then the bouncing between the initial state and (1,1) will cause no change to the latch. Once the other contact breaks then the latch will switch, and any bouncing back to (0,0) will be ignored. If the break occurs first, then the latch will switch on the first make of the other contact, and again, any bouncing back to (0,0) will be ignored.

• So I don't have to worry about glitches. Thanks! – Richard Hansen Jan 2 '13 at 16:34

A typical SPDT switch will be "guaranteed break-before-make", meaning that even if moving the lever slowly could the contact being opened to bounce for an unspecified duration, the second contact won't close until after the first contact has opened for good. Thus, you shouldn't have to worry about the second contact being closed.

There are, however, a couple of points you may consider: (1) there are a number of ways you can design the switch circuit so that the switch will draw zero power in a steady-state condition. For example, instead of using NAND or NOR gates, use inverters with resistors in the feedback path, and use the switch to ground one or other inverter's input; (2) even with a two-state switch, absolutely perfect debouncing is impossible, because the contact which is closing might conduct for an extremely brief moment and then re-open for awhile before it closes for good. If the initial brief closure is just the right length, it may disturb the latch enough to stop it from holding a clean latched "zero", but not enough for it to latch a clean "1". This could cause a condition called "metastability"; there are ways by which one may make metastability extremely improbable (e.g. to somewhere around probability of one's apparatus being destroyed by a random meteorite) but it's hard to eliminate it as a possibility.

• The switch I was trying to debounce with a latch is a DPST, not a SPDT. – Richard Hansen Jan 3 '13 at 18:18
• @RichardHansen: Ah, with both poles switching in the same direction (as opposed to independent poles which close at opposite ends of travel)? If the switch is designed so that one pole is guaranteed to make after and break before the other, a latching circuit as you describe be helpful; if no such guarantee exists, having two switch inputs is unlikely to be much better than having one, though one can use resistor tricks so that the resistance required to detect a contact as "closed" is lower than that required to decide it hasn't "opened" yet. – supercat Jan 3 '13 at 19:07

## protected by W5VO♦Jan 2 '13 at 3:11

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).