Memory & FIFOs
Synchronous FIFO Depth Calculator (Counter-Based)
A synchronous FIFO depth calculator using a counter-based approach to track buffer levels with configurable almost-full thresholds.
About this block
Simulate it in the Verilog IDE
Synchronous FIFO Depth Calculator (Counter-Based) is a Verilog reference block in the Memory & FIFOs catalog. SRAM models, FIFOs, register files, and memory-style storage. Marked Medium: more state or a wider datapath, still one workspace in the IDE.
The fifo_depth_calculator module is a lightweight, synchronous digital IP core designed to track the depth of a FIFO buffer without storing the actual data. It maintains an internal 8-bit counter that increments on write enable (wr_en) and decrements on read enable (rd_en).
This module is ideal for:
- Flow Control: Providing
full,empty, andalmost_fullstatus flags to manage data producers and consumers. - Status Monitoring: Exposing the current depth via the
countoutput for debugging or adaptive logic. - Resource Efficiency: Since it does not store data, it consumes minimal FPGA/ASIC resources compared to a full data FIFO.
This IP provides a synchronous FIFO depth calculator using a counter-based approach. It tracks the number of valid items in a buffer without storing the data itself, making it suitable for flow control, status monitoring, and depth-aware logic in digital designs. The module supports configurable almost-full thresholds and provides standard full, empty, and count outputs. It is designed for easy integration, predictable timing, and comprehensive verification.
- Choose Open in IDE. RTL Studio loads the packaged workspace for Synchronous FIFO Depth Calculator (Counter-Based).
- Read the Verilog module in the editor. The catalog line for this block: A synchronous FIFO depth calculator using a counter-based approach to track buffer levels with configurable almost-full thresholds.
- Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
- Run Yosys in the same IDE for a generic netlist. Sky130 liberty mapping is a separate Pro library option.
RTL Studio is the Verilog simulator and IDE around this block: Slang lint, Verilator, VCD waveforms, and Yosys, in the browser. Simulation guide · Yosys guide.
Features
- Synchronous Operation: All state changes occur on the rising edge of
clk. - Asynchronous Reset: Active-low
rst_nresets the depth counter to zero. - Configurable Threshold: An 8-bit input
almost_full_threshallows dynamic adjustment of the "almost full" warning level. - 8-Bit Depth: Supports up to 256 entries (0-255).
- Standard Interface: Provides standard
full,empty, andcountoutputs.
Architecture
The core of the module is a synchronous 8-bit register (cnt). The logic updates cnt based on wr_en and rd_en:
- Write Only (
wr_en=1, rd_en=0): Incrementcntif not full. - Read Only (
wr_en=0, rd_en=1): Decrementcntif not empty. - Both (
wr_en=1, rd_en=1): No change incnt(simultaneous read/write). - Neither: No change in
cnt.
Status flags are derived combinatorially from the current counter value and control signals.
Ports
| Port Name | Direction | Width | Description |
|---|---|---|---|
clk | Input | 1 | Clock input |
rst_n | Input | 1 | Active-low asynchronous reset |
wr_en | Input | 1 | Write enable (increment depth) |
rd_en | Input | 1 | Read enable (decrement depth) |
almost_full_thresh | Input | 8 | Threshold for almost_full flag |
full | Output | 1 | High when FIFO is full and writing |
empty | Output | 1 | High when FIFO is empty |
almost_full | Output | 1 | High when depth >= threshold |
count | Output | 8 | Current FIFO depth (0-255) |
Verification
The IP includes a comprehensive testbench (tb_fifo_depth_calculator.v) that validates:
- Reset Behavior: Counter returns to 0 on
rst_nassertion. - Write Operations: Counter increments correctly on
wr_en. - Read Operations: Counter decrements correctly on
rd_en. - Simultaneous Read/Write: Counter remains unchanged when both are asserted.
- Flag Assertions:
full,empty, andalmost_fullflags are asserted correctly based on counter state.
### Running Simulation
- Ensure you have a Verilog simulator installed (e.g., ModelSim, VCS, or Icarus Verilog).
- Compile the RTL and testbench:
- Run the simulation:
- Check the log for
INFO: PASSto confirm all test cases passed. - View the waveform using the generated
sim/dump.vcdfile.
More in Memory & FIFOs
- 16-Word 16-Bit Sync RAM with Byte Enable — L2 Upgrade
- 16×8 Sync RAM (No Reset, Registered Read) — L2 Upgrade
- 32-Bit Asynchronous FIFO with Gray Pointer Encoding
- 32-Bit Register with Byte Writes
- 32x16 Synchronous Single-Port RAM
- 4x8 1W1R Register File (Comb Read)
- 4×8 Sync RAM (Async Reset, Comb Read)
- 64-bit Wide Scratchpad RAM with Dual-Port Access
- 8-Bit Valid/Ready Skid Buffer
- 8x16 Single-Port Sync RAM
- 8x32 Dual-Read Register File
- 8×8 Sync RAM (Async Reset, Comb Read, Loop Init) — L1 Upgrade
- Asymmetric RAM WR8 RD16 — L2 Upgrade
- Byte-Enable Regfile 8x32 — L2 Upgrade
- CAM 4x8 with Invalidate
- Circular Buffer 16x8