Xilinx ISE FIFO讀寫操作仿真學習


---恢復內容開始---

  針對xilinx FIFO IP核進行簡單的學習,整個流程參考http://www.eefocus.com/guoke1993102/blog/15-06/313183_36284.html,仿真工具使用modelsim.

  FIFO ip核設置參照鏈接設置,本文不再貼圖,其中部分設置更改如下:

 

之后開始編寫程序,程序代碼如下:

  1 `timescale 1ns / 1ps
  2 //////////////////////////////////////////////////////////////////////////////////
  3 // Company: 
  4 // Engineer: 
  5 // 
  6 // Create Date:    19:34:55 11/14/2016 
  7 // Design Name: 
  8 // Module Name:    FIFO_test 
  9 // Project Name: 
 10 // Target Devices: 
 11 // Tool versions: 
 12 // Description: 
 13 //
 14 // Dependencies: 
 15 //
 16 // Revision: 
 17 // Revision 0.01 - File Created
 18 // Additional Comments: 
 19 //
 20 //////////////////////////////////////////////////////////////////////////////////
 21 module FIFO_test(
 22                         input clk,
 23                         input rstin_n,
 24                         
 25                         output wire [7:0] dout
 26                                     
 27     );
 28 wire clk_50M;
 29 wire clk_100M;
 30 
 31 wire             rst_n;
 32 
 33 reg [7:0]     din;//寫入FIFO中數據
 34 wire             wr_en;
 35 reg [2:0]     cnt;
 36 
 37 wire             full;//FIFO滿
 38 wire            empty;
 39 
 40 wire             rd_en;
 41 
 42 wire             valid;
 43 wire            wr_ack;
 44 
 45 wire             overflow;
 46 wire            underflow;
 47 
 48 wire             almost_empty;
 49 wire             almost_full;
 50 
 51 wire [7:0]     rd_data_count;
 52 wire [7:0]     wr_data_count;
 53 
 54 wire            prog_full;
 55 wire            prog_empty;
 56 
 57 
 58 assign wr_en = (!full && !rd_en && (cnt == 3'd5)) ?  1'b1 : 1'b0;//非滿時寫,且滿后就不再寫了,即便之后數據被讀取導致非滿
 59 assign rd_en = (empty == 1'b0 && wr_en == 1'b0) ? 1'b1 : 1'b0;//寫時不讀取,寫完再讀取
 60 
 61 //----------寫FIF數據---------------------------
 62 always @(posedge clk_50M or negedge rst_n) 
 63      if(!rst_n)
 64         begin
 65             din <= 8'd0;
 66             cnt <= 3'd0;
 67         end
 68     else
 69         begin
 70             if(full)
 71                 begin
 72                     din <= 8'd0;
 73                 end
 74             else if(wr_en)
 75                 begin
 76                     din <= din + 8'd1;
 77                 end
 78             else
 79                 begin
 80                     din <= din;
 81                 end
 82                 
 83             if(cnt == 3'd5)
 84                 begin
 85                     cnt <= cnt;
 86                 end
 87             else
 88                 begin
 89                     cnt <= cnt + 3'd1;
 90                 end
 91         end
 92         
 93 fifo_ip FIFO_ip (
 94                       .rst(!rst_n), // input rst
 95                       .wr_clk(clk_50M), // input wr_clk
 96                       .rd_clk(clk_100M), // input rd_clk
 97                       .din(din), // input [7 : 0] din
 98                       .wr_en(wr_en), // input wr_en
 99                       .rd_en(rd_en), // input rd_en
100                       .dout(dout), // output [3 : 0] dout
101                       .full(full), // output full
102                       .almost_full(almost_full), // output almost_full
103                       .wr_ack(wr_ack), // output wr_ack
104                       .overflow(overflow), // output overflow
105                       .empty(empty), // output empty
106                       .almost_empty(almost_empty), // output almost_empty
107                       .valid(valid), // output valid
108                       .underflow(underflow), // output underflow
109                       .rd_data_count(rd_data_count), // output [7 : 0] rd_data_count
110                       .wr_data_count(wr_data_count), // output [7 : 0] wr_data_count
111                       .prog_full(prog_full), // output prog_full
112                       .prog_empty(prog_empty) // output prog_empty
113                     );
114 
115   pll_ip PLL_ip(                                // Clock in ports
116                          .CLK_IN1(clk),      // IN
117                             // Clock out ports
118                          .CLK_OUT1(clk_50M),     // OUT
119                          .CLK_OUT2(clk_100M),     // OUT
120                          // Status and control signals
121                          .RESET(!rstin_n),// IN
122                          .LOCKED(rst_n) // OUT
123                          );     
124                         
125 //ILA和ICON定義
126 //ILA和ICON定義
127 wire [35:0] CONTROL0;
128 wire [127:0] TRIG0;
129 
130 
131 ICON ICON (
132                  .CONTROL0(CONTROL0) // INOUT BUS [35:0]
133               );
134 
135 ILA ILA (
136             .CONTROL(CONTROL0), // INOUT BUS [35:0]
137             .CLK(clk_100M), // IN
138             .TRIG0(TRIG0) // IN BUS [15:0]
139         );
140 
141 assign TRIG0[7:0]  = din;
142 assign TRIG0[8]     = wr_en;
143 assign TRIG0[9]     = wr_ack;
144 assign TRIG0[10]     = full;
145 assign TRIG0[11]     = almost_full;
146 assign TRIG0[12]     = overflow;
147 assign TRIG0[13]     = empty; 
148 assign TRIG0[14]     = prog_full; 
149 assign TRIG0[15]     = prog_empty; 
150 
151 
152 assign TRIG0[23:16] = dout;
153 assign TRIG0[24]      = rd_en;
154 assign TRIG0[25]      = valid;
155 assign TRIG0[26]      = underflow;
156 
157 
158 endmodule

仿真代碼如下:

`timescale 1ns / 1ps

