首页 > 其他分享 >FPGA的FIFO部分的知识点

FPGA的FIFO部分的知识点

时间:2024-03-13 21:24:47浏览次数:20  
标签:知识点 wire FPGA clk FIFO rd wr rst fifo

看的小梅哥的新视频,FIFO这边讲的不太清楚,换正点原子的fifo听一下。

后面的以太网和HDMI有空也看一下正点原子的,主要是想快速看zynq的知识,而且现在学的很多都是模仿抄代码,真正自己来还是得工程中实际应用的时候才会使用学习


FIFO,先入先出,像队列。常用于数据的缓存,因为数据的读写带宽,也就是读写速度不同步,可以通过异步FIFO解决

同步FIFO就是读写同时钟,异步FIFO就是时钟独立,跨时钟处理。

这边FIFO的结构,黑色的都是必要的,蓝色的可选(读时钟在同步FIFO里面就没有了,可选),灰色的是可选(             )


这是时钟IP核生成的端口。

//----------- Begin Cut here for INSTANTIATION Template ---// INST_TAG
fifo_test your_instance_name (
  .rst(rst),                      // input wire rst
  .wr_clk(wr_clk),                // input wire wr_clk
  .rd_clk(rd_clk),                // input wire rd_clk
  .din(din),                      // 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 [7 : 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
  .rd_data_count(rd_data_count),  // output wire [7 : 0] rd_data_count
  .wr_data_count(wr_data_count),  // output wire [7 : 0] wr_data_count
  .wr_rst_busy(wr_rst_busy),      // output wire wr_rst_busy
  .rd_rst_busy(rd_rst_busy)      // output wire rd_rst_busy
);

从原子哥那里漂的顶层模块和例化的框图

任务是,先写满,再读出来

那么其中除了根据满和空的状态,控制读写信号使能。由时钟IP产生两个时钟分别给读写时钟,异步读写FIFO

