FPGA DEVICES · ENGINEERING · SOURCING Source-linked information. Clear project requirements.

Tutorials

Verilog Inferred Latches: Find the Missing Assignment and Verify the Fix

Published · Updated

A combinational block that leaves an output unassigned on one branch asks that output to keep its previous value. That retained state is the clue to an inferred latch. Find the missing assignment first, then verify that the corrected behavior is actually the behavior the interface needs.

Make the retained value visible

Missing assignment retains the previous valueMissing assignment retains theprevious valueendlatch qfixed q
Logical sequence exercised by tb_latch.v: the incomplete block retains 1 while disabled; the fixed block returns 0. Horizontal spacing is illustrative.
always @* begin
  if (en) q = d;
end

When en is high, q follows d. When en is low, the block makes no assignment to q, so q retains a previous value. Adding always_comb changes the language construct and may improve diagnostics, but it does not supply the missing assignment. If storage was unintended, every combinational output needs a defined value on every path.

In the downloadable counterexample, the test sets en=1 and d=1, then sets en=0 and d=0. The incomplete block retains q=1. The corrected combinational block produces q=0. This is a small observation that makes the semantic difference visible without a large application around it.

For a case statement, inspect the default branch and every output assigned by the block. A default for one output does not cover another. Partial vector assignments can leave only some bits retaining state. Also inspect early conditional paths and assignments nested under enables.

Choose a default that matches the contract

always @* begin
  q = 1'b0;
  if (en) q = d;
end

The default zero is correct only if q must be zero when disabled. It is not a cosmetic fix for a warning. If the design needs q to retain state across clock cycles, express that behavior in an appropriate clocked process instead. If it intentionally needs a level-sensitive latch, describe and constrain that architecture deliberately.

Mojo v3 development board. The published latch results come from software simulation and generic synthesis, not a board measurement.
Mojo v3 development board. The published latch results come from software simulation and generic synthesis, not a board measurement. Photo: SparkFun Electronics from Boulder, USA. Original image, CC BY 2.0.

The Mojo v3 photograph shows a physical FPGA development board. It is not the hardware used to run this example: the behavior here was checked in simulation, and the structure was inspected in generic synthesis. The lesson concerns RTL semantics rather than a claim about that board’s timing or tool support.

A state-machine next-state block often starts from a deliberate default such as next_state = state, while its output defaults follow the protocol. That does not justify q = q as a universal combinational default; self-retention preserves the storage behavior you were trying to remove.

Keep reset logic in the intended sequential state elements and review it with the reset-release guide. A reset branch added to an otherwise incomplete combinational block is not a replacement for full assignment coverage.

Check behavior and structure after the fix

Observed generic synthesis differenceObserved generic synthesis difference01latch_bad: $dlatch present02latch_fixed: no $dlatch
Executed Yosys generic synthesis observation for the supplied modules. No Vivado implementation or board result is implied.

The supplied latch test passed with Icarus Verilog from OSS CAD Suite 2026-11-15. Yosys processing of the two tiny modules produced a $dlatch cell for latch_bad and no $dlatch cell for latch_fixed. The download includes the source and commands so you can repeat both checks. These are generic synthesis results, not a Vivado implementation report.

iverilog -g2012 -s tb_latch -o latch.vvp latch_bad.v latch_fixed.v tb_latch.v
vvp latch.vvp
yosys -p "read_verilog latch_bad.v; proc; opt; stat"
yosys -p "read_verilog latch_fixed.v; proc; opt; stat"

In the production tool, inspect the inferred primitives and warnings again after integrating the fix. Then rerun functional tests that cover enabled and disabled behavior. Removing a latch while changing the protocol is a regression, even if synthesis is quieter.

Use the branch worksheet to list outputs and assignment coverage; it does not parse arbitrary RTL or prove that a pasted block is latch-free. The counter testbench gives a larger example of checking behavior around disabled and reset conditions.

Once the RTL behavior is correct, review timing coverage and any remaining timing failures in the actual Vivado project.

Combinational assignment coverage checklist

Inputs and exported records stay in this browser. The check evaluates the assumptions you enter; it does not inspect your project files.

Use the worked values and equations above, or download the examples below. The interactive check requires JavaScript.

Watch the short disabled branch: retained q versus default q sequence

The sequence visualizes the stated example. It is not a hardware capture. The static figures and text above contain the same explanation.

Disabled branch: retained q versus default q

Download both RTL versions and the testbench; include the unexpected synthesized cell and failing input sequence in a review.

Download the timing and RTL examples (ZIP) · Discuss this engineering task

The ZIP includes the clock and I/O examples, timing-audit commands, counter/latch/reset RTL and testbenches. Bring the relevant exported record to the enquiry; this page does not submit it automatically.

References and example scope

Documentation checked 16 November 2026. AMD examples use the cited 2024.1 documentation baseline. Vivado commands and vendor macros were not executed for this article. Counter, latch and illustrative reset tests were executed with Icarus Verilog; latch structure was checked with Yosys. See the included commands and validation record for the exact scope.

Back to Tutorials →

Related evidence and next tasks

Continue the task with the relevant source scope. These reading paths do not establish interchangeability or current supply.

Source addresses and citation trail

Full source addresses are retained below. Read each citation with its document revision, page, table and applicability conditions above.

  1. https://commons.wikimedia.org/wiki/File:Mojo_v3_FPGA_Development_Board_(9303578174).jpg
  2. https://creativecommons.org/licenses/by/2.0
  3. https://docs.amd.com/r/2024.1-English/ug901-vivado-synthesis/Always-Procedures
  4. https://github.com/steveicarus/iverilog
  5. https://yosyshq.readthedocs.io/projects/yosys/en/latest/