Transcript for:
Understanding Metastability in Flip-Flops

Hello and welcome to ElectroTuts. In this video, we will be looking at the concept of metastability in detail. So let's get started. We have learnt from the previous videos on static timing analysis and interview questions that when dealing with sequential circuits like flip-flops, some conditions must be followed. Input to the flip-flop must remain stable at least setup time before the clock edge. I mean this time must be greater than TS. Input D must not change in this region before the clock. Also, another condition is imposed that says the input D must be stable at least whole time after the clock edge. I mean this time must be greater than TH. The input D must not change in this region after the clock. Now, here comes an obvious question. What happens if the input D is changing during the aperture time around the clock? Aperture time is another name for setup time plus hold time. We know that if the input to the flip-flop D is stable at low value during the aperture time, the output Q takes a low value, whatever be the previous output. Similarly, if the input D is high during the aperture time, Q takes a high value. If the input D changes to a high or a low value during the aperture time, flip-flop captures a value part way between low and high and this state is called as metastable state or a quasi-stable state. The output will eventually settle to a high or a low but it can take unlimited amount of time to to resolve into a good low or high value. This whole process of flip-flop going into a metastable state and then settling into one of the stable states, a high state or a low state is known as metastability. Moving further, let's get some intuition about what a metastable state is through a common analogy. Consider a hill on a golf course. The valley around the hill can be related to the two stable states of a flip-flop, a high and a low state. Then the top of the hill becomes the metastable state. From position 1, if you hit the ball lightly, it remains where ball 1 is. But if you hit the ball hard, it crosses the hill and reaches 2. But if you hit the ball such that it lands at the top of the hill and stays there, Even the slightest disturbances like the wind will make the ball fall to either 1 or 2. The hilltop is the metastable state because even if the ball can reach this state, it can't stay there infinitely in the real world because of the disturbances or the noises present. Same goes true for any bistable device like flip flop. The flip flop must go through a metastable state when transitioning from one stable state to another. and transitioning during the aperture time can be compared to reaching and stopping at the top of the hill where you know that the ball will eventually fall but you don't know the exact amount of time after which the ball will fall. Now that you have an idea about what metastability and metastable state is, let's look at some possible causes for the metastability in a system. If setup time constraint or hold time constraint is not met for the system, The concept of setup time constraint and hold time constraint is discussed in great detail in my previous videos on STA. If you want to know more about them, you can look at my previous videos from the link in description below. If the input to a flip-flop is asynchronous, this statement needs some more explanation. If the input to a system is, let's say from a button, you can't predict when the button will be pressed. Therefore you can't ensure that the system won't go into the metastable state. Let's look at another example, where the input to the flip-flop is asynchronous. If we connect two systems operating at different frequencies or at the same frequency but different phase, then also the input to the receiving system is asynchronous compared to its own clock domain. To explain this statement, Let's have an example of two systems A and B operating at different frequencies defined by clock A and clock B. Now let's say if A wants to share some data with B. then because of different frequencies, it can't be ensured that data received by B is not changing during the aperture time. So, we can't ensure that the system doesn't go into a metastable state. After discussing so much about the metastability, let's look at an obvious question. Why should we care? Why should we care if the flip-flop goes into a metastable state? We should care because Once a flip-flop goes into a metastable state, the amount of time it takes to settle to one of the valid states is unknown. So, if the data output resolves before the next flip-flop captures it, the system doesn't get impacted negatively. But if it fails to resolve in the allotted time, I mean before it reaches the next flip-flop, it can cause system to fail and these failures are very difficult to track down and even correct. So, we need to ensure that the system avoids going into a metastable state. In the next video, we will be looking at the methods to prevent metastability using synchronizers and an estimate used by designers to quantify failure rates of a system. Thanks for watching this video and if you gained something from this video, please hit the like button. Subscribe to this channel for more electronics related tutorials.