////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer:
//
// Create Date:   20:19:58 11/14/2016
// Design Name:   FIFO_test
// Module Name:   D:/Xilinx_Project/FIFO_test/vtf_FIFO_test.v
// Project Name:  FIFO_test
// Target Device:  
// Tool versions:  
// Description: 
//
// Verilog Test Fixture created by ISE for module: FIFO_test
//
// Dependencies:
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
////////////////////////////////////////////////////////////////////////////////

module vtf_FIFO_test;

    // Inputs
    reg clk;
    reg rstin_n;

    // Outputs
    wire [3:0] dout;

    // Instantiate the Unit Under Test (UUT)
    FIFO_test uut (
        .clk(clk), 
        .rstin_n(rstin_n), 
        .dout(dout)
    );

    initial begin
        // Initialize Inputs
        clk = 0;
        rstin_n = 0;

        // Wait 100 ns for global reset to finish
        #1000;
        rstin_n = 1;
        // Add stimulus here
    end

always #10 clk = ~clk;
      
        
        
endmodule

查看仿真波形:

 

從上圖可以看出wr_en型號對應數據從0開始寫入,而對應wr_ack延時一個時鍾,表示數據寫入成功,wr_data_count延時wr_ack一個時鍾表示寫入到FIFO中的數據個數,由於rd_data_count對應於讀FIFO時鍾域,對應也可能會延時寫多個時鍾才出現,在此不做考慮。

注意:對應FIFO手冊上說明:復位完成后需要延時3個時鍾才能進行FIFO讀寫操作,則從仿真波形上也可以看出full信號在復位完成3個時鍾之后才拉低,所以這點需要注意一下。

In this configuration, the FIFO requires a minimum asynchronous reset pulse of 1 write clock
period (WR_CLK/CLK). After reset is detected on the rising clock edge of write clock, 3 write
clock periods are required to complete proper reset synchronization. During this time, the
FULL, ALMOST_FULL, and PROG_FULL flags are asserted. After reset is deasserted, these
flags deassert after three clock periods (WR_CLK/CLK) and the FIFO can then accept write
operations.


上圖讀操作:由於采用的是常規讀操作模式,則置高rd_en一個時鍾之后讀數據才輸出,對應valid有效信號延時rd_en一個時鍾,valid正好對齊dout。

注意full ,almost_full等信號的變化,almost_full延時一個時鍾之后full信號才置高,都是跟隨寫時鍾變化的。full信號跟隨寫時鍾,empty信號跟隨讀時鍾。

pro_full時跟隨寫時鍾變化的,當wr_data_count滿足設置的wr_data_count >=253時pro_full就會置高。

pro_empty跟隨讀時鍾變化,當rd_data_count滿足設置的rd_data_count <= 2時peo_empty就會置高。

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM