当前位置:网站首页>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边栏推荐
- Goweb开发之Beego框架实战:第五节 项目搭建及注册用户
- Codeworks round 801 (Div. 2) and epic Institute of technology round D. tree queries (tree DP)
- Unity3d shader achieves ablation effect
- Unity shader realizes water wave effect with noise texture
- Goweb开发之Beego框架实战:第二节 项目初始化配置
- Jupyter notebook win installation record
- Detailed steps for setting up SUSE storage6 environment – win10 + VMware Workstation
- The practice of the beego framework for goweb development: Section V project construction and user registration
- valarray数值库学习
- influxdb2的使用
猜你喜欢

22年多校第三场(F的证明

The 16th program design competition of Dalian University of Technology (Problem Solver)

利用SQL Server代理作业对数据库进行定时还原

Problem solution of code heartstrings Junior Group (official competition) of Dalian University of Technology (Development Zone campus) in 2021

在android开发过程中遇到.sqlite文件处理

Microservice Architecture - service registry and service gateway (6.8) (Reprint)

How do we do full link grayscale on the database?

The practice of the beego framework for goweb development: Section V project construction and user registration

Unity3d shader achieves ablation effect

数据库故障容错之系统时钟故障
随机推荐
总数据量超万亿行,玉溪卷烟厂通过正确选择时序数据库轻松应对
高速电路中电阻的选择
Unity3d shader achieves ablation effect
微服务架构-服务注册中心和服务网关(6.8) (转载)
Goweb开发之Beego框架实战:第五节 项目搭建及注册用户
Educational codeforces round 126 (rated for Div. 2) f.teleporters (two sets and two points)
批量下载文件
valarray数值库学习
Atcoder regular contest 133 d.range XOR (digital dp+ classification discussion)
HTAP comes at a price
Mysql database addition, deletion, modification and query (detailed explanation of basic operation commands)
Realize the reset function of steering wheel UI with touch rotation and finger departure in unity
What does the service grid that has been popular for two years bring to microservices? (Reprinted)
2022牛客多校第二场CDE
线性代数及矩阵论(十)
Valarray Library Learning
The 2021 ICPC ASIA Taipei Regional programming contest L. leadfoot (combinatorics /2-adic assignment function +kummer theorem)
SUSE CEPH add nodes, reduce nodes, delete OSD disks and other operations – storage6
Codeforces round 770 (Div. 2) e. fair share
Unity shader transparent effect