Codiode

Transparent Latch using always_latch

MediumVerilog / SystemVerilogBuild

Latches are usually a bug, but clock gating cells and some bus interfaces need one on purpose. always_latch tells the tools the latch is intended.

The module acts as an 8-bit transparent D-latch with an asynchronous active-low reset. When the reset is asserted, the output clears to zero immediately. During normal operation, when the enable signal is high, the output transparently follows the data input. When the enable signal transitions low, the output holds the last observed data value regardless of subsequent changes on the data input.

Timing and Reset Rules:

  • Trigger: Level-sensitive; no clock edge is used
  • Reset type: Asynchronous
  • Reset polarity: Active-low
  • Output values on reset: q clears to 8'b00000000
  • Priority rules: rst_n overrides en; if rst_n is low, the output is zero regardless of en or d

Worked Trace:

Step 1: rst_n=0, en=X, d=X → q=0 (Reset)
Step 2: rst_n=1, en=1, d=170 → q=170 (Transparent)
Step 3: rst_n=1, en=0, d=187 → q=170 (Hold)
Step 4: rst_n=1, en=0, d=204 → q=170 (Hold)
Step 5: rst_n=1, en=1, d=204 → q=204 (Transparent)
Step 6: rst_n=0, en=0, d=204 → q=0 (Async Reset)

Port Table:

Signal Direction Width Description
d input 8 Data input
en input 1 Active-high latch enable
rst_n input 1 Asynchronous active-low reset; clears q to 0 when asserted
q output 8 Latch output; resets to 8'b00000000

Constraints

  • Output q must be explicitly modeled as a latch using the SystemVerilog always_latch block
  • Reset is asynchronous and active-low
  • When en is low and rst_n is high, q must hold its previous value
  • No clock signal is provided; the logic must be entirely level-sensitive

Topics

SequentialLatchSystemVerilog

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Part of Sequential RTL

Problem 22 of 26 in the Sequential RTL track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.