What are posedge and negedge in Verilog?

In Verilog, posedge and negedge are keywords used within always blocks to specify the edge-triggered events that should trigger the execution of the block's statements.

  • posedge:

    • Indicates the rising edge of a signal.
    • The always block will execute only when the specified signal transitions from 0 to 1.
  • negedge:

    • Indicates the falling edge of a signal.
    • The always block will execute only when the specified signal transitions from 1 to 0.

Example :

always @ (posedge clk) begin
  // Code to be executed on the rising edge of the clock signal
end

always @ (negedge rst_n) begin
  // Code to be executed on the falling edge of the reset signal
end

 

Key Points :

  • posedge and negedge are crucial for designing synchronous circuits where events are triggered by specific transitions of a clock signal.
  • They are used in conjunction with always blocks to create flip-flops, registers, and other sequential logic elements.
  • The choice between posedge and negedge depends on the specific requirements of your design and the desired behavior of the circuit.

By understanding the use of posedge and negedge, you can effectively model and design digital circuits with precise timing and synchronization in Verilog.