之前的博文都是讲单端口RAM的,它们仅有一套控制输入,例如cs,we,oe,还有数据总线以及地址。

【FPGA】单端口RAM的设计(同步读、同步写)

附上太多链接,我也累,自己找吧。

双端口RAM,顾名思义,有两套地址,数据总线,以及cs等。

从输入输出也可以看出来:

input clk       , // Clock Input
input [ADDR_WIDTH - 1 : 0] address_0 , // address_0 Input
inout [data_0_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_0_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

写部分:

//--------------Code Starts Here------------------ 
// Memory Write Block 
// Write Operation : When we_0 = 1, cs_0 = 1
always @ (posedge clk)
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 @ (posedge clk)
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 @ (posedge clk)
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

可见,可以操作地址0以及地址1读写,因此可以实现同时读写操作。

如果对两套端口同时进行写操作,可见地址0优先,而读就不存在这种情况。(可不必考虑这句话!)

下面给出完整Verilog HDL设计代码:

`timescale 1ns / 1ps
//
// Create Date: 2019/05/28 20:50:48
// Design Name:
// Module Name: ram_dp_sr_sw
//module ram_dp_sr_sw #(
parameter data_0_WIDTH = 8,
parameter ADDR_WIDTH = 8,
parameter RAM_DEPTH = 1 << ADDR_WIDTH
)(
input clk       , // Clock Input
input [ADDR_WIDTH - 1 : 0] address_0 , // address_0 Input
inout [data_0_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_0_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_0_WIDTH-1:0] data_0_out ;
reg [data_0_WIDTH-1:0] data_1_out ;
reg [data_0_WIDTH-1:0] mem [0:RAM_DEPTH-1];//initialization// synopsys_translate_off
integer i;
initial beginfor(i=0; i < RAM_DEPTH; i = i + 1) beginmem[i] = 8'h00;end
end
// synopsys_translate_on//--------------Code Starts Here------------------
// Memory Write Block
// Write Operation : When we_0 = 1, cs_0 = 1
always @ (posedge clk)
begin : MEM_WRITEif ( cs_0 && we_0 ) beginmem[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 @ (posedge clk)
begin : MEM_READ_0if (cs_0 && !we_0 && oe_0) begindata_0_out <= mem[address_0]; end else begindata_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 @ (posedge clk)
begin : MEM_READ_1if (cs_1 && !we_1 && oe_1) begindata_1_out <= mem[address_1]; end else begindata_1_out <= 0;end
endendmodule // End of Module ram_dp_sr_sw

下面对此进行测试:

过程如下:

两个端口同时对RAM初值:

端口0写,同时端口1读:

两端口同时读:

可见,读出来的数据与时钟同步。

最后给出测试文件:

`timescale 1ns / 1psmodule ram_dp_sr_sw_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 Enableinitial beginclk = 0;forever#2 clk = ~clk;
endreg [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) beginaddress_0 = i;address_1 = i;endend//地址0写,地址1读@(negedge clk) beginwe_0 = 1;we_1 = 0;oe_0 = 0;oe_1 = 1;endfor(i = 0; i < 256; i = i + 1) begin@(negedge clk) beginaddress_0 = i;data_in0 = data_in0 + 1;address_1 = i;endend//地址0读·,地址1读@(negedge clk) beginwe_0 = 0;we_1 = 0;oe_0 = 1;oe_1 = 1;endfor(i = 0; i < 256; i = i + 1) begin@(negedge clk) beginaddress_0 = i;address_1 = i;endend//结束吧,片选结束
@(negedge clk) begin
cs_0 = 0;
cs_1 = 0;
end#100 $stop;endram_dp_sr_sw #(
.ADDR_WIDTH(8), //给参数
.data_0_WIDTH(8)) u_ram(
.clk(clk),
.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_sr_sw.html

【FPGA】双端口RAM的设计(同步读写)相关推荐

  1. 【FPGA】双端口RAM的设计(异步读写)

    上篇写了双端口RAM设计(同步读写):https://blog.csdn.net/Reborn_Lee/article/details/90647784 关于异步读写和同步读写,在单端口RAM设计中也 ...

  2. 【正点原子FPGA连载】第十九章IP核之双端口RAM实验 -摘自【正点原子】新起点之FPGA开发指南_V2.1

    1)实验平台:正点原子新起点V2开发板 2)平台购买地址:https://detail.tmall.com/item.htm?id=609758951113 2)全套实验源码+手册+视频下载地址:ht ...

  3. Verilog设计实例(3)基于Verilog的单端口同步读写RAM设计

    文章目录 写在前面 正文 电路设计 行为仿真 交个朋友 写在前面 为什么要写单端口同步读写RAM呢? 没有那么多为什么?就是因为简单.基础,能清晰说明单端口RAM的原理,顺手给出设计,也能说明你的设计 ...

  4. 数字IC设计系列----单端口RAM、双端口RAM、同步FIFO、异步FIFO

    目录​​​​​​​ 一.单端口RAM原理及实现 1.1.原理 1.2.Verilog实现 1.3.优缺点分析 2.双端口RAM原理及实现 2.1.原理 2.2.Verilog实现 2.3.优缺点分析 ...

  5. 【FPGA】单端口RAM的设计(异步读、同步写)

    上篇博文讲到了:单端口同步读写RAM的设计,那里对RAM的读写采用的是同步的方式,也就是和时钟同步,读写都依赖于时钟. 这篇博文,我们的写依然是同步的,但是读是异步的,所谓的异步就是指不依赖于时钟,这 ...

  6. 【FPGA】单端口RAM的设计(同步读、同步写)

    Single Port RAM  Synchronous Read/Write 这篇博文介绍单端口同步读写RAM,在之前的博文中,也介绍过类似的设计:[Verilog HDL 训练]第 13 天(存储 ...

  7. 【FPGA】单端口RAM的设计(异步读、异步写)

    前面有博文写了同步读写和异步读.同步写的单端口RAM设计: [FPGA]单端口RAM的设计(同步读.同步写) [FPGA]单端口RAM的设计(异步读.同步写) 这篇博文讲异步读写: 在博文:[FPGA ...

  8. FPGA 基于双端口RAM的串口通信系统

    FPGA实验报告 文章目录 一.概述 1.目的及意义: 2.主要功能: 二.原理及步骤 1.原理框图: 2.工作原理 3.功能模块简介 4.实验步骤 三.程序设计及描述 四.仿真与综合测试 五.总结 ...

  9. (195)FPGA编程:双端口RAM(一)

    (195)FPGA编程:双端口RAM(一) 1.1.1 本节目录 1)本节目录: 2)本节引言: 3)FPGA简介: 4)FPGA编程:双端口RAM(一): 5)结束语. 1.1.2 本节引言 &qu ...

