FIFO Full Condition Logic
An async FIFO is full when the write pointer has lapped the read pointer exactly once. With Gray-coded pointers, that shows up as a specific pattern in the top two bits.
The module evaluates two Gray code pointers to detect a full condition. A Gray-coded FIFO is full when the write pointer has wrapped exactly once relative to the read pointer. In Gray code, this wrap condition occurs when the top two bits of the write pointer are the exact inverse of the synchronized read pointer's top two bits, while all remaining lower bits match exactly. The evaluated full condition is then registered on the write clock.
The module must include a parameter ADDR_WIDTH with a default value of 4. The pointer widths are ADDR_WIDTH + 1 bits.
- Clock edge:
posedge clk - Reset: Asynchronous active-low
rst_n - Reset behavior:
wfullresets to 0
Worked Trace:
- Cycle 1:
rst_n=0 →wfull=0 - Cycle 2:
rst_n=1,wptr=5'b00000,wq2_rptr=5'b00000. On posedgeclk,wfullevaluates to 0. - Cycle 3:
wptr=5'b00001,wq2_rptr=5'b00000. On posedgeclk,wfullevaluates to 0. - Cycle 4:
wptr=5'b11000,wq2_rptr=5'b00000. On posedgeclk,wfullevaluates to 1 (FIFO full). - Cycle 5:
wptr=5'b11000,wq2_rptr=5'b00001. On posedgeclk,wfullevaluates to 0 (Read occurred).
| Signal | Direction | Width | Description |
|---|---|---|---|
clk |
input | 1 | Positive-edge triggered write clock |
rst_n |
input | 1 | Asynchronous active-low reset; wfull goes to 0 when asserted |
wptr |
input | ADDR_WIDTH+1 |
Write pointer in Gray code |
wq2_rptr |
input | ADDR_WIDTH+1 |
Synchronized read pointer in Gray code |
wfull |
output | 1 | Registered full flag |
Constraints
- The full condition must be registered on the positive edge of
clk. - The pointers must be treated as Gray code sequences, not standard binary.
- The parameter
ADDR_WIDTHmust dictate the bit slicing for the comparison logic; do not hardcode index 4 or 3. - Asynchronous reset must take priority and drive the output to 0 immediately.
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 22 of 36 in the Clock Domain Crossing and Synchronization track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks