4
\$\begingroup\$

This is the problem:

timing diagram

This is the proposed solution:

debouncer in verilog

What I don't understand:

The button bounces in the setup/hold time of the input of the circuit, making the FF go into a metastable state whereby it may settle to High or it may settle to Low. How then can the next FF in the shift register sequence get the initial input correctly?

In other words, if the button bounced at a critical time which resulted in the first FF going low, how then can the next FF interpret the original signal (button press) correctly?

\$\endgroup\$
1
\$\begingroup\$

To answer your specific question, most flip-flops in general, and the flip-flops used in shift registers in particular, have a minimum clock-to-output propogation time. What this means is that the output won't change state for a certain amount of time after each clock edge, and this time is greater than the maximum input hold time of the next flip-flop.

In most cases, each flip-flop is designed so that the required input hold time is in fact zero. And no flip-flop has a minimum clock-to-output delay that is less than zero.

When you connect flip-flops in series to deal with potential metastability, even if the first one goes metastable, it can't immediately case the second one to go metastable; the metastability must persist for a clock period before it could potentially make the second one go metastable as well.

\$\endgroup\$
0
\$\begingroup\$

In a very ideal sense, metastability can be sustained for an infinite length of time for unchanging conditions. It basically comes down to the fact that you can't prove that the indeterminate state won't hang around forever. In reality with rail bounce and transistor mismatching it would an extremely rare event for the metastability to persist for the length of a clock cycle.

In this design you are using edge triggered FF's which consist of master/slave latch pairs. When the clock changes state (on the negative edge) the conditions under which metastability can persist are disrupted. However, one could still argue that the metastability was transferred to the follow on latch in the FF. This is of course an even more rare event, because probabilities multiply together. BY the time you've added in a second FF any reasonable person would accept that the metastability basically cannot propagate through the FF's.

Here are some numbers to demonstrate the effect. Say that the probability of getting a metastable state that persists for 1/2 a clock cycle on the rising edge is \$P_r=\dfrac{1}{2,000,000}\$ and that the probability of propagating a metastable state that persists for 1/2 a clock cycle on the falling edge is \$P_f=\dfrac{1}{1,000,000}\$ then the combined probability of that making it through a FF is \$P_r*P_f=\dfrac{1}{1,000,000 * 2,000,000}=\dfrac{1}{2*10^{12}}\$. After a second FF this might be down to \$P_{2FF}=\dfrac{1}{2*10^{24}}\$. of course these are numbers just pulled from the air.

These sorts of events follow power law statistics. If you look at probability vs. length of persistence of metastable state it would probably follow a behaviour with every doubling of the time factor meaning that the probability is some factor (maybe X 1/2, or X 1/10 ) lower.

\$\endgroup\$
  • \$\begingroup\$ I appreciate the time you took in answering. The question I am really asking is, how exactly does the solution improve the circuit's functioning? If for example, you pressed the button within the setup/hold times of the FF, the result is still unpredictable, no? \$\endgroup\$ – midnightBlue Jun 2 '13 at 20:27
  • \$\begingroup\$ And as I answered that unpredictability cannot propagate because the probability of it happening twice or more decreases with each stage and metastability cannot be sustained through a change of state (clock movement). \$\endgroup\$ – placeholder Jun 2 '13 at 21:51
  • \$\begingroup\$ Say for instance, the metastable state dies down very quickly within 1 clock cycle. Then the next flip flop will result in 0. Therefore, wouldn't the signal of the button press be lost? So how do we deal with button presses on the exact clock rising edge? Is it that it is so improbable that it doesn't matter? If so, then what is the purpose of this circuit? \$\endgroup\$ – midnightBlue Jun 2 '13 at 22:53
  • \$\begingroup\$ If the button press signal is lost then it wasn't a button press but a glitch. If the signal is held and sustained then it makes it through, if it's indeterminate the double, or triple or etc. stages prevent a false trigger from causing a metastable state from propagating. \$\endgroup\$ – placeholder Jun 2 '13 at 23:13
  • \$\begingroup\$ So if I understand this correctly, a secondary FF is used to stop a meta stable state from propagating. But it can do nothing better than the original circuit when a switch is actually pressed on the rise time of the clock. (?) \$\endgroup\$ – midnightBlue Jun 3 '13 at 0:25

protected by W5VO Jun 2 '13 at 19:32

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).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.