最新文章

  1. Wpf消息循环之消息传递
  2. 5G 信令流程 — 5GC 的连接管理(CM,Connection Management)
  3. The Elements of C# Style -Naming
  4. java中HashMap,LinkedHashMap,TreeMap,HashTable的区别
  5. python 编程一日一练-Python每日一练0022
  6. UIAutomation 自动化
  7. AntDB上使用表空间
  8. python getattr和getattribute_python中__getattr__和__getattribute__区别
  9. php 动态多维数组长度,怎么在php中利用count获取多维数组的长度
  10. SDUT 3347 数据结构实验之数组三:快速转置
  11. 首提“智能X效应”,英特尔携手产业加速智能变革
  12. redis 配置文件翻译
  13. 华为鸿蒙操作系统国美通讯,国美通讯(600898)03月06日14:30大单揭秘
  14. 微信商户平台关闭自动提现
  15. 个人计算机也可以做为服务器,普通个人电脑可以充当电脑服务器来使用吗
  16. 原版XP合集,非BT下载
  17. winform程序使用clickonce方式发布之后点击安装没反应
  18. Windows 任意窗口置顶显示
  19. 广东最新中级消防设施操作员机考真题及答案
  20. 客户案例|低代码上的西门子,乘风破浪的财务部

热门文章

  1. TypeMock是很不错的模拟测试框架
  2. python bottle部署g_python web(bottle框架)之环境搭建
  3. vue中父子组件先后渲染_VUE如何实现子父组件、父子组件、兄弟组件传值
  4. jstree中文api文档_开发中文 API 的一些策略
  5. linux系统用uefi启动安装win7,uefi下安装win7系统有什么不同
  6. linux用户变量设置位置,linux---位置参数
  7. rsa加密算法java实例,java实现的RSA加密算法详解
  8. linux数组删除数据,JavaScript在数组的循环中删除元素
  9. 虚幻4皮肤材质_虚幻周报20200721 | CJ就要开始啦~
  10. 智能车竞赛技术报告 | 智能车视觉 - 中南大学 - 中南大学比亚迪午马2021