+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Junior Member level 1
    Points: 246, Level: 2

    Join Date
    Jun 2018
    Posts
    16
    Helped
    0 / 0
    Points
    246
    Level
    2

    [Verilog] Asynchronous Reset

    Code:
    module  asyn_reset(clk,reset,a,c);
         input clk;
         input reset;
         input a;
         output c; 
    
       wire clk;
       wire reset;   
       wire a;    
       reg c;
            
    always @ (posedge clk or posedge reset)
     if ( reset == 1'b1) begin
       c <= 0;
     end else begin
       c <= a;
     end
    endmodule
    Above is the code from asic world (http://www.asic-world.com/code/tidbits/asyn_reset.v)
    I am confused for the 'always @' and 'if' part about 'reset'.
    Since 'always @' holds the condition when we check the if loop. One of the condition is at the rising edge of reset.
    If only consider reset, when it is at its rising edge, reset might hold the value from 0 to 1 inclusive. Thus, reset might be some value in between 0 and 1, such as 0.3, when reset hasn't reached 1 yet if it rises slowly.
    In this case, reset == 1 condition would fail and reset would fail.

    Could anyone please explain this to me?
    Thank you so much!

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 3
    Points: 7,121, Level: 20
    Achievements:
    7 years registered

    Join Date
    Jul 2010
    Location
    Sweden
    Posts
    939
    Helped
    367 / 367
    Points
    7,121
    Level
    20

    Re: [Verilog] Asynchronous Reset

    Your code will synthesize to logic for an asynchronous reset, no edge detection is involved in the hardware for the reset signal.
    You should view the verilog code as instructions to the simulator about how to simulate an asynchronous reset.
    The simulator will execute the code in the always block when there is a positive edge on clk or reset. In simulation reset is guaranteed to be '1' after a rising edge.
    Remember that both verilog and VHDL were designed to simulate a hardware design. Synthesis came later.
    For an asynchronous reset, it is easier to see the correlation between source code and synthesized hardware with VHDL.



    •   AltAdvertisement

        
       

  3. #3
    Member level 1
    Points: 382, Level: 4

    Join Date
    May 2018
    Posts
    40
    Helped
    3 / 3
    Points
    382
    Level
    4

    Re: [Verilog] Asynchronous Reset

    I will suggest you to take a look at D flip flop internal structure and see how asyn reset factors into output. Coming back to your question, if switching delay of reset from 0 -> 1 is extremely slow in that case actual circuit will not reset until reset is logically 1. Also from simulator perspective, it follows zero delay modelling and hence, it is not an issue for simulators.



    •   AltAdvertisement

        
       

  4. #4
    Junior Member level 1
    Points: 246, Level: 2

    Join Date
    Jun 2018
    Posts
    16
    Helped
    0 / 0
    Points
    246
    Level
    2

    Re: [Verilog] Asynchronous Reset

    Quote Originally Posted by std_match View Post
    Your code will synthesize to logic for an asynchronous reset, no edge detection is involved in the hardware for the reset signal.
    You should view the verilog code as instructions to the simulator about how to simulate an asynchronous reset.
    The simulator will execute the code in the always block when there is a positive edge on clk or reset. In simulation reset is guaranteed to be '1' after a rising edge.
    Remember that both verilog and VHDL were designed to simulate a hardware design. Synthesis came later.
    For an asynchronous reset, it is easier to see the correlation between source code and synthesized hardware with VHDL.
    Thanks for your response.

    Do you mean that during the simulation, 'always @' will compile first and the if loop will compile after that?
    So while the simulator reaches the line 'if (reset == 1'b1)', the 'posedge reset' has been checked and reset has rised up to 1 already.
    Therefore, if I want to reset the circuit and change reset value from 0 to 1, when the compiler reach 'if (reset == 1'b1)', the reset value here is the one after the rising edge, which is 1.

    When you say there is no edge detection involved, do you mean there is no Verilog code for edge detection component? I am wondering why 'always @ posedge' is not edge dection?



  5. #5
    Advanced Member level 5
    Points: 8,339, Level: 21

    Join Date
    Apr 2016
    Posts
    1,755
    Helped
    309 / 309
    Points
    8,339
    Level
    21

    Re: [Verilog] Asynchronous Reset

    Quote Originally Posted by EEPuppyPuppy View Post
    Thanks for your response.

    Do you mean that during the simulation, 'always @' will compile first and the if loop will compile after that?
    So while the simulator reaches the line 'if (reset == 1'b1)', the 'posedge reset' has been checked and reset has rised up to 1 already.
    Therefore, if I want to reset the circuit and change reset value from 0 to 1, when the compiler reach 'if (reset == 1'b1)', the reset value here is the one after the rising edge, which is 1.

    When you say there is no edge detection involved, do you mean there is no Verilog code for edge detection component? I am wondering why 'always @ posedge' is not edge dection?
    forget about interpreting the code line by line like software. verilog is about templates. the way that specific code was written implies an async reset and that is all that matters.
    Really, I am not Sam.



    •   AltAdvertisement

        
       

  6. #6
    Super Moderator
    Points: 257,472, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    44,932
    Helped
    13664 / 13664
    Points
    257,472
    Level
    100

    Re: [Verilog] Asynchronous Reset

    forget about interpreting the code line by line like software. verilog is about templates. the way that specific code was written implies an async reset and that is all that matters.
    Yes, it's the required template for synchronous registers with asynchronous reset, understood by all synthesis tools. Interpreting the code line by line like a simulator shouldn't contradict the synthesis result, but in special cases it does as discussed in previous Edaboard threads, e.g. when having multiple asynchronous inputs.

    https://www.edaboard.com/showthread....DL-and-Verilog
    https://www.edaboard.com/showthread....sensitive-list
    https://www.edaboard.com/showthread....f-Verilog-code

    Referring to the original question, it's useless and misleading to read a behavior into the register template that's neither intended nor supported by the logic hardware. The hardware doesn't perform edge detection for multiple inputs and it doesn't detect other logic levels than 0 and 1.



--[[ ]]--