posedge i_clk triggers the block at a rising edge. With neither reset nor enable active, no assignment occurs: the register intentionally retains its value.
Define reset
The first module has synchronous reset: o_data clears at a rising edge with i_reset = 1. Specify polarity, reset type and affected registers in the block contract.
Resetting every register is not always useful. It can add routing, prevent memory inference or complicate timing. Define the starting states required for correct operation.
Asynchronous reset appears in the event list:
always @(posedge i_clk or negedge i_reset_n) begin if (!i_reset_n) o_data <= 8'h00; else o_data <= i_data;end
Assertion acts without waiting for a clock. Arrange deassertion according to technology requirements, usually synchronized in each domain. Choose this pattern for the circuit's needs.
Read previous values with nonblocking assignments
<= evaluates its right side and schedules an update in the simulator's nonblocking region. Following statements therefore do not immediately see the register's new value:
module delay_line ( input wire i_clk, input wire i_reset, input wire i_bit, output reg [2:0] o_history); always @(posedge i_clk) begin if (i_reset) begin o_history <= 3'b000; end else begin o_history[0] <= i_bit; o_history[1] <= o_history[0]; o_history[2] <= o_history[1]; end endendmodule
Each stage receives its predecessor's previous value, forming three flip-flops in series. With =, simulation could propagate a new value through all three statements in one execution.
i_clear precedes i_event: when both are active at an edge, the counter clears. On eight bits, incrementing 8'hFF produces 8'h00. Add saturation or carry handling if wraparound is unwanted.
Keep <= for registers and = for combinational calculations; avoid mixing them on one target. Do not create a clock with a simple logic gate, and handle clock-domain crossings explicitly.