fifo_wr
 module fifo_write(
    wr_clk,
    reset_n,
    
    //FIFO
    empty,  //输入空信号!!!这是读时钟域的信号,异步信号需要打拍。
    almost_full,  //将满信号
    wr_rst_busy, //写复位忙信号
    fifo_wr_en,
    fifo_wr_data
    );
    
    input   wr_clk;
    input   reset_n;
    
    input   empty;
    input   almost_full;
    input   wr_rst_busy;
    output reg fifo_wr_en;
    output reg [7:0] fifo_wr_data;
    
    reg empty_d0;
    reg empty_d1;
    
    //打两拍,延时2周期
    //因为实际上的空信号是读时序的时候FIFO才能输出来的,所以这边跟写时序是异步信号
    always @(posedge wr_clk or negedge reset_n)
        if(!reset_n) begin
            empty_d0 <= 0;
            empty_d1 <= 0;
        end
        else begin
            empty_d0 <= empty;
            empty_d1 <= empty_d0;
        end
    
     always @(posedge wr_clk or negedge reset_n)
        if(!reset_n) 
            fifo_wr_en <= 0;
        else if(!wr_rst_busy) begin
            if(empty_d1)
                fifo_wr_en <= 1'b1;
            else if(almost_full)
                fifo_wr_en <= 1'b0;
        end
        
     //对fifo_wr_data赋值 0~254   
       always @(posedge wr_clk or negedge reset_n)
             if(!reset_n)
                fifo_wr_data <= 0;
             else if(fifo_wr_en && fifo_wr_data < 8'd254)
                fifo_wr_data <= fifo_wr_data + 8'd1;
             else
                fifo_wr_data <= 0;
                
endmodule
fifo_rd
 module fifo_read(
    rd_clk,
    reset_n,
    fifo_rd_data,
    almost_empty,
    full,
    rd_rst_busy,
    fifo_rd_en
    );
    
    input   rd_clk;
    input   reset_n;
    
    input  [7:0] fifo_rd_data;
    input   almost_empty;
    input   full;
    input   rd_rst_busy;
    
    output reg fifo_rd_en;
    
    reg full_d0;
    reg full_d1;
    
    always @(posedge rd_clk or negedge reset_n)
        if(!reset_n) begin
            full_d0 <= 0;
            full_d1 <= 0;
        end
        else begin
             full_d0 <= full;
             full_d1 <= full_d0;
        end
        
     always @(posedge rd_clk or negedge reset_n)
        if(!reset_n)
               fifo_rd_en <= 1'b0;
        else if(!rd_rst_busy) begin
            if(full_d1)
                fifo_rd_en <= 1'b1;
            else if(almost_empty)
                fifo_rd_en <= 1'b0;

        end
            
    
endmodule
ip_fifo顶层例化
 module ip_fifo(
    clk,
    reset_n
    );
    
    input   clk;
    input   reset_n;
    
    wire    clk_50m;
    wire    clk_100m;
    wire    locked;
    
    wire rst_n;
    assign rst_n = reset_n & locked;
    
    wire    empty;
    wire    almost_full    ;
    wire    wr_rst_busy    ;
    wire    fifo_wr_en     ;
    wire  [7:0]  fifo_wr_data   ;
    

    wire  [7:0]  fifo_rd_data  ;
    wire    almost_empty  ;
    wire    full          ;
    wire    rd_rst_busy   ;
    wire    fifo_rd_en    ;
    
    wire  [7:0]  rd_data_count;
    wire  [7:0]  wr_data_count;
    
   clk_wiz_0 instance_name
   (
    // Clock out ports
    .clk_out1(clk_50m),     // output clk_out1
    .clk_out2(clk_100m),     // output clk_out2
    // Status and control signals

    .locked(locked),       // output locked
   // Clock in ports
    .clk_in1(clk)
    );      // input clk_in1
    
    
    fifo_write fifo_wirte_inst(
     .wr_clk(clk_50m),     
     .reset_n(rst_n),    
                 
     //FIFO      
     .empty(empty),  //输入
     .almost_full(almost_full),
     .wr_rst_busy(wr_rst_busy),
     .fifo_wr_en(fifo_wr_en), 
     .fifo_wr_data(fifo_wr_data)
    
    
    
    );
    
    fifo_read fifo_read_inst(
    .rd_clk(clk_100m),       
    .reset_n(rst_n),      
    .fifo_rd_data(fifo_rd_data), 
    .almost_empty(almost_empty), 
    .full(full),         
    .rd_rst_busy(rd_rst_busy),  
    .fifo_rd_en(fifo_rd_en)    

    );
    
    //FIFO的复位高电平有效
    fifo_test your_instance_name (
  .rst(~rst_n),                      // input wire rst
  .wr_clk(clk_50m),                // input wire wr_clk
  .rd_clk(clk_100m),                // input wire rd_clk
  .din(fifo_wr_data),                      // input wire [7 : 0] din
  .wr_en(fifo_wr_en),                  // input wire wr_en
  .rd_en(fifo_rd_en),                  // input wire rd_en
  .dout(fifo_rd_data),                    // output wire [7 : 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
  .rd_data_count(rd_data_count),  // output wire [7 : 0] rd_data_count
  .wr_data_count(wr_data_count),  // output wire [7 : 0] wr_data_count
  .wr_rst_busy(wr_rst_busy),      // output wire wr_rst_busy
  .rd_rst_busy(rd_rst_busy)      // output wire rd_rst_busy
);
    
endmodule

 

FIFO的高电平复位,例化的时候取反。

标签:知识点,wire,FPGA,clk,FIFO,rd,wr,rst,fifo
From: https://www.cnblogs.com/cjl520/p/18070725

相关文章

  • 从零开始利用MATLAB进行FPGA设计(一):建立脉冲检测模型的Simulink模型2
    目录1.模块的总体结构1.1从工作空间导入输入信号1.2FIR滤波器2.Subsystem3.MATLABFunction文章灵感来源于MATLAB官方免费教程:HDLCoderSelf-GuidedTutorial考虑到MATLAB官网的英文看着慢,再加上视频讲解老印浓浓的咖喱味,我决定记录利用MATLAB&Simulink&SystemGenerat......
  • FPGA的时钟IP核知识点
    IP核在我看来就跟stm32中的一些驱动的库函数一样,可以调用快速使用。不用一步一步的自己写底层原理。可以加速设计,快速设计代码。IP核的PLL还有一个MMCM。PLL是锁相环,对时钟进行管理。也是后面使用中很重要的IP核。不同器件需要不同的时钟。时钟管理单元CMT=PLL+MMCM混合时钟管......
  • UVM - 2 (补充虚基类及纯虚函数知识点)
    虚方法和纯虚方法虚方法定义一个函数为虚函数,不代表函数为不被实现的函数。定义他为虚函数是为了允许用基类的指针来调用子类的这个函数。virtualfunction纯虚方法定义一个函数为纯虚函数,才代表函数没有被实现。定义纯虚函数是为了实现一个接口,起到一个规范的作用,规范......
  • 【Linux进程的知识点】
    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档文章目录前言操作系统的知识补充我们来理解一个用户操作接口:进程的理解进程的基本概念描述进程-PCBtask_struct-PCB的一种task_struct内容分类进程的task_struct本身内部的属性有哪些?1、启动查找pid......
  • 商票琐碎知识点记录
    1.基础交易关系:直接前手可以基于没有基础关系进行抗辩【票据司法解释第二条  依照票据法第十条的规定,票据债务人(即出票人)以在票据未转让时的基础关系违法、双方不具有真实的交易关系和债权债务关系、持票人应付对价而未付对价为由,要求返还票据而提起诉讼的,人民法院应当依法受理......
  • C语言最重要的知识点(2)
    第二章第一节:数据输出(一)(二)1、使用printf和scanf函数时,要在最前面加上#include“stdio.h”2、printf可以只有一个参数,也可以有两个参数。(选择题考过一次)3、printf(“第一部分”,第二部分 );把第二部分的变量、表达式、常量以第一部分的形式展现出来!4、printf(“a=%d,b=%d”,12......
  • 机器学习知识点
    目录机器学习的概念:样本:特征:标签:回归和分类任务:泛化能力:假设空间:输出空间:有监督学习:无监督学习:半监督学习:奥卡姆剃刀:四个损失函数:正确率:误差:过拟合:过拟合的处理:欠拟合欠拟合的处理方式:没有免费的午餐定理(NFL定理):误差训练误差:测试误差:验证误差:泛化误差......
  • 基于FPGA各种视频接口转换的国产化设计
    随着国产化进程推进,现在许多项目需要实现国产化设计,本博主通过器件选型/原理图设计,到视频接口输入,DDR3缓存,再到图像输出,使用者可在此基础实现二次开发,功能实现通过verilog,操作简单,添加功能方便。接口包含lvds/camelink/bt1120/hdmi/sdi等等常用视频接口,也可定制其他接口,带......
  • Django基础知识点一
    Django基础知识点【零】补充方法【1】Django项目测试if__name__=='__main__':importosimportdjangoos.environ.setdefault('DJANGO_SETTINGS_MODULE','BookSystem.settings')django.setup()'''测试代码''......
  • 计算机三级知识点(信息安全技术)
    计算机三级(信息安全技术)知识点源于顺文好友的馈赠TCSES(橘皮书)将计算机系统的安全划分为四个等级七个级别,是计算机安全评估的第一个正式标准。香农发表《保密系统的通信理论》1977年美国制定数据加密标准DES,为加密算法标准化奠定了基础。1994年美国颁布数字签名标准DS......