Friday, May 30, 2008

FIFO Depth Calculation .

Basically we use FIFO for synchronizing two clock domains (different frequencies) so we need a device which has some tolerance power to hold the data that device is called FIFO .By using FIFO we can easily avoid overflow and underflow conditions The scenario can be two of following

  • Writing is faster than reading then there is possibility of overflow
  • Writing is slower than reading then there is possibility of underflow

In FIFO depth calculation we always have to consider worst cast .size of FIFO basically implies that how much data is required to buffer . And it is totally depend on data rate of reading and writing.

Data rate = Number of Data x Time Period
Difference = DRFAST – DRSLOW
Depth = Difference / Higher Freq. Time Period

Writing side is Source and Reading Side is Sink. If the data rate of writing is higher then the reading side’s data rate then the FIFO will now overflow.Another Type of depth calculation can be done by this method:


Consider F1 is writing frequency and F2 is reading frequency (F1>F2) and Data Size is D (Data Words)

Time taken to write to FIFO = DATA/F1
Data Read from the FIFO in the same time = (DATA/F1) xF2
Excess Data is FIFO (Backlog) = DATA-((DATA/F1) x F2
Read side will take more time to read the data so that time is called mop-up time.

Following is the calculation of mop-up time
Mop-up time = Backlog/F2 = DATA-(DATA/F1 F2)
Depth= Wmax – {Wmax x Fread x Wread}

Fwrite x WwriteFwrite = Clock Frequency of Write Clock Domain

Fread = Clock Frequency of Read Clock Domain
Wmax= Maximum number of worlds can be Written
Wwrite = Number of Writes in Per Clock
Wread = Number of reads in Per Clock

Following are some cases of FIFO depth calculation with perfect explanation.

Case: 1
Writing Side = 30 MHz => 33.33 ns Time Period
Reading Side = 40 MHz = > 25.0 ns Time Period

Solution:
Consider the data size is = 10
Data Rate of Writing = 10 x (1/30) =333.33 ns
Data Rate of Reading = 10 x (1/40) =250.0 ns.
Difference between Data Rates = 333.33 – 250.0 = 83.33
Now divide with highest frequency time period = 83.33/25ns = 3.3332 = 4 (Aprox)
Depth of FIFO Should be 4

Case: 2
Writing Side = 80 Data/100 Clock = 100 MHz => 10ns Time Period
Reading Side = 80 Data/80 Clock = 80 MHz => 12.5ns Time Period
No Randomization

Solution:
Data Size is = 80
Data Rate of Writing =80*10=800ns
Data Rate of Reading=80*12.5=1000ns
Difference = 1000-800=200ns
Now divide with highest frequency time period = 200/10ns=20
Depth of FIFO Should be 20


Case: 3
Writing Side = 10 MHz => 100 ns
Reading Side = 2.5 MHz=>400 ns
Word Size = 2
Solution:

Data Rate of Writing =100*2=200ns
Data Rate of Reading=400*2=800ns
Difference = 800-200=600
Now Divide by the lowest frequency time period = 600/400 = 1.5 = 2

(Reading Frequency is slower than writing Frequency )
Case: 4
Writing Data = 80 DATA/100 Clock (Randomization of 20 Data’s)
Outgoing Data= 8 DATA/10 Clock

Solution:
Above shows that the Writing Frequency is equal to reading frequency
20 Data + 80 Valid Data + 80 Valid Data + 20 DataWe will consider worst case

So we will consider 200 Cycles. In 200 Cycle 160 Data is written. it means 160 data continuously written in 160 clock it is the worst case .
At the reading side we will Read 8x16=128 data in 16x10=160 Clock Cycle.
So the Difference between Written Data and Read Back Data is = 160-128=32

FIFO Depth Should be 32

PDF Version of This Concept Can Be Find Here : http://shobhitkapoor.googlepages.com/FIFODepthCalculation.pdf


8 comments:

gblogger said...

ho does 80MHZ for case 2 equal 12ns?? according to my calculation, this should equal 12.5ns

gblogger said...

the 80Mhz = 12ns error makes your case 2 calculation wrong. 80Mhz is 12.5ns, thus ur FIFO depth will be just 2. can u clarify/correct this before someone else gets confused.

sp said...

Dear Shobhit,

In the 3rd case, what is the reason behind dividing the difference(data rate reading - data rate of writing) by the lowest frequency time period ??

Methids in both case 2 and case 3 are confusing. can you plz clarify.

Shekhil Hasssan T said...

My FIFO problem is like this

Data width of FIFO 1 bit.

Input and output data width is also 1 BIT.

Now

at a time 8 locations in FIFO will be written with 50MHz.
and at a time 32 locations in FIFO will be read with 25 MHz.

Now how to calculate depth?

I am not understanding the Data size you have mentioned !? Pls help .

thanks
shekhil@gmail.com

ERROR said...

for 40 Mhz time period is 250 ns.
on depth calculation you written 25ns. how it is possible

RAJESH said...

In 4th case, how it is reading 128 data .
I didn't understand reading calculation.

In 3rd case , why it is dividing with lowest clock frequency .

will u please explain me. I will thankfull to you.

Sushant Mahajan said...

Hi,

I am little confused about the data size.
Suppose for example I am writting 8 bits of data at 30 Mhz and reading 8 bits 40Mhz then what will be the datasize according to your first method,Please help.

Shainky said...

hi,
i have a query on your 1st case.
Your read data freq is greater than your write data freq. We use fifo to store the data which is written but we couldnt read so that we can read it next time. So why would you even need a fifo is this case, because you are anyways reading faster than writing.