FIFO depth
fifo size calculation
The logic is very simple. I will expalin it in a non technical way. Suppose there is a person A and B. Now A can throw 10 mangoes at an instant of time. But B can catch only 6 mangoes at the same amount of time(remember this is very important i.e the phrase same amount of time which i have written above. This will help in calculating the FIFO size). So he cannot catch remaining 4 mangoes from A. So he require a bag of size 4. This is the funda behind the FIFO size/depth calculation.
In technical terms i will explain
Asssume sender as Person A
Assume Receiver as Person 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
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 size is = M-(M/n*Ts*p)/Tr
This is equivalent to our example 10 - 6.
Deduce this u will get
Fifo size= M ( n * fs -  p *fr ) / (n *fs )
Where
M= Max number of bytes that the sender can send
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
FIFO设计中的深度计算
写时钟频率 w_clk,
读时钟频率 r_clk,
写时钟周期里,每B个时钟周期会有A个数据写入FIFO
读时钟周期里,每Y个时钟周期会有X个数据读出FIFO
则,FIFO的最小深度是?
计算公式如下:
fifo_depth = burst_length - burst_length * X/Y * r_clk/w_clk
例举说明:
如果100个写时钟周期可以写入80个数据,10个读时钟可以读出8个数据。令wclk=rclk ,考虑背靠背(20个clk不发数据+80clk发数据+80clk发数据+20个clk不发数据的200个clk)代入公式可计算FIFO的深度
fifo_depth = 160-160X(80%)=160-128=32
如果令wclk=200mhz,改为100个wclk里写入40个,rclk=100mhz,10个rclk里读出8个。那么fifo深度为48
计算如下fifo_depth =80-80X(80%)X(100/200)=80-32=48
注:将 fifo_depth = burst_length - burst_length * (X/Y) * (r_clk/w_clk) 作个变形,得到 fifo_depth = burst_length - (burst_length /w_clk)*[r_clk*(x/y)] 其中(burst_length /w_clk) 表示这个burst的持续时间,r_clk*(x/y)表示读的实际速度。两者的乘积自然就是这段时间读出的数据量。显然burst_length表示这 段时间写入的数据量,两者的差为fifo中残留的数据,这个也就是理论上的fifo的最小深度。实际应用中往往是以半空半满信号来指示fifo的空满状态 的,所以实际设计fifo的时候会至少留下一个数据空间的深度裕量。
浙公网安备 33010602011771号