0
0
Verilogprogramming~5 mins

Latch inference and how to avoid it in Verilog - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is latch inference in Verilog?
Latch inference happens when the synthesis tool creates a latch because some outputs are not assigned in all possible conditions inside a combinational always block.
Click to reveal answer
beginner
Why is latch inference usually undesirable in digital design?
Latches can cause timing problems and unpredictable behavior because they hold their previous value without a clock, making circuits harder to debug and slower to operate.
Click to reveal answer
beginner
How can you avoid latch inference in a combinational always block?
Make sure every output signal is assigned a value in every possible path of the always block, including the else parts of if statements or default assignments at the start.
Click to reveal answer
intermediate
What is a common coding pattern to prevent latch inference?
Assign default values to all outputs at the beginning of the always block, then override them conditionally. This ensures outputs always have a value.
Click to reveal answer
intermediate
Show an example of a latch inferred due to missing else branch.
always @(*) begin if (enable) out = in1; // Missing else: out keeps old value, latch inferred end
Click to reveal answer
What causes latch inference in a combinational always block?
ANot assigning outputs in all possible conditions
BUsing a clock signal
CAssigning outputs only once
DUsing blocking assignments
How can you prevent latch inference?
AUse only non-blocking assignments
BAssign default values to outputs at the start of the always block
CAvoid using if statements
DUse only clocked always blocks
Which of these is a sign that a latch might be inferred?
AUsing non-blocking assignments
BAll outputs are assigned in every branch
CUsing always @(posedge clk)
DAn output is assigned only inside an if without an else
Why are latches generally avoided in synchronous designs?
AThey cause timing uncertainty and glitches
BThey use too much power
CThey are slower than combinational logic
DThey require more code
What is a good practice when writing combinational always blocks?
AAvoid using else statements
BUse only blocking assignments
CAssign default values to outputs at the start
DUse only asynchronous resets
Explain what latch inference is and why it happens in Verilog.
Think about what happens when outputs are not assigned in all cases.
You got /3 concepts.
    Describe how to write Verilog code to avoid latch inference.
    Consider how to make sure outputs always get a value.
    You got /4 concepts.