An always block sensitivity list tells Verilog when to run the code inside an always block. It helps the circuit react to changes in signals.
Always block sensitivity list in Verilog
always @(sensitivity_list) begin
// statements
endThe sensitivity_list can include signals or edges like posedge clk or negedge reset.
If you want to model combinational logic, include all input signals in the sensitivity list.
a, b, or c changes. It models combinational AND logic.always @(a or b or c) begin y = a & b & c; end
clk. It models a flip-flop storing d.always @(posedge clk) begin
q <= d;
endalways @(posedge clk or negedge reset) begin if (!reset) q <= 0; else q <= d; end
@(*) means "all inputs used inside". It automatically includes all signals read inside the block.always @(*) begin
y = a | b;
endThis example shows an always block sensitive to a and b. It updates y whenever a or b changes, modeling an AND gate.
module simple_and(
input wire a,
input wire b,
output reg y
);
always @(a or b) begin
y = a & b;
end
endmodule
// Testbench
module testbench;
reg a;
reg b;
wire y;
simple_and uut(.a(a), .b(b), .y(y));
initial begin
a = 0; b = 0;
#10 a = 1;
#10 b = 1;
#10 a = 0;
#10 b = 0;
#10 $finish;
end
initial begin
$monitor($time, ": a=%b b=%b y=%b", a, b, y);
end
endmoduleTime complexity: The always block runs only when signals in the sensitivity list change, making simulation efficient.
Space complexity: Minimal, just stores the signals and output.
Common mistake: Forgetting to include all input signals in the sensitivity list for combinational logic can cause simulation mismatches.
Use @(*) for combinational logic to avoid missing signals in the sensitivity list.
The always block sensitivity list controls when the block runs.
Use signal names or edges like posedge in the list.
Use @(*) to automatically include all inputs for combinational logic.
Practice
always block control?Solution
Step 1: Understand the role of sensitivity list
The sensitivity list specifies which signals trigger thealwaysblock to run when they change.Step 2: Differentiate from unrelated concepts
Data types, clock frequency, and synthesis optimization are unrelated to sensitivity lists.Final Answer:
When thealwaysblock executes based on signal changes -> Option CQuick Check:
Sensitivity list controls execution timing [OK]
- Confusing sensitivity list with clock frequency
- Thinking it controls variable types
- Assuming it affects synthesis optimization
always block sensitivity list that triggers on the positive edge of clock clk and any change in reset rst?Solution
Step 1: Recall correct sensitivity list syntax
The correct syntax usesposedge clkandorto separate signals:always @(posedge clk or rst).Step 2: Identify incorrect syntax in other options
A usesandinstead ofor, B uses wrong orderclk posedge, D uses comma which is invalid.Final Answer:
always @(posedge clk or rst) -> Option BQuick Check:
Use 'or' to separate signals in sensitivity list [OK]
- Using 'and' instead of 'or' in sensitivity list
- Placing 'posedge' after signal name
- Separating signals with commas
reg q;
always @(posedge clk or posedge rst) begin
if (rst)
q <= 0;
else
q <= d;
endWhat happens to
q when rst goes high?Solution
Step 1: Analyze sensitivity list triggers
The block triggers on positive edge ofclkorrst. Whenrstgoes high, the block runs immediately.Step 2: Check the if condition inside the block
Ifrstis high,qis assigned 0, resetting it.Final Answer:
qis set to 0 immediately -> Option AQuick Check:
Reset high sets q to 0 [OK]
- Assuming q holds value on reset
- Thinking q updates only on clock edge
- Confusing reset with data input
always @(clk or rst) begin
if (rst)
q <= 0;
else if (posedge clk)
q <= d;
endSolution
Step 1: Check sensitivity list correctness
The sensitivity list usesclkandrstwithout edges, so it triggers on any change.Step 2: Identify improper use of
You cannot useposedge clkinside blockposedge clkas a condition inside the block; it must be in sensitivity list.Final Answer:
Usingposedge clkinside the block instead of sensitivity list -> Option DQuick Check:
Edge triggers belong in sensitivity list [OK]
- Placing edge conditions inside always block
- Ignoring sensitivity list edges
- Confusing blocking and nonblocking assignments
y whenever any input signal a, b, or c changes. Which sensitivity list is best practice to ensure correct behavior?Solution
Step 1: Understand combinational logic sensitivity
For combinational logic, sensitivity list should include all inputs to avoid simulation mismatches.Step 2: Use
@(*)for automatic sensitivity@(*)automatically includes all signals read inside the block, ensuring correctness and easier maintenance.Final Answer:
always @(*) -> Option AQuick Check:
Use @(*) for combinational logic sensitivity [OK]
- Listing signals manually and missing some
- Using edge triggers for combinational logic
- Using 'and' instead of 'or' in sensitivity list
Ready to prove it?
Pass the test and this pattern moves unknown
