Today, while studying the asynchronous FIFO read and write clock synchronization in FPGA, I noticed an issue: when connecting two different clocks, it is challenging to achieve complete synchronization. As a result, at a certain moment, the edge of the high-precision clock may appear in the middle of the edge of the low-precision clock, leading to the inability to meet Tsu and Thold. This is a point worth noting, as shown in the figure below:
It can be seen that when the edge of CLK cannot meet Tsu or Tco, a metastable state will occur. The output of the flip-flop will remain in an uncertain state for a period of time, which is neither a high level “1” nor a low level “0”, or it may oscillate.Undoubtedly, if in communication, our master and slave devices mostly use different clocks, failing to minimize the impact of metastability can lead to communication errors or even crashes.Common methods include:Synchronizer method, oversampling, and replacing with higher precision devices.Here, I will introduce the synchronizer method:This is the most commonly used and fundamental method. The signal from the asynchronous domain (the sender) is passed through two (or more) cascaded flip-flops. The first flip-flop has a probability of entering a metastable state, but it is given a complete clock cycle to stabilize. The probability that the signal resampled by the second flip-flop is stable is greatly increased. The downside is that this method uses more resources.If two flip-flops are cascaded, the waveform is as follows:
As shown in the figure, rx_reg0 is the first-level register in RX,and rx_reg0 is followed by another flip-flop. Therefore, when the oscillation time of the first-level register is long, the second-level register will capture the metastable state, but the signal output from the second-level register will be relatively stable.However, it is important to note: while this can capture a stable value, this stable value is independent of the input, making it impossible to determine the specific level state.It has been verified that the first-level register can achieve 70% stability, while the second level can reach 99%. Further improvements yield diminishing returns.