Transparent Latch using always_latch
Clock gating cells and specific asynchronous bus protocols rely on level-sensitive latches to hold state during inactive clock phases. While standard synthesis tools flag latches as unintended bugs in combinational logic, hardware engineers must sometimes instantiate them intentionally.
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:
qclears to8'b00000000 - Priority rules:
rst_noverridesen; ifrst_nis low, the output is zero regardless ofenord
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)
{ "signal": [
{ "name": "rst_n", "wave": "011110" },
{ "name": "en", "wave": "x10010" },
{ "name": "d", "wave": "x=====", "data": ["170", "187", "204", "204", "204"] },
{},
{ "name": "q", "wave": "0====0", "data": ["170", "170", "170", "204"] }
], "head": { "text": "Level-sensitive latch behavior with asynchronous 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
qmust be explicitly modeled as a latch using the SystemVerilogalways_latchblock - Reset is asynchronous and active-low
- When
enis low andrst_nis high,qmust hold its previous value - No clock signal is provided; the logic must be entirely level-sensitive
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against a real 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.