Draft preview. Lessons are being written and reviewed.

Digital Design / Module 7: Memories and FIFOs

42. FIFO depth calculation

Size buffers for bursts.

Lecture coming soon

See it move

The idea

A must absorb the difference between how fast data comes in and how fast it leaves. Too shallow means lost data, and too deep wastes area. The sizing question is common in interviews, and the reasoning is simple: how many words pile up in the worst case?

The basic calculation

During a burst, words arrive at the write rate while some leave at the read rate. Whatever remains is what the FIFO must hold.

depth = burst length - words read during the burst

Worked example

A 100-word burst is written at 100 MHz, and reads run at 50 MHz.

  • The burst lasts 100 words / 100 MHz = 1 µs.
  • In 1 µs, reads remove 50 MHz x 1 µs = 50 words.
  • So the FIFO must hold 100 - 50 = 50 words.

With idle cycles

If the reader takes one word every 4 clocks at 50 MHz, its effective rate is 12.5 MHz, so in 1 µs it removes 12.5 words. Round the words removed down, since a partial word frees no space. That gives 12 words read, and a depth of 100 - 12 = 88 entries.

Add margin

Real designs need more than the ideal number:

  • Reads may start late, so data can pile up before the first read.
  • An async FIFO's flags are delayed by , which reserves a few entries.
  • Pipelined writers may have words in flight after full rises.

When no depth can work

If the average write rate exceeds the read rate forever, the FIFO will eventually overflow, whatever its depth. A FIFO absorbs bursts, but it can't fix a sustained mismatch. That needs , or a faster reader.

Common mistake

Assuming the worst case is a single burst. Find out about back-to-back bursts. Two bursts may arrive with too short a gap for the FIFO to drain between them, which increases the required depth. Ask about this in the interview. Use the lab below to try different bursts and clock rates.

Key ideas

  • Backlog is what's written minus what's read during a burst.
  • Ideal depth = burst length minus the words read while the burst lasts.
  • Add margin for synchronizer latency in async FIFOs.

Lab: FIFO depth lab

Your exercise

A 100-word burst arrives at 100 MHz; reads run at 50 MHz. Find the depth.

Interview questions

coreBurst 100 at 100 MHz, reads at 50 MHz?

basicA writer sends at 100 MHz continuously and the reader takes words at 90 MHz continuously. What FIFO depth do you need?

basicAn 80-word burst is written at 200 MHz, and the reader runs at 120 MHz, one word per cycle. What is the ideal FIFO depth?

coreA 120-word burst arrives at 100 MHz. The reader's clock is 80 MHz, but it takes a word only every second cycle. What depth do you need?

coreA 50-word burst arrives at 100 MHz, and the reader runs at 33 MHz. What depth do you choose, and which way do you round?

coreA 100-word burst arrives at 100 MHz, and the 50 MHz reader starts 200 ns after the burst begins. What depth do you need?

coreYour calculation says a depth of 50 is enough, but a cycle-accurate simulation shows the FIFO peaking at 51 entries. Is the simulation wrong?

advancedTwo 100-word bursts arrive at 100 MHz with a 60-cycle (600 ns) gap between them, and the reader runs at 50 MHz. What depth is needed, and how long must the gap be for one burst's depth to be enough?

advancedA writer at 100 MHz sends 80 words in every 100-cycle frame, placed anywhere in the frame. The reader takes one word every cycle at 80 MHz. What is the ideal depth?

Practise these 9 questions with animations