fifo学习(5)

4.异步fifo

(2)带同步复位信号和标志位

读写频率比为2:1

module ID_fifo1(rst,wr_clk,rd_clk,din,wr_en,rd_en,dout,full,empty,almost_full,almost_empty,valid);
 input rst;
 input wr_clk;
 input rd_clk;
 input [7:0] din;
 input wr_en;
 input rd_en;
 output [3:0] dout;
 output full;
 output empty;
 output almost_full;
 output almost_empty;
 output valid;
 
 reg [7:0] din1;
 always @(posedge wr_clk or posedge rst)//异步fifo只能异步复位
    begin
         if(rst)
            din1 <= 8'd0;
         else
            din1 <= din;
    end
    
 fifo_8_16_rst f1 (
  .rst(rst),                    // input wire rst
  .wr_clk(wr_clk),              // input wire wr_clk
  .rd_clk(rd_clk),              // input wire rd_clk
  .din(din1),                    // input wire [7 : 0] din
  .wr_en(wr_en),                // input wire wr_en
  .rd_en(rd_en),                // input wire rd_en
  .dout(dout),                  // output wire [3 : 0] dout
  .full(full),                  // output wire full
  .almost_full(almost_full),    // output wire almost_full
  .empty(empty),                // output wire empty
  .almost_empty(almost_empty),  // output wire almost_empty
  .valid(valid)                // output wire valid
);
endmodule

module tb_ID_fifo1;
 reg rst,wr_clk,rd_clk;
 reg [7:0] din;
 reg wr_en,rd_en;
 wire [3:0] dout;
 wire full,empty,almost_full,almost_empty,valid;
 
 initial begin
              rst=1'b1;
              wr_clk=1'b0;
              rd_clk=1'b0;
              din=8'd0;
              wr_en=1'b1;//写
              rd_en=1'b0;
              #160
              rst=1'b0;
              #400
              wr_en=1'b0;//读
              rd_en=1'b1;
         end
 always #20 wr_clk = ~wr_clk;
 always #10 rd_clk = ~rd_clk;
 always #40 din = din + 1'b1;
 
 ID_fifo1 i1(.rst(rst),
             .wr_clk(wr_clk),
             .rd_clk(rd_clk),
             .din(din),
             .wr_en(wr_en),
             .rd_en(rd_en),
             .dout(dout),
             .full(full),
             .empty(empty),
             .almost_full(almost_full),
             .almost_empty(almost_empty),
             .valid(valid));
endmodule

可以看出,在rst置零后的第4个写时钟上升沿(本来是3个,因为赋值语句增加了一级延时)才能开始写入,即300ns的位置;在540写入最后一个0c;在570开始读取,850读取结束;在rst异步复位有效的情况下,full、empty、almost_full、almost_empty都置1,dout置零;

读写频率比为4:3

一样是4个周期的写入延时;

(3)带同步复位信号和标志位+输出寄存器

加入寄存器后增加了一级延时;

(4)带同步复位信号和标志位+FWFT

valid信号提前置1

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值