微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > 关于FIFO的问题

关于FIFO的问题

时间:10-02 整理:3721RD 点击:
我想用verilog构造一个fifo,由两个频率不同的独立时钟控分别制输入输出。可以实现吗?可以用两个状态机来控制FIFO吗?

可以在google上搜一下,有很多介绍



我写了一个不知道有没有问题
module fifo_i (input [15:0]data_in,input clk_in,clk_o,rst,rd,wr,fifo_i,reset,
             output empty,full,output reg [4:0]fifo_cnt,output reg [15:0]data_out);
    reg [15:0] fifo_ram[0:15] ;
    reg [2:0]  rd_ptr,wr_ptr;                               //read and write point
    assign empty=(fifo_cnt==0);
    assign full= (fifo_cnt==15);
    always @( posedge clk_i ) begin:write
        if(fifo_i)begin
            if(wr &&!full)
                fifo_ram[wr_ptr] <= data_in;
                /*    else if(wr && rd)
                fifo_ram[wr_ptr] <= data_in;*/
            end
    end
    always @ (posedge clk_o )begin:read
        if(fifo_i)begin
            if (rd&&!empty)
                data_out <= fifo_ram[rd_ptr];
                    else if (wr&&rd)                          // always deal with the data read out fifo first
                data_out <= fifo_ram[rd_ptr];         
        end
    end
    always @ (posedge clk_i )begin:pointer1
        if (fifo_i)begin
            if (rst)begin
                wr_ptr<=0;
               
            end
            else begin
                wr_ptr<=((fifo_i&&(wr&&!full)/*||(wr&&rd)*/))?wr_ptr+1:wr_ptr;   
            end
        end
    end
   
        always @ (posedge clk_o )begin:pointer2
        if (fifo_i)begin
            if (rst)begin
                rd_ptr<=0;
            end
            else begin
                rd_ptr<=((fifo_i&&(rd&&!empty))||(fifo_i&&(wr&&rd)))?rd_ptr+1:rd_ptr;
            end
        end
    end
   
    always @ (posedge clk_i )begin:count1
        if (fifo_i)begin
            if (rst)
            fifo_cnt <=4'b0000;
            else begin
            case({wr,rd})
            2'b00:fifo_cnt<=fifo_cnt;
        /*    2'b01:fifo_cnt<=(fifo_cnt==0)?0:fifo_cnt-1;    */
            2'b10:fifo_cnt<=(fifo_cnt==15)?15:fifo_cnt+1;
        /*    2'b11:fifo_cnt<=fifo_cnt-1;                    */
            default:fifo_cnt<=fifo_cnt;
            endcase
            end
            end
          end
        always @ (posedge clk_o)begin:count2
        if (fifo_i)begin
            if (rst)
            fifo_cnt <=4'b0000;
            else begin
            case({wr,rd})
            2'b00:fifo_cnt<=fifo_cnt;
            2'b01:fifo_cnt<=(fifo_cnt==0)?0:fifo_cnt-1;
        /*    2'b01:fifo_cnt<=(fifo_cnt==15)?15:fifo_cnt+1;   */
            2'b11:fifo_cnt<=fifo_cnt-1;
            default:fifo_cnt<=fifo_cnt;
            endcase
            end
            end
        end
endmodule

就是异步fifo,很多资料的

当然可以 FIFO就是用在跨时钟域的地方

一个异步FIFO的实现 怎么描述的怪怪的

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top