当前位置:网站首页>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边栏推荐
- Some notes on how unity objects move
- The practice of beego framework developed by goweb: Section 4 database configuration and connection
- Hikvision responded to the impact of the 'US ban': there are options for the components currently used
- Go language slow entry - process control statement
- Easypoi --- excel file export
- Make full use of English
- Vscode界面介绍
- Net framework
- WPF command button transparent style
- The 2021 ICPC ASIA Taipei Regional programming contest L. leadfoot (combinatorics /2-adic assignment function +kummer theorem)
猜你喜欢
随机推荐
2021年4月份自考
wpf命令按钮透明样式
Unity shader global fog effect
Leetcode 2022.04.10 China Merchants Bank special competition D. store promotion (DP)
Verilog 每日一题(VL6 数据串转并电路)
Fine-grained Fact Verification with Kernel GA Network
Net framework
Difference between reconnaissance aircraft and early warning aircraft
System clock failure of database fault tolerance
Unity shader texture animation
CNSA与CASC和CASIC的区别
数据库故障容错之系统时钟故障
GEAR: Graph-based Evidence Aggregating and Reasoning for Fact Verification
Differences between CNSA and CASC and CASIC
The actual combat of the beego framework of goweb development: Section III program execution process analysis
After paying $1.8 billion in royalties to Qualcomm, Huawei reportedly ordered 120million chips from MediaTek! Official response
Comprehensively design an oppe homepage -- page service part
Re10: are we really making much progress? Revisiting, benchmarking, and refining heterogeneous gr
Goweb开发之Beego框架实战:第四节 数据库配置及连接
Ugui learning notes (I) rendering level









