欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > Xilinx FPGA:vivado关于同步fifo的两个小实验

Xilinx FPGA:vivado关于同步fifo的两个小实验

2024/10/24 7:22:15 来源:https://blog.csdn.net/loveyousosad/article/details/140229992  浏览:    关键词:Xilinx FPGA:vivado关于同步fifo的两个小实验

一、实验一:在同步fifo里写一个读一个(写入是8个位宽,读出是16个位宽)

程序:

`timescale 1ns / 1ps
//要求写一个读一个
//读写时钟一致,写是8个位宽,读是16个位宽
module sync_fifo_test(input                 sys_clk    ,input                 rst_n      );wire [15 : 0]   dout         ;                    wire full                    ;wire wr_ack                  ;wire empty                   ;wire valid                   ;wire [4 : 0] rd_data_count   ;wire [5 : 0] wr_data_count   ;reg [7 : 0] din  ;reg wr_en        ;reg rd_en        ;always@(posedge sys_clk )if(!rst_n)din <= 0 ;elsedin <= din +1 ;always@(posedge sys_clk )if(!rst_n)wr_en <= 0 ;else if (full)wr_en <= 0 ;elsewr_en <= 1 ;//----------- Begin Cut here for INSTANTIATION Template ---// INST_TAG
sync_fifo_generator your_instance_name (.clk(sys_clk),                      // input wire clk.srst(~rst_n),                    // input wire srst.din(din),                      // input wire [7 : 0] din.wr_en(wr_en),                  // input wire wr_en.rd_en(wr_ack),                  // input wire rd_en.dout(dout),                    // output wire [15 : 0] dout.full(full),                    // output wire full.wr_ack(wr_ack),                // output wire wr_ack.empty(empty),                  // output wire empty.valid(valid),                  // output wire valid.rd_data_count(rd_data_count),  // output wire [4 : 0] rd_data_count.wr_data_count(wr_data_count)  // output wire [5 : 0] wr_data_count
);
// INST_TAG_END ------ End INSTANTIATION Template ---------endmodule

仿真程序:

`timescale 1ns / 1ps
module test_sync_fifo( );reg                 sys_clk    ;reg                 rst_n      ;initialbeginsys_clk = 0 ;rst_n   = 0 ;#10rst_n   = 1 ;endalways #1 sys_clk = ~sys_clk ;     sync_fifo_test  sync_fifo_test_1(.         sys_clk  ( sys_clk)  ,.         rst_n    ( rst_n  )  );endmodule

实验结果:

TIPS:

二、实验二:在实验一的基础上完成“写完再读”

程序:

`timescale 1ns / 1ps
module sync_fifo_2(input               sys_clk   ,input               rst_n     );reg   [7 : 0] din             ;reg   wr_en                   ;reg   rd_en                   ;wire [15 : 0] dout            ;wire full                     ;wire wr_ack                   ;wire empty                    ;wire valid                    ;wire [4 : 0] rd_data_count    ;wire [5 : 0] wr_data_count    ;always@(posedge sys_clk )if(!rst_n)wr_en <= 0 ;else if (full)wr_en <= 0 ;else if (rd_en)wr_en <= 0 ;elsewr_en <= 1 ;always@(posedge sys_clk )if(!rst_n)din <= 0 ;elsedin <= din +1 ;always@(posedge sys_clk )if(!rst_n)rd_en <= 0 ;else if (full)   //写满了 rd_en <= 1 ;else if (empty)   // 读空了rd_en <= 0 ;elserd_en <= rd_en ;//----------- Begin Cut here for INSTANTIATION Template ---// INST_TAG
sync_fifo_generator your_instance_name (.clk(sys_clk ),                      // input wire clk.srst(~rst_n),                    // input wire srst.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 [15 : 0] dout.full(full),                    // output wire full.wr_ack(wr_ack),                // output wire wr_ack.empty(empty),                  // output wire empty.valid(valid),                  // output wire valid.rd_data_count(rd_data_count),  // output wire [4 : 0] rd_data_count.wr_data_count(wr_data_count)  // output wire [5 : 0] wr_data_count
);
// INST_TAG_END ------ End INSTANTIATION Template ---------endmodule

仿真程序:

`timescale 1ns / 1ps
module test_sync_fifo_2( );reg               sys_clk   ;reg               rst_n     ;initialbeginsys_clk = 0 ;rst_n   = 0 ;#10rst_n   = 1 ;endalways #1 sys_clk = ~sys_clk ;sync_fifo_2   sync_fifo_2_1(.    sys_clk  (sys_clk) ,.    rst_n    (rst_n  ) ); endmodule

仿真结果:

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com