当前位置:网站首页>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边栏推荐
- Why do I choose to use go language?
- Classroom attendance system based on QT design (using RDS for MySQL cloud database)
- Iris framework practice of goweb development: project summary and review
- In 2020q2, shipments in the global tablet market soared by 26.1%: Huawei ranked third and Lenovo increased the most!
- 带参数的微信小程序二维码生成
- Algorithm learning: leetcode interview question 09. implement queue with two stacks
- Modeling Semantics with Gated Graph Neural Networks for KBQA
- Using MVC in the UI of unity
- Educational codeforces round 126 (rated for Div. 2) f.teleporters (two sets and two points)
- Unity shader uses rendered texture to achieve glass effect
猜你喜欢

Realize the reset function of steering wheel UI with touch rotation and finger departure in unity

Unity shader uses rendered texture to achieve glass effect

Round 1C 2022 - Code jam 2022 b.square (Mathematics, thinking)

总数据量超万亿行,玉溪卷烟厂通过正确选择时序数据库轻松应对

Reasoning Over Semantic-Level Graph for Fact Checking

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

Unity shader transparent effect

Re10: are we really making much progress? Revisiting, benchmarking, and refining heterogeneous gr

Why do I choose to use go language?

飞马D200S无人机与机载激光雷达在大比例尺DEM建设中的应用
随机推荐
Steps to configure V530 switch
Huawei mate 40 series exposure: large curvature hyperboloid screen, 5nm kylin 1020 processor! There will also be a version of Tianji 1000+
PostgreSQL weekly news - July 20, 2022
Record the processing process of CEPH two RBDS that cannot be deleted
Codeforces Round #750 (Div. 2) F.Korney Korneevich and XOR (easy&&hard version)(dp)
It is said that NVIDIA has held talks with Softbank and will offer more than US $32billion to acquire arm
Source code of voice live broadcast app
Classroom attendance system based on QT design (using RDS for MySQL cloud database)
Realize the reset function of steering wheel UI with touch rotation and finger departure in unity
Jupyter notebook win installation record
线性代数及矩阵论(十)
In 2020q2, shipments in the global tablet market soared by 26.1%: Huawei ranked third and Lenovo increased the most!
Android Development - set cache
Application of Pegasus d200s UAV and airborne lidar in large-scale DEM construction
Codeforces round 768 (Div. 2) e.paint the middle (greedy / interval relationship processing)
堡垒机的作用
2022牛客多校第二场CDE
高速电路中电阻的选择
Using MVC in the UI of unity
Verilog 每日一题(VL6 数据串转并电路)