D Latch
intermediate · sequential · 100 XP
Sign in to write your solution, run it in the simulator and submit it for grading.
Sign in or create a free account →Problem
D Latch
The D (Data) latch fixes the SR latch's forbidden state problem by using a single data input. It is **transparent** when enabled — the output tracks the input directly.
- `en=1`: Q follows D continuously (transparent)
- `en=0`: Q holds its last value (opaque/latched)
**Interface**
| Port | Direction | Description |
|------|-----------|---------------------|
| `d` | input | Data input |
| `en` | input | Level-sensitive enable (active-high) |
| `q` | output | Data output |
| `qn` | output | Complement output |
**Key difference from D Flip-Flop:** The latch responds to the **level** of `en`, not its edge. When `en` goes low, whatever value was on D at that moment is captured.
**Use in RTL:** Latches appear in clock-gating cells and asynchronous interfaces. Unintentional latches (from incomplete if-else) are bugs.
Constraints
- Use always @(*) — level-sensitive, no clock.
- When en=0: q must hold (latch behaviour).
- Declare q and qn as reg.
Examples
Input: en=1, d=1
Output: q=1, qn=0
Transparent — follows D
Input: en=1, d=0
Output: q=0, qn=1
Input: en=0, d=X
Output: q=prev
Latched — holds
Common questions
- What does the D Latch problem ask you to build?
- D Latch The D (Data) latch fixes the SR latch's forbidden state problem by using a single data input. It is **transparent** when enabled — the output tracks the input directly.
- What constraints does D Latch have?
- Use always @(*) — level-sensitive, no clock.; When en=0: q must hold (latch behaviour).; Declare q and qn as reg.
- What is an example input and output for D Latch?
- Input en=1, d=1 gives output q=1, qn=0. Transparent — follows D
- Which Verilog concepts does D Latch practise?
- sequential, latch, level-sensitive, enable.