深度为16,位宽8bit的单端口SRAM——学习记录

链接:

【Verilog HDL 训练】第 13 天(存储器、SRAM)-云社区-华为云

复制代码
 module sram #(
      parameter ADDR_BITS=4
      )(
      input clk,
      input [ 7:0] addr,
      input [ 7:0] din,
      input ce,
      input we,
      output reg [ 7:0] dout
      );
      localparam MEM_DEPTH= 1<<ADDR_BITS;
      reg [7:0] mem[MEM_DEPTH-1:0];
      // synopsys_translate_off
      integer i;
      initial begin
      for(i=0; i<MEM_DEPTH;i=i+1) begin
      mem[i] = 8'h00;
      end
      end
      // synopsys_translate_on
      always @(posedge clk) begin
      if(ce & we) begin
      mem[addr] <= din;
      end
      end
      always @(posedge clk) begin
      if(ce && (!we)) begin
      dout <= mem[addr];
      end
      end
      endmodule

`timescale 1ns / 1ps
      //
      // Company: 
      // Create Date: 2019/05/16 21:04:57
      // Design Name: 
      // Module Name: SRAM_tb
      //
      module sram_tb(
      );
     	reg [7 : 0] addr;
     	reg [7 : 0]data_in;
     	reg clk;
     	reg we;
     	reg ce;
     	wire [7 : 0] data_out;
     	integer i;
     	//clock generation
     	initial begin
     		clk = 0;
     		forever
       #4 clk = ~clk;
     	end
     	initial begin
     		ce = 1'b0;
     		we = 1'b0;
     		addr = 4'd0;
     		data_in = 8'h00;
       #20
     		@(negedge clk)//read
     		ce = 1'b1;
     		for (i = 0; i<16; i=i+1) begin
     			@(negedge clk)
      addr = i;
     		end
     		@(negedge clk)//write
     			we = 1'b1;
     		for (i = 0; i<16; i=i+1) begin
     			@(negedge clk) begin
      addr = i;
      data_in = data_in + 'h01;
     			end
     		end
     		@(negedge clk)//read
     			we = 1'b0;
     		for (i = 0; i<16; i=i+1) begin
     			@(posedge clk)
      addr = i;
     		end
     		@(negedge clk)
     			ce = 1'b0;
     		 //#100 $finish;
       #100 $stop;
     	end
     	sram #( .ADDR_BITS(4) ) u_sram(
     	.clk(clk),
     	.ce(ce),
     	.we(we),
     	.addr(addr),
     	.din(data_in),
     	.dout(data_out)
     	);
      endmodule
相关推荐
I'm a winner1 小时前
【IP核】 Xilinx FPGA LVDS 高速接口,含验证工程与板级测试用例
tcp/ip·fpga开发·测试用例
I'm a winner3 小时前
基于Xilinx FPGA的LVDS高速串行通信系统 - 完整源码解决方案(一)(文末附源码)
fpga开发
国科安芯4 小时前
航天器多路并联大功率电源系统设计与ASP4644均流特性分析
单片机·嵌入式硬件·fpga开发·安全性测试
茯苓gao6 小时前
嵌入式开发笔记:CANopen相关移位运算与通信协议术语详解
网络·嵌入式硬件·学习·信息与通信
HERR_QQ9 小时前
强化学习的数学原理 学习笔记
人工智能·笔记·学习·自动驾驶
MartinYeung510 小时前
[论文学习]DP-Fusion:面向大语言模型的令牌级差分隐私推理-深度解析
人工智能·学习·语言模型
zwenqiyu11 小时前
非线性字符串数据结构串讲
数据结构·c++·学习·算法
MartinYeung512 小时前
[论文学习]SecureGate:通过令牌级门控学习何时安全地揭示PII-深度解析
学习·安全
大鱼>13 小时前
超参数调优进阶:Optuna/Bayesian/Early Stopping
人工智能·学习·机器学习·聚类
liuyicenysabel13 小时前
多服务上线日记二:
服务器·笔记·学习