Search code examples
veriloghardwareflip-floptiming-diagram

Why do verilog tutorials commonly make reset asynchronous?


This question is in the context of FPGA synthesis if that makes any difference. The data sheet (iCE40UP) states that each logic cell has a D-type flop with asynchronous reset and clock enable inputs.

Many verilog tutorials introduce sequential logic with something like:

always @(posedge clk)
  begin
    some_reg <= [...]
  end

I'm familiar with clocked logic and this makes intuitive sense to me.

Then the very next concepts introduced are usually:

  • Be careful to not accidentally create a latch because what you really need is a proper register.
  • always @(posedge clk or [pos|neg]edge reset)
  • always @(*)

In Wikipedia I read scary statements like "if the system has a dependence on any continuous inputs then these are likely to be vulnerable to metastable states. [...] If the inputs to an arbiter or flip-flop arrive almost simultaneously, the circuit most likely will traverse a point of metastability."

At the risk of having my question closed for being poorly-formed ... what am I missing?

  • Is asynchronous reset recommended design practice? What is gained by not treating reset like any other input and having it take effect on the next cycle? Documentation for real chips usually requires that the RST* pin is held low for many clock cycles.

  • Does having a latch in the design make it asynchronous? How do we ensure proper timing is observed in the presence of a latch driven by something outside the clock domain?

  • When would anyone ever actually want a latch in a clocked design? Why does verilog make it so easy to create one accidentally?

Thanks!

Seemingly related questions: - Verilog D-Flip-Flop not re-latching after asynchronous reset - What if I used Asynchronous reset, Should I have to make as synchronous turned it?


Solution

  • Synchronous vs. asynchronous reset has some similarities to the big endian vs. little endian battle for CPUs. In many cases, both types work equally well. But there are cases when either type has an advantage over the other. At situations like powerup or powerdown you may not have a valid clock, but you still need the reset to work to put your system in a known passive state, and avoid dangerous I/O glitches. Only asynchronous reset can do that.

    If your design contains registers which lack reset capability, such as RAM blocks, then using asynchronous reset on the registers feeding adr, data and control signals to the RAM can cause corruption of the RAM content when a reset occurs. So if you need the ability to do a warm reset where RAM content must be preserved: Use synchronous warm reset for the logic closest to the RAM.

    Altera and Xilinx are adding to the confusion by recommending their customers to only use synchronous reset. Using only synchronous reset can work well on Altera and Xilinx, since both are SRAM based FPGA architectures, so powerup glitches are never a concern.

    But if you want to make your design portable to other architectures, such as ASICs or flash FPGAs, then asynchronous reset may be the better default choice.

    Regarding your question about metastability caused by asynchronous reset. That is correct. A fully asynchronous reset signal can cause metastability. That is why you must always synchronize the rising edge of a active low asynchronous reset signal. Only the falling edge of the reset can be fully asynchronous.

    Synchronizing only the rising edge is done by two flip-flops.

    Latches: No, you almost never want latches in a clocked design. Good practice is to let the DRC trigger an error in case a latch is found.