⏱️ Delay Controls #
Delay controls simulate time-based or event-driven behavior and are used in testbenches or other non-synthesizable contexts.
🔹 #delay
— Time Delay (simulation only)
#
#10 a = 1; // Wait 10 time units before executing
⛔ Not allowed in synthesizable RTL — Using
#
delays in RTL logic breaks synthesis and must be avoided.
🔹 @event
— Event-Based Control
#
@(posedge clk) q = d; // Wait until rising edge of clk
@(a or b) out = a & b; // Wait until 'a' or 'b' changes
🔹 wait
— Blocking Wait Statement
#
The wait
statement blocks execution until a condition becomes true.
wait (ready == 1); // Wait until 'ready' is asserted
a = data_in; // Then execute assignment
🔹 Combined Example #
always @(posedge clk) begin
wait (ready); // Wait until 'ready' is high
a = temp; // Then assign 'temp' to 'a'
end
repeat
with intra-assignment vs regular delay
#
Syntax | Meaning |
---|---|
a = repeat(3) @(posedge clk) b; |
Captures b immediately, then waits 3 rising edges before assigning to a . |
repeat(3) @(posedge clk); a = b; |
Waits for 3 rising edges, then assigns current value of b to a . |
🎯 Difference: The first captures
b
early, the second usesb
after the delay.