FIFO的学习

本文介绍了一个16*16位FIFO的设计实现,包括功能框图及Verilog HDL代码。该FIFO支持读写操作,并通过fifo_empty、fifo_full和fifo_half等信号指示状态。

                        16*16位FIFO的功能框图

 

其中,clock为系统时钟信号输入,reset为系统复位信号,read为读数据信号允许信号,write为写入FIFO允许信号,fifo_in[15:0]为数据输入,fifo_out[15:0]为数据输出,fifo_empty为指示FIFO当前是空的,这种情况下,只能对FIFO进行写入数据操作;fifo_full指示当前FIFO是满的,这种情况下,当然只能对FIFO进行读数据操作,是不能写入数据的;fifo_half指示当前FIFO队列中没空也没满,这种情况下,既可以对FIFO进行写入数据操作,也能进行读数据操

 

16*16位FIFO读写数据操作的Verilog HDL的代码整理如下。

module FIFO_16_16(
      clock,reset,
      read,write,fifo_in,fifo_out,
      fifo_empty,fifo_full,fifo_half);
input clock,reset,read,write;
input [15:0] fifo_in;
output [15:0] fifo_out;
output fifo_empty,fifo_full,fifo_half;

reg [15:0] fifo_out;
reg [3:0] read_ptr,write_ptr,counter;
reg [15:0] ram [15:0];
wire fifo_empty,fifo_full,fifo_half;

always @(posedge clock)
 if(reset)
  begin
  read_ptr=0;
  write_ptr=0;
  counter=0;
  fifo_out=0;
  end
 else
 case({read,write})
  2'b00: counter=counter;
  2'b01: begin
     ram[write_ptr]=fifo_in;
     counter=counter+1;
     write_ptr=(write_ptr==15)?0:write_ptr+1;
     end
  2'b10: begin
     fifo_out=ram[read_ptr];
     counter=counter-1;
     read_ptr=(read_ptr==15)?0:read_ptr+1;
     end
  2'b11: begin
     if(counter==0)
      fifo_out=fifo_in;
     else
      begin
       ram[write_ptr]=fifo_in;
       fifo_out=ram[read_ptr];
       write_ptr=(write_ptr==15)?0:write_ptr+1;
       read_ptr=(read_ptr==15)?0:read_ptr+1;
      end
     end
 endcase
assign fifo_empty=(counter==0);
assign fifo_full=(counter==15);
assign fifo_half=(counter==8);
endmodule

详细请见:http://www.cnblogs.com/ant2012/archive/2012/02/22/2362328.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值