基础003_V7-Memory Resources
一、綜述
參考ug473.pdf。
常用Memory 資源:
在IP核中,Block memory(distributed memory為CLB中的資源):
通常選用Native,而不用AXI接口:
Block RAM可配置單端口RAM、偽雙端口RAM、雙端口RAM、單端口ROM、雙端口ROM、FIFO。
各個模式調(diào)用時可承受的最高頻率,參考pg058.pdf:
二、主要功能
學(xué)習資源:?http://www.asic-world.com/examples/verilog/memories.html
A-RAM/ROM
主要功能:
每一個Block RAM都可配置為1個36Kb的BRAM或1個36Kb的FIFO;同時也可以將其配置為2個單獨的18Kb的BRAM或1個18KbBRAM + 1個18Kb的BRAM。
為什么是18k而不是16k(2的整次冪)?因為每8bit一個校驗位。2*8 + 2 =18bit。
結(jié)論:無論是單端口RAM、偽雙端口RAM還是雙端口RAM,他們都只有一塊Memory。
Single-port RAM:
同步示例:
module ram_sp_sr_sw ( clk , // Clock Input address , // Address Input data , // Data bi-directional cs , // Chip Select we , // Write Enable/Read Enable oe // Output Enable ); parameter DATA_WIDTH = 8 ; parameter ADDR_WIDTH = 8 ; parameter RAM_DEPTH = 1 << ADDR_WIDTH;//--------------Input Ports----------------------- input clk ; input [ADDR_WIDTH-1:0] address ; input cs ; input we ; input oe ; //--------------Inout Ports----------------------- inout [DATA_WIDTH-1:0] data ;//--------------Internal variables---------------- reg [DATA_WIDTH-1:0] data_out ; reg [DATA_WIDTH-1:0] mem [0:RAM_DEPTH-1]; reg oe_r;//--------------Code Starts Here------------------ // Tri-State Buffer control // output : When we = 0, oe = 1, cs = 1 assign data = (cs && oe && !we) ? data_out : 8'bz; // Memory Write Block // Write Operation : When we = 1, cs = 1 always @ (posedge clk) begin : MEM_WRITEif ( cs && we ) beginmem[address] = data;end end// Memory Read Block // Read Operation : When we = 0, oe = 1, cs = 1 always @ (posedge clk) begin : MEM_READif (cs && !we && oe) begindata_out = mem[address];oe_r = 1;end else beginoe_r = 0;end endendmodule // End of Module ram_sp_sr_sw異步(異步讀、同步寫)示例:
module ram_sp_ar_sw ( clk , // Clock Input address , // Address Input data , // Data bi-directional cs , // Chip Select we , // Write Enable/Read Enable oe // Output Enable ); parameter DATA_WIDTH = 8 ; parameter ADDR_WIDTH = 8 ; parameter RAM_DEPTH = 1 << ADDR_WIDTH;//--------------Input Ports----------------------- input clk ; input [ADDR_WIDTH-1:0] address ; input cs ; input we ; input oe ; //--------------Inout Ports----------------------- inout [DATA_WIDTH-1:0] data ;//--------------Internal variables---------------- reg [DATA_WIDTH-1:0] data_out ; reg [DATA_WIDTH-1:0] mem [0:RAM_DEPTH-1];//--------------Code Starts Here------------------ // Tri-State Buffer control // output : When we = 0, oe = 1, cs = 1 assign data = (cs && oe && !we) ? data_out : 8'bz; // Memory Write Block // Write Operation : When we = 1, cs = 1 always @ (posedge clk) begin : MEM_WRITEif ( cs && we ) beginmem[address] = data;end end// Memory Read Block // Read Operation : When we = 0, oe = 1, cs = 1 always @ (address or cs or we or oe) begin : MEM_READif (cs && !we && oe) begindata_out = mem[address];end endendmodule // End of Module ram_sp_ar_sw對應(yīng)電路:
可以看出2^8 = 256由4個64拼接拼接而成:
這里其實調(diào)用的是CLB中SliceM下的Distributed RAM資源:
B-FIFO
?FIFO的能力:
?FIFO的IP核使用,具體可參考:pg057.pdf。
?FIFO可調(diào)用shift reg、distributed RAM、Block RAM、BulitIn FIFO,關(guān)于使用,xilinx論壇有相關(guān)說法:
Q:
From PG057 (Fifo generator) I understand FIFO's can be implemented in 4 ways, using :?
- block RAM?
- distributed RAM
- shift register
- built-in FIFO? (using FIFO18 / FIFO36)
is there any simple document / app note / overview describing on what basis you typically decide between the?4? implementations. What are the main tradeoffs, advantages, ... of each underlying memory type used?
I can imagine a few, but not sure if these are correct and complete :
- block RAM is interesting for large, deep fifo's
- distributed RAM is interesting for smaller fifo's
- shift register is interesting for smaller fifo's, with short word width
- built-in FIFO allow for the fastest fifo's
but that's just intuition ... so any corrections or further insights are welcome here!
A:
Its based your application , requirement and available resources in your target FPGA. The most of the points you mention correct. I would recommend you to refer target FPGA resource guide LUTs have lowest access time, FIFO18/FIFO36 good timing performance but require effort in design migration, BRAM very good for scalable memory requirement . You can also check about URAM/ultraram available in ultrascale devices
三、IP核調(diào)用
A-simple dual RAM?
?參考IP_bram筆記。
?這里涉及到位寬的計算,以6通道,160MHz采樣率,12bit有效位AD舉例,現(xiàn)在需要轉(zhuǎn)化為:240MHz的FPGA工作時鐘。
12bit*6*160/240 = 48bit
位寬由12*6 = 72bit轉(zhuǎn)化為48bit,:
- Port-A為寫數(shù)據(jù),width:位寬12*6 = 72bit,depth = 160
- Port-B為讀數(shù)據(jù),width:48bit,depth = 240
但Port-B的width只能是:72bit/(2^n),n = 0, ±1, ±2, ...,因此通常都是二次轉(zhuǎn)化:
Step1:72*160 = 48*240 < x * 240,x = 72*2^n >48,此處n = 0;x工作在240MHz。
Step2:x * M = 48 * N,M、N都是整數(shù)。M = 1,N = 2,完成轉(zhuǎn)化。
總結(jié)步驟:160Mhz 72bit轉(zhuǎn)化為 240Mhz 72bit;240Mhz寫1拍(M = 1),每2(N = 2)拍讀取一次數(shù)據(jù)。 IP核調(diào)用格式: 按輸入端口,調(diào)用IP即可 bm_tb bram_int( .addra(addra), ... ) 未勾選primitive output register:勾選primitive output register:
可見該選項延遲了1拍。
B-FIFO
主要參考:
關(guān)于IP核參數(shù)設(shè)置,可參考FIFO generator筆記。
與BRAM同樣的例子,很多時候數(shù)據(jù)時鐘域轉(zhuǎn)換用dual-port RAM而不用FIFO,說是前者含地址,存在時延變量取數(shù)方便,但改為FIFO實現(xiàn)其實也可以,后者含有計數(shù)功能,同樣可以進行定位。
?
從讀使能給出,到數(shù)據(jù)輸出,經(jīng)過6個周期,計算:
?
總結(jié)
以上是生活随笔為你收集整理的基础003_V7-Memory Resources的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 总分类账与明细分类账平行登记的要点不包括
- 下一篇: 融资偿还股票是利好还是利空 利空