当前位置:网站首页>Verilog 每日一题(VL29 单端口RAM)
Verilog 每日一题(VL29 单端口RAM)
2022-07-28 16:23:00 【别再出error了】
题目描述:
设计一个单端口RAM,它有: 写接口,读接口,地址接口,时钟接口和复位;存储宽度是4位,深度128。注意rst为低电平复位。
信号示意图:

思路:由于是单端口的RAM,写入和读取都从一个端口进行,使能信号为高电平时写入,为低电平时读取。在数据写入时,需要用一个长度为128的数组来进行数据地址的存储(因为存储深度为128,则易得addr位宽为7bits)。由于写入数据宽度为4bits,所以数组也是4位。
(RAM: Random Access Memory,是与CPU直接交换数据的内部存储器。它可以随时读写(刷新时除外),而且速度很快,通常作为操作系统或其他正在运行中的程序的临时数据存储介质。)
代码详解如下:
`timescale 1ns/1ns
module RAM_1port(
input clk,
input rst,
input enb,
input [6:0]addr,
input [3:0]w_data,
output wire [3:0]r_data
);
//*************code***********//
reg [3:0] data[127:0]; //定义一个0-127的数组,因为深度是128,每个地址的位宽是4bits
reg [3:0] rdata;
reg [7:0] i;
//写入RAM
always @(posedge clk or negedge rst) begin
if(!rst)
for(i=0;i<=8'd127;i=i+1)
data[i] = 0;
else
data[addr]= enb? w_data:data[addr]; //将数据指向一个地址
end
//读取RAM 这里一开始写成了时序电路,按答案来说,应该是当enb使能信号为0时读取数据,此时地址是什么就读出什么,不需要时序电路
//而写入数据的时候,enb=1,随着输入地址和数据,在上升沿来时进行存储,必须为时序电路。
always @(*) begin
if(~rst)
rdata = 0;
else
rdata = ~enb? data[addr]: rdata;
end
assign r_data = rdata;
//*************code***********//
endmodule边栏推荐
- 使用阿里云免费的SSL证书
- UNIQUE VISION Programming Contest 2022(AtCoder Beginner Contest 248)G. GCD cost on the tree
- How to use fail2ban to protect WordPress login page
- Visual Studio 2015 团队开发之Azure DevOps篇
- Atcoder regular contest 133 d.range XOR (digital dp+ classification discussion)
- Goweb开发之Iris框架实战:项目总结与回顾
- Codeforces round 768 (Div. 2) e.paint the middle (greedy / interval relationship processing)
- 高速电路中电阻的选择
- MySQL详细学习教程(建议收藏)
- Create a self-organizing / safe / controllable Lora network! Semtech responded for the first time to the impact of the "new regulations of the Ministry of industry and information technology"
猜你喜欢

我为什么选择使用Go语言?

火了 2 年的服务网格究竟给微服务带来了什么?(转载)

配置V530交换机步骤

Unity shader realizes mirror effect with rendered texture

Goweb开发之Beego框架实战:第三节 程序执行流程分析

The practice of beego framework developed by goweb: Section 4 database configuration and connection

MySQL数据库增删改查(基础操作命令详解)

: No such file or directory

kubernetes service 原理解析

How to protect image security during construction
随机推荐
Some attention code explanations
Goweb开发之Beego框架实战:第四节 数据库配置及连接
Round 1C 2022 - Code jam 2022 b.square (Mathematics, thinking)
Steps to configure V530 switch
《Kubernetes》你需要掌握的 Service 和 Ingress
SUSE CEPH rapid deployment – storage6
Hikvision responded to the impact of the 'US ban': there are options for the components currently used
Atcoder regular contest 133 d.range XOR (digital dp+ classification discussion)
Algorithm learning: leetcode interview question 09. implement queue with two stacks
我为什么选择使用Go语言?
22年多校第三场(F的证明
Comprehensively design an oppe homepage -- page service part
CNSA与CASC和CASIC的区别
GEAR: Graph-based Evidence Aggregating and Reasoning for Fact Verification
Learn about service discovery in kubernetes
Verilog 每日一题(VL6 数据串转并电路)
Difference between reconnaissance aircraft and early warning aircraft
Andthen of function interface
线性代数及矩阵论(九)
Realization of reflection and refraction effect in unity shader cube texture