名稱:通用FIFO存儲(chǔ)器設(shè)計(jì)1024*8bit(代碼在文末付費(fèi)下載)
軟件:Quartus
語(yǔ)言:Verilog
代碼功能:
本代碼為FIFO通用代碼,其他深度和位寬可簡(jiǎn)單修改以下參數(shù)得到
reg?[7:0]?ram?[1023:0];//RAM。深度1024,寬度8
設(shè)計(jì)一個(gè)基于FPGA的FIFO存儲(chǔ)器,使之能提供以下功能:
1.存儲(chǔ)空間至少1024 儲(chǔ)器。
2.存儲(chǔ)位寬8bit。
3.拓展功能:存儲(chǔ)器空、滿報(bào)警。
演示視頻:
FPGA代碼資源下載網(wǎng):hdlcode.com
部分代碼展示
//fifo?1024*8bit?fifo //存儲(chǔ)空間1024 //位寬8bit module?a_fifo ( input?clk,//時(shí)鐘 input?rst,//復(fù)位 input?[7:0]?din,//fifo寫數(shù)據(jù) input?wr_en,//寫使能 input?rd_en,//讀使能 output?reg?[7:0]?dout,//讀數(shù)據(jù) output?empty,//空信號(hào) output?full//滿信號(hào) ); reg?[7:0]?ram?[1023:0];//RAM。深度1024,寬度8 reg?[11:0]?count=12'd0; reg?[11:0]?rp=12'd0; reg?[11:0]?wp=12'd0; integer?i; always@(posedge?clk) if(rst)begin//復(fù)位 wp<=12'd0; rp<=12'd0; dout<=8'd0; count<=12'd0; for(i=0;i<1024;i=i+1) ram[i]<=8'b00000000;//清零 end else case({rd_en,wr_en}) 2'b00:count<=count; 2'b01://單寫FIFO if(~full)begin//未滿 ram[wp]<=din;//存入fifo if(wp>=12'd1023) wp<=12'd0;//寫地址循環(huán)累加 else wp<=wp+12'd1; count<=count+12'd1; rp<=rp; end 2'b10://單讀FIFO if(~empty)begin//未空 dout<=ram[rp];//讀fifo if(rp>=12'd1023) rp<=12'd0;//讀地址循環(huán)累加 else rp<=rp+12'd1; count<=count-12'd1; end 2'b11://同時(shí)讀寫FIFO if(empty)begin//FIFO為空,只能寫
設(shè)計(jì)文檔:
1. 工程文件
2. 程序文件
3. 程序編譯
4. Testebnch
5. 仿真圖
仿真圖依次仿真了如下功能:
具體功能1/2/3對(duì)應(yīng)如下:
1:寫FIFO 20次,再讀20次,F(xiàn)IFO讀空
1. 寫FIFO 10次,然后同時(shí)讀寫20次,最后讀10次,F(xiàn)IFO讀空
2. 連續(xù)寫FIFO 2048次,F(xiàn)IFO寫滿