FIFO设计中的深度计算 您所在的位置:网站首页 fifo最小深度计算 FIFO设计中的深度计算

FIFO设计中的深度计算

2024-02-01 16:57| 来源: 网络整理| 查看: 265

 http://www.asic-world.com/tidbits/index.html

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的时候会至少留下一个数据空间的深度裕量。

、、、

 

 

 

One of the most common questions in interviews is how to calculate the depth of a FIFO. Fifo is used as buffering element or queueing element in the system, which is by common sense is required only when you slow at reading than the write operation. So size of the FIFO basically implies the amount of data required to buffer, which depends upon data rate at which data is written and the data rate at which data is read. Statistically, Data rate varies in the system majorily depending upon the load in the system. So to obtain safer FIFO size we need to consider the worst case scenario for the data transfer across the FIFO under consideration.    For worst case scenario, Difference between the data rate between write and read should be maximum. Hence, for write operation maximum data rate should be considered and for read operation minimum data rate should be considered.     So in the question itself, data rate of read operation is specified by the number of idle cycles and for write operation, maximum data rate should be considered with no idle cycle.     So for write operation, we need to know Data rate = Number of data * rate of clock. Writing side is the source and reading side becomes sink, data rate of reading side depends upon the writing side data rate and its own reading rate which is Frd/Idle_cycle_rd.     In order to know the data rate of write operation, we need to know Number of data in a Burst which we have assumed to be B.     So following up with the equation as explained below: Fifo size = Size to be buffered = B - B * Frd / (Fwr* Idle_cycle _rd ).     Here we have not considered the sychnronizing latency if Write and Read clocks are Asynchronous. Greater the Synchronizing latency, higher the FIFO size requirement to buffer more additional data written.      

Example : FIFO Depth Calculation      Assume that we have to design a FIFO with following requirements and We want to calculate minumum FIFO depth,     A synchronized fifo Writing clock 30MHz - F1 Reading clock 40MHz - F2 Writing Burst Size - B Case 1 : There is 1 idle clock cycle for reading side - I Case 2 : There is 10 idle clock cycle for reading side - I      FIFO depth calculation = B - B *F2/(F1*I)     If if we have alternate read cycles i.e between two read cycle there is IDLE cycle. FIFO depth calculation = B - B * F2/(F1*2)     In our present problem FIFO depth = B - B *40/(30*2)= B(1-2/3)= B/3     That means if our Burst amount of data is 10 , FIFODEPTH = 10/3 = 3.333 = 4 (approximatly)

If B = 20 FIFO depth = 20/3 = 6.6 = 7or 8 (clocks are asynchronous)     If B = 30 FIFO depth = 30/3 = 1010+1 = 11 (clocks are asynchronous)

If 10 IDLE cycles betweeen two read cycles .FIFO DEPTH = B - B *F2/(F1*10) .= B(1-4/30)= B * 26 /30 

 

前几天发了没有人回,在:别的论坛上看到的这个贴子,觉得有点问题,大家来讨论一下:

写时钟周期w_clk,读时钟周期r_clk,写时钟周期里,每B个时钟周期会有A个数据写入FIFO读时钟周期里,每Y个时钟周期会有X个数据读出FIFO则,FIFO的最小深度是?

首先,这道题不一定有解有解的必要条件是在一定时间内(足够长),写入的数据数量一定要等于读出的数据数量因此有:A/B * w_clk = X/Y * r_clk

其次,算出写数据的最大burst_length。考虑最坏情况比如,如果条件给出,每100个写时钟,写入80个数据,那么在背靠背的情况下,burst_length = 2*80=160

最后,fifo_depth = burst_length - burst_length * X/Y * r_clk/w_clk

BTW:通常,为了安全起见,都会多留一些depth的余度 个人觉得,公式应该是这样:A/(B * w_clk) = X/(Y * r_clk)

fifo_depth = burst_length - burst_length * X/Y * w_clk /r_clk

举例说明:如果100个写时钟周期可以写入80个数据,10个读时钟可以读出8个数据其中w_ck=5ns,r_ck=10ns

如果按照之前的公式,得出的深度为:fifo_depth = burst_length - burst_length * X/Y * r_ck/w_clk=160-160*8/10*2=-94,显然是不对的

实际上,考虑背靠背(20个clk不发数据+80clk发数据+80clk发数据+20个clk不发数据的200个clk)

这样在中间160个写时钟周期连续写的情况下,只能读出160*5/(10*10)*8=64个数据,所以FIFO的深度应该为160-64=96也就是fifo_depth = burst_length - burst_length * X/Y * w_clk /r_clk=160-160*8/10*5/10=96

大家可以讨论一下,加深对这个问题的认识。 原帖由 windzjy 于 2007-1-14 17:18 发表个人觉得,公式应该是这样:A/(B * w_clk) = X/(Y * r_clk)

fifo_depth = burst_length - burst_length * X/Y * w_clk /r_clk

举例说明:如果100个写时钟周期可以写入80个数据,10个读时钟可以读出 ... 我以前看到过这个公式,是用来计算同步fifo的。

你所举的那个例子, 如果呼入fifo的数据宽度和呼出相同的话,都设为w bit。那么呼如fifo的带宽就是200wbps,呼出fifo的带宽是100wbps。考虑链路利用率都是80%。那么呼入fifo的有效带宽是160wbps。呼出fifo的带宽是80wbps。现在看到矛盾了,由于输入输出带宽不相等,进来永远比出去多,那么FIFO总是处于不断积累数据的状态。所以lz所举的这个例子并不合适。应该提高读时钟的速率,使fifo两端的带宽匹配,在这个前提下才能计算出有解的fifo深度。

如果令wclk=rclk (以下内容中的clk表示时钟的频率,不是周期)。可使得读写带宽匹配。那么这个例子的答案是32原因如下: 考虑背靠背的情况,160个wclk连续都写入了160个数据。而这160个wclk时间内,由于wclk=rclk,那么读出了(16/10 )×8=128个数据。有32个数据会被留在fifo里。那么fifo的最小深度就是32。

如果令wclk=200mhz,改为100个wclk里写入40个,rclk=100mhz,10个rclk里读出8个。那么fifo深度为48续上:讲数据带入公式 fifo_depth = burst_length - burst_length * X/Y * r_clk/w_clk正好也是也是这个结果。所以我觉得公式是对的。其实 A/B * w_clk = X/Y * r_clk 即 (A/B)*W_CLK=(X/Y)*R_CLK所表达的含义就是 fifo的输入和输出带宽要匹配,其中A/B表示链路利用率,w_clk×width表示带宽,这里大概是默认输入输出的数据宽度相同,所以以wclk来代替带宽。 X/Y 和 r_clk 的含义也是这样:) 。在带宽匹配的前提下数据不会无限积累。

fifo_depth = burst_length - burst_length * (X/Y) * (r_clk/w_clk)公式是对的 续上: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的时候会至少留下一个数据空间的深度裕量。 仔细看了一下发现自己的问题:1,贴子中写时钟周期w_clk和读时钟周期r_clk并不是指的周期,而是指的频率2,我举例不当,因该是wice3所说的那样,100个CLOCK写40个数据,这样在100个周期内     写入的数据数量和读出的数据数量就一致了,不会造成溢出。

总结:1,原公式还是对的,只是w_clk和r_clk意义描述的容易让人误解2,又加深了对fifo的理解

有什么问题大家可以继续讨论。

 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有