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?
✗ Incorrect
Latch inference happens when outputs are not assigned in every possible condition, causing the tool to create a latch to hold the previous value.
How can you prevent latch inference?
✗ Incorrect
Assigning default values ensures outputs always have a value, preventing latches from being inferred.
Which of these is a sign that a latch might be inferred?
✗ Incorrect
If an output is assigned only in an if branch and not in else, the tool infers a latch to hold the previous value.
Why are latches generally avoided in synchronous designs?
✗ Incorrect
Latches can cause timing uncertainty and glitches because they are level-sensitive and hold values without a clock edge.
What is a good practice when writing combinational always blocks?
✗ Incorrect
Assigning default values at the start of the block ensures outputs are always assigned, preventing latch inference.
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.