Well, I was asked a very common interview question during my interview at product based MNC focusing on storage equipment development. I was not able to answer during interview so I did extensive research on FIFO depth calculation concept and requirement of necessary depth.
The logic behind FIFO depth calculations very simple. First I will explain it in a non technical way. Suppose there is a person Mr. A and Mr. B. Now Mr. A can throw 10 balls at an instant of time. But Mr. B can catch only 6 balls at the same amount of time. (the phrase written over here "same amount of time" is very important which will help us to calculate FIFO depth). So Mr. B cannot catch remaining 4 balls from Mr. A. So he require a bag of size 4. This is the funda behind the FIFO depth calculation.
In technical terms I will explain like let's
Assume sender as Mr. A
Assume Receiver as Mr. B.
Assume FIFO as a bag.
Sender is writing a data to FIFO and receiver is reading some data from FIFO. If sender writes 10 data in 't' time and receiver reads 6 data in the same 't' time then FIFO size is 10-6=4.
FIFO has two frequency one is sender frequency(fs) and the receiver frequency (fr).
fs=1/Ts;
fr=1/Tr;
Now sender wants to transmit M words of data (let's say a Burst of data). But FIFO can take only n words of data in Ts time.
So the time taken to transmit M words is M/n*Ts.
That is sender wants M/n*Ts time to write M words of data into FIFO.
But our receiver can receive/read 'p' words in Tr time interval. In Tr times receiver can read p words
So in M/n*Ts time how many words can receiver read.
It is (M/n*Ts*p)/Tr words the receiver can read.
Till now what did we do.
We calculated how much time we want to write M words of data into FIFO. In the same amount of time how much data can our FIFO read. so simply subtract the the data read from FIFO to the data written into the FIFO.
Here the data written into the FIFO is M words
Data read from the FIFO is (M/n*Ts*p)/Tr words.
So FIFO depth is = M-(M/n*Ts*p)/Tr
This is equivalent to our example 10 - 6 = 4.
Deduce this u will get
Fifo depth = M ( 1 - fr *p / (n *fs) )
Where
M= Max number of bytes that the sender can send = Burst data
n = No of bytes that the sender sends per clock
fs= sender clock frequency
p= No of bytes that receiver can receive per clock
fr = receiver clock frequency
Let's have an real example.
Write side of FIFO:
Write clock frequency fs = 15 MHz (clk_wr)
Maximum size of the Burst = 100 bytes (burst_width)
Delay between writes in a burst = 1 clock cycle (wr_delay)
Read side of FIFO
Read clock Frequency fr = 10 MHz (clk_read)
Delay between reads = 2 clock cycles (rd_delay)
Step1:- FIFO Width = 8 (1 byte = 8 bits worth of data at each buffer location). @ each clk_wr 1 byte of data will be written in FIFO. so n = 1.
Step2:- Assume maximum size of the burst = 100. so M = 100.
Step3:- No of write clock cycles for writing 100 locations in FIFO = 100 @ clk_wr
Step4:- Time taken to write 100 locations = 100/(15*10^6) = 6.67 us
Step5:- No of reads during 6.67 us = (6.67 us) * 10 * 10^6 = 66.7 @ clk_read (approx 67)
Step6:- No of dead cycles between reads = 2, Means every 2 clk_rd actual number of read will be 1 byte. So every clk_rd , number of read will be 1/2 bytes. so p = 1/2.
So Depth of the FIFO = 100 – 66.7/2 = 100 – 33.35 = 66.65 = 67
Let's put all these values in our derived equation
Fifo depth = M * ( 1 - fr *p / (n *fs) )
Depth of the FIFO = 100 * (1 – 10*(1/2) /(1* 15) )= 100*(1-1/3) = 200/3 = 66.66 = 67
P.S. : - If you still any doubt regarding FIFO depth calculation drop me a mail at akghona_1989@yahoo.com
The logic behind FIFO depth calculations very simple. First I will explain it in a non technical way. Suppose there is a person Mr. A and Mr. B. Now Mr. A can throw 10 balls at an instant of time. But Mr. B can catch only 6 balls at the same amount of time. (the phrase written over here "same amount of time" is very important which will help us to calculate FIFO depth). So Mr. B cannot catch remaining 4 balls from Mr. A. So he require a bag of size 4. This is the funda behind the FIFO depth calculation.
In technical terms I will explain like let's
Assume sender as Mr. A
Assume Receiver as Mr. B.
Assume FIFO as a bag.
Sender is writing a data to FIFO and receiver is reading some data from FIFO. If sender writes 10 data in 't' time and receiver reads 6 data in the same 't' time then FIFO size is 10-6=4.
FIFO has two frequency one is sender frequency(fs) and the receiver frequency (fr).
fs=1/Ts;
fr=1/Tr;
Now sender wants to transmit M words of data (let's say a Burst of data). But FIFO can take only n words of data in Ts time.
So the time taken to transmit M words is M/n*Ts.
That is sender wants M/n*Ts time to write M words of data into FIFO.
But our receiver can receive/read 'p' words in Tr time interval. In Tr times receiver can read p words
So in M/n*Ts time how many words can receiver read.
It is (M/n*Ts*p)/Tr words the receiver can read.
Till now what did we do.
We calculated how much time we want to write M words of data into FIFO. In the same amount of time how much data can our FIFO read. so simply subtract the the data read from FIFO to the data written into the FIFO.
Here the data written into the FIFO is M words
Data read from the FIFO is (M/n*Ts*p)/Tr words.
So FIFO depth is = M-(M/n*Ts*p)/Tr
This is equivalent to our example 10 - 6 = 4.
Deduce this u will get
Fifo depth = M ( 1 - fr *p / (n *fs) )
Where
M= Max number of bytes that the sender can send = Burst data
n = No of bytes that the sender sends per clock
fs= sender clock frequency
p= No of bytes that receiver can receive per clock
fr = receiver clock frequency
Let's have an real example.
Write side of FIFO:
Write clock frequency fs = 15 MHz (clk_wr)
Maximum size of the Burst = 100 bytes (burst_width)
Delay between writes in a burst = 1 clock cycle (wr_delay)
Read side of FIFO
Read clock Frequency fr = 10 MHz (clk_read)
Delay between reads = 2 clock cycles (rd_delay)
Step1:- FIFO Width = 8 (1 byte = 8 bits worth of data at each buffer location). @ each clk_wr 1 byte of data will be written in FIFO. so n = 1.
Step2:- Assume maximum size of the burst = 100. so M = 100.
Step3:- No of write clock cycles for writing 100 locations in FIFO = 100 @ clk_wr
Step4:- Time taken to write 100 locations = 100/(15*10^6) = 6.67 us
Step5:- No of reads during 6.67 us = (6.67 us) * 10 * 10^6 = 66.7 @ clk_read (approx 67)
Step6:- No of dead cycles between reads = 2, Means every 2 clk_rd actual number of read will be 1 byte. So every clk_rd , number of read will be 1/2 bytes. so p = 1/2.
So Depth of the FIFO = 100 – 66.7/2 = 100 – 33.35 = 66.65 = 67
Let's put all these values in our derived equation
Fifo depth = M * ( 1 - fr *p / (n *fs) )
Depth of the FIFO = 100 * (1 – 10*(1/2) /(1* 15) )= 100*(1-1/3) = 200/3 = 66.66 = 67
P.S. : - If you still any doubt regarding FIFO depth calculation drop me a mail at akghona_1989@yahoo.com