antonantal said:
I think I finally got it. The setup time restriction might not be met at the second flip-flop. At the first flip-flop it is not the case because it's input is always at +Vcc, but the input of the second flip-flop might change at a time less than t_{SU} before the rising edge of the system clock. This will cause the flip-flop to enter a metastable state in which the output oscillates between '1' and '0', and will take some time to settle down. This could be solved by adding another D flip-flop with it's input to the output of the second one and the clock input to the system clock. This way we give the second flip-flop a time of one clock period to settle down from the metastable state.
Excellent! That's exactly the issue that I wanted to highlight with this circuit. When you have an asynchronous signal (like a button press, or a receive data line in a communications system) that you want to bring into a clocked system for processing, you must invest at least two FFs in series to synchronize the signal to the internal clocks.
The usual way you would do it is to bring the asynchronous signal into the D input of the first FF, and the Q output of that FF goes into the 2nd FF's D input. Both FFs are clocked by the system clock. The output of the 2nd FF is what you would use inside the clocked processing circuitry.
The issue is indeed the metastability that can be caused when the setup or hold times for the FF are violated, which can happen easily with an asynchronous input signal. So there is a finite probability that the first FF will have its output go metastable at times, but FFs are also rated by how long it is likely that the metastable state will persist. And usually, the probability that the output of the first FF will be wrong by the time the next clock comes along, is very low. That is, even if the first FF goes metastable, it is likely that its output will be correct for the next clock cycle, so the setup and hold times of the 2nd FF will be met, and it will not go metastable. But, if the clock rate is very high, and the FFs are not super-fast themselves (which shortens the metastability relaxation time), then you might need to series connect 3 FFs as the synchronizer, instead of the more typical two FFs.
Good job antonantal. BTW, there is a good discussion of all of this in the paper that I referenced with this Bad Circuit post (post #152).
EDIT -- I'll look around a bit for another good Bad Circuit to post. Work has been very hectic lately, so it may take me a couple days.