FPGA 内部双口块RAM 读写实现

XILINX官网文档PG058 “LogiCORE IP Block Memory Generator v8.2”

FPGA 内部块RAM 的读时序如下图:

   可知,块RAM的读延时为两个时钟周期。

FPGA 内部块RAM 的写时序如下图:

 可知,块RAM 的写延时为0,但是RAM 中的内容是在写的下一个时钟改变。

 

在ISE下实现对FPGA内部块RAM 的读写代码:

module TOP(
input USER_CLK
    );

`define DLY #1
reg FPGA_Enable=0;
reg[3:0] FPGA_Write_Enable=4'h0;
reg[31:0] FPGA_Address=0;
reg[31:0] FPGA_Write_Data=0;
reg[31:0] FPGA_Read_Data_reg=0;
wire[31:0] FPGA_Read_Data;

reg[10:0] count=0;
always @ (posedge USER_CLK)
begin
	count <= count + 1;
	if(count<=100)
	begin
		FPGA_Enable <= 0;
		FPGA_Write_Enable <= 4'h0;
	end
	else if((count <= 105)&&(count >100))
	begin
		FPGA_Enable <= 1;
		FPGA_Write_Enable <= 4'hf;
		FPGA_Address <= FPGA_Address + 4;
		FPGA_Write_Data <= FPGA_Write_Data + 1;
	end
	else if((count <= 110)&&(count >105))
	begin
		FPGA_Enable <= 0;
		FPGA_Write_Enable <= 4'h0;
		FPGA_Address <= 0;
		FPGA_Write_Data <= 0;
	end
	else if((count <= 117)&&(count >110))
	begin
		FPGA_Enable <= 1;
		FPGA_Write_Enable <= 4'h0;
		FPGA_Read_Data_reg <= FPGA_Read_Data;
		FPGA_Address <= FPGA_Address + 4;
	end
	else if(count == 118)
	begin
		FPGA_Enable <= 0;
		count <= count;
		
	end
end

BBBB your_instance_name (
  .clka(USER_CLK), // input clka
  .ena(FPGA_Enable), // input ena
  .wea(FPGA_Write_Enable), // input [3 : 0] wea
  .addra(FPGA_Address), // input [31 : 0] addra
  .dina(FPGA_Write_Data), // input [31 : 0] dina
  .douta(FPGA_Read_Data), // output [31 : 0] douta
  
  
  .clkb(clkb), // input clkb
  .enb(enb), // input enb
  .web(web), // input [3 : 0] web
  .addrb(addrb), // input [31 : 0] addrb
  .dinb(dinb), // input [31 : 0] dinb
  .doutb(doutb) // output [31 : 0] doutb
);
endmodule


效果图:

从上图可以看出,在地址4~20里面写入了1-5的数,数据读出的时候对应地址的数据都延时了两个时钟周期才输出。

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值