FIFO Empty Condition Logic
An async FIFO is empty when the read pointer has caught up with the synchronized write pointer. The read side must not pop past that point.
The module maintains an internal 4-bit binary read pointer and outputs a 4-bit Gray-coded read pointer. When a read is requested (rinc is 1) and the FIFO is not empty, the internal binary pointer increments. The next Gray pointer is calculated from this next binary value. The FIFO is considered empty when the next Gray read pointer exactly matches the synchronized Gray write pointer (wq2_wptr).
The module is driven by the read clock (rclk) on the positive edge. An asynchronous active-low reset (rrst_n) initializes the internal binary pointer and the output Gray pointer (rptr) to 0, and asserts the empty flag (rempty to 1). Read requests must be ignored if rempty is currently 1.
Cycle-by-cycle execution trace:
- Cycle 1:
rrst_n=0 →rptr=0,rempty=1 - Cycle 2:
rrst_n=1,rinc=1,wq2_wptr=0 →rptr=0,rempty=1 (read ignored because empty) - Cycle 3:
rinc=0,wq2_wptr=1 →rptr=0,rempty=0 (write syncs in, FIFO no longer empty) - Cycle 4:
rinc=1,wq2_wptr=1 →rptr=1,rempty=1 (read executes, FIFO empty again) - Cycle 5:
rinc=0,wq2_wptr=1 →rptr=1,rempty=1 (hold state)
| Signal | Direction | Width | Description |
|---|---|---|---|
rclk |
input | 1 | Positive-edge triggered read domain clock |
rrst_n |
input | 1 | Asynchronous active-low reset |
rinc |
input | 1 | Read request enable |
wq2_wptr |
input | 4 | Synchronized write pointer in Gray code |
rempty |
output | 1 | Registered empty flag; 1 when FIFO is empty |
rptr |
output | 4 | Registered Gray-coded read pointer |
Constraints
- The design must use
posedge rclkfor synchronous logic andnegedge rrst_nfor asynchronous resets. - On reset,
remptymust be 1 andrptrmust be 4'b0000. - If
remptyis 1, any assertion ofrincmust be ignored (the internal pointer must not increment). - The
remptyflag must be evaluated combinationally using the next Gray read pointer, but the outputremptyitself must be a registered signal updated onposedge rclk. - Both
remptyandrptrmust be registered outputs.
Topics
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 Clock Domain Crossing and Synchronization
Problem 23 of 36 in the Clock Domain Crossing and Synchronization track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks