【FPGA】双端口RAM的设计(异步读写)
【摘要】 上篇写了双端口RAM设计(同步读写):https://blog.csdn.net/Reborn_Lee/article/details/90647784
关于异步读写和同步读写,在单端口RAM设计中也提到过:https://blog.csdn.net/Reborn_Lee/article/details/90646285
这里就不再叙述了,总之就是和时钟无关了。
下面...
上篇写了双端口RAM设计(同步读写):https://blog.csdn.net/Reborn_Lee/article/details/90647784
关于异步读写和同步读写,在单端口RAM设计中也提到过:https://blog.csdn.net/Reborn_Lee/article/details/90646285
这里就不再叙述了,总之就是和时钟无关了。
下面我们同样会给出Verilog设计和仿真验证。
有了同步读写的Verilog描述,异步简直易如反掌:
-
`timescale 1ns / 1ps
-
//
-
// Create Date: 2019/05/28 22:53:20
-
// Design Name:
-
// Module Name: ram_dp_ar_aw
-
//
-
-
-
module ram_dp_ar_aw #(
-
parameter DATA_WIDTH = 8,
-
parameter ADDR_WIDTH = 8,
-
parameter RAM_DEPTH = 1 << ADDR_WIDTH
-
)(
-
input [ADDR_WIDTH - 1 : 0] address_0 , // address_0 Input
-
inout [DATA_WIDTH-1 : 0] data_0 , // data_0 bi-directional
-
input cs_0 , // Chip Select
-
input we_0 , // Write Enable/Read Enable
-
input oe_0 , // Output Enable
-
input [ADDR_WIDTH - 1 : 0] address_1 , // address_1 Input
-
inout [DATA_WIDTH-1 : 0] data_1 , // data_1 bi-directional
-
input cs_1 , // Chip Select
-
input we_1 , // Write Enable/Read Enable
-
input oe_1 // Output Enable
-
);
-
-
//--------------Internal variables----------------
-
reg [DATA_WIDTH-1:0] data_0_out ;
-
reg [DATA_WIDTH-1:0] data_1_out ;
-
reg [DATA_WIDTH-1:0] mem [0:RAM_DEPTH-1];
-
-
-
//initialization
-
-
// synopsys_translate_off
-
integer i;
-
initial begin
-
for(i=0; i < RAM_DEPTH; i = i + 1) begin
-
mem[i] = 8'h00;
-
end
-
end
-
// synopsys_translate_on
-
-
-
//--------------Code Starts Here------------------
-
// Memory Write Block
-
// Write Operation : When we_0 = 1, cs_0 = 1
-
always @ (address_0 or cs_0 or we_0 or data_0
-
or address_1 or cs_1 or we_1 or data_1)
-
begin : MEM_WRITE
-
if ( cs_0 && we_0 ) begin
-
mem[address_0] <= data_0;
-
end
-
else if (cs_1 && we_1) begin
-
mem[address_1] <= data_1;
-
end
-
end
-
-
// Tri-State Buffer control
-
// output : When we_0 = 0, oe_0 = 1, cs_0 = 1
-
assign data_0 = (cs_0 && oe_0 && !we_0) ? data_0_out : 8'bz;
-
-
// Memory Read Block
-
// Read Operation : When we_0 = 0, oe_0 = 1, cs_0 = 1
-
always @ (address_0 or cs_0 or we_1 or oe_0)
-
begin : MEM_READ_0
-
if (cs_0 && !we_0 && oe_0) begin
-
data_0_out <= mem[address_0];
-
end else begin
-
data_0_out <= 0;
-
end
-
end
-
-
//Second Port of RAM
-
// Tri-State Buffer control
-
// output : When we_0 = 0, oe_0 = 1, cs_0 = 1
-
assign data_1 = (cs_1 && oe_1 && !we_1) ? data_1_out : 8'bz;
-
// Memory Read Block 1
-
// Read Operation : When we_1 = 0, oe_1 = 1, cs_1 = 1
-
always @ (address_1 or cs_1 or we_1 or oe_1)
-
begin : MEM_READ_1
-
if (cs_1 && !we_1 && oe_1) begin
-
data_1_out <= mem[address_1];
-
end else begin
-
data_1_out <= 0;
-
end
-
end
-
-
endmodule // End of Module ram_dp_ar_aw
仿真同步的做过了,这个会难吗?
虽然这里没用到时钟,但测试文件,我仍可以使用时钟,作为一个时间标尺吧,这样就可以直接用上篇博文的测试文件,我也懒着改了(这里说的直接用,是大体上直接用,但仍需改动例化,以及模块名字什么的,以及参数等等):
先读初始值,什么时候给地址什么时候给数据:
地址0写,地址1读:
双端口同时读:(地址与数据对齐)
最后还是给出测试文件吧:
-
`timescale 1ns / 1ps
-
-
module ram_dp_ar_aw_tb;
-
-
reg clk ; // Clock
-
reg [7 : 0] address_0 ; // address_0 input
-
wire [7 : 0] data_0 ; // data_0 bi-directional
-
reg cs_0 ; // Chip Select
-
reg we_0 ; // Write Enable/Read Enable
-
reg oe_0 ; // Output Enable
-
reg [7 : 0] address_1 ; // address_1 input
-
wire [7 : 0] data_1 ; // data_1 bi-directional
-
reg cs_1 ; // Chip Select
-
reg we_1 ; // Write Enable/Read Enable
-
reg oe_1 ; // Output Enable
-
-
-
initial begin
-
clk = 0;
-
forever
-
#2 clk = ~clk;
-
end
-
-
reg [7 : 0] data_in0; //写数据时候,双向总线与data_in0连接(这样做的目的是保证总线在某一时刻读和写,二者之一有效)
-
assign data_0 = (cs_0 && we_0 && !oe_0) ? data_in0 : 8'dz;
-
-
reg [7 : 0] data_in1; //写数据时候,双向总线与data_in1连接(这样做的目的是保证总线在某一时刻读和写,二者之一有效)
-
assign data_1 = (cs_1 && we_1 && !oe_1) ? data_in1 : 8'dz;
-
-
integer i = 0;
-
-
initial begin
-
oe_0 = 0;
-
oe_1 = 0;
-
we_0 = 0;
-
we_1 = 0;
-
cs_0 = 0;
-
cs_1 = 0;
-
address_0 = 0;
-
address_1 = 0;
-
data_in0 = 0;
-
data_in1 = 0;
-
//先读出初识值(两套地址一起读)
-
#4
-
cs_0 = 1;
-
cs_1 = 1;
-
oe_0 = 1;
-
oe_1 = 1;
-
-
for(i = 0; i < 256; i = i + 1) begin
-
@(negedge clk) begin
-
address_0 = i;
-
address_1 = i;
-
end
-
-
end
-
-
//地址0写,地址1读
-
@(negedge clk) begin
-
we_0 = 1;
-
we_1 = 0;
-
oe_0 = 0;
-
oe_1 = 1;
-
-
end
-
-
for(i = 0; i < 256; i = i + 1) begin
-
@(negedge clk) begin
-
address_0 = i;
-
data_in0 = data_in0 + 1;
-
address_1 = i;
-
end
-
-
end
-
-
//地址0读·,地址1读
-
@(negedge clk) begin
-
we_0 = 0;
-
we_1 = 0;
-
oe_0 = 1;
-
oe_1 = 1;
-
-
end
-
-
for(i = 0; i < 256; i = i + 1) begin
-
@(negedge clk) begin
-
address_0 = i;
-
address_1 = i;
-
end
-
-
end
-
-
-
//结束吧,片选结束
-
@(negedge clk) begin
-
cs_0 = 0;
-
cs_1 = 0;
-
end
-
-
#100 $stop;
-
-
-
end
-
-
-
ram_dp_ar_aw #(
-
.ADDR_WIDTH(8), //给参数
-
.DATA_WIDTH(8)
-
) u_ram(
-
.address_0(address_0),
-
.data_0(data_0),
-
.cs_0(cs_0),
-
.we_0(we_0),
-
.oe_0(oe_0),
-
.address_1(address_1),
-
.data_1(data_1),
-
.cs_1(cs_1),
-
.we_1(we_1),
-
.oe_1(oe_1)
-
);
-
-
-
-
endmodule
参考链接:http://www.asic-world.com/examples/verilog/ram_dp_ar_aw.html
文章来源: reborn.blog.csdn.net,作者:李锐博恩,版权归原作者所有,如需转载,请联系作者。
原文链接:reborn.blog.csdn.net/article/details/90648811
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)