【问题标题】:Can't see anything when accessing RAM contents in simulation在模拟中访问 RAM 内容时看不到任何内容
【发布时间】:2021-04-08 21:37:52
【问题描述】:

我在尝试设计 SRAM 内存时遇到了问题。更具体地说,内存有时钟,有一个写使能——高电平时,可以写数据,低电平时,可以读数据——地址输入,指定写入/读取数据的内存地址.然后,我创建了一个名为user的模块,方便写操作;因此,写入数据时无需提供内存地址。

我尝试模拟电路时出现问题,因为访问内存内容时看不到任何内容。在测试台中,我指定了一些要存储在内存中的值,然后,我提取了数据,但没有成功。

我在这里附上了代码。

//stores instructions
module sram_1port_instructions(
    input clk,//clocked memory
    input wr_en,//when high, data is writeen, otherwise is read
    input [15:0] address_in,//suppose timer cannot count more than 13ms
    input [2:0] wr_data,//3 bit instructions
    output reg [2:0] rd_data
);

reg [2:0] memory [2 ** 15 - 1 : 0];

always @(posedge clk) begin
    if(wr_en) memory[address_in] <= wr_data;
    else rd_data <= memory[address_in];
end

endmodule

//user interface designed for the first memory
module user(
    input clk,
    input wr_en,
    input [15:0] address_in,
    input [2:0] wr_data,
    output [2:0] rd_data
);

reg [15:0] pointer,address;

initial pointer = 16'd0;

sram_1port_instructions i0(.clk(clk),.wr_en(wr_en),.address_in(address_in),.wr_data(wr_data),.rd_data(rd_data));

always @(posedge clk) begin
    if(wr_en) begin
        address <= pointer;
        pointer <= pointer + 1;
    end 
    else address <= address_in;
end

endmodule

//user tb
module user_tb(
    output reg clk, wr_en, 
    output reg [15:0] address_in,
    output reg [2:0] wr_data,
    output [2:0] rd_data
);

user cut(.clk(clk),.wr_en(wr_en),.address_in(address_in),.wr_data(wr_data),.rd_data(rd_data));

initial $dumpvars(0,user_tb);

initial begin
    clk = 1'd1;
    repeat (2000)
    #100 clk = ~clk;
end

initial begin
    wr_en = 1'd1;
    #100000 wr_en = 1'd0;
end

integer i;

initial begin
    wr_data = 3'd0;
    for(i = 1;i < 500;i = i + 1) begin
    #200 wr_data = i;
    end
end

initial begin
    address_in = 16'd0;
    #100000 address_in = 16'd0;
    for(i = 1;i < 500;i = i + 1) begin
    #200 address_in = i;
    end
end

endmodule

【问题讨论】:

    标签: memory verilog simulation hdl icarus


    【解决方案1】:

    当我运行您的仿真并查看波形时,我在时间 100000 看到 rd_data=3。那时,您读取地址 0,这是您写入地址 0 的最后一个值。否则,您所有的读取其他地址返回 X(未知)。当您执行所有写入操作时,您只写入地址 0。从 time=0 到 time=100000、wr_en=1 和 address_in=0(在您的 sram_1port_instructions 模块内)。当您查看 VCD 文件中的波形时,您可以看到这一点。 wr_data 每个时钟周期都会改变,但你每个周期都写入同一个地址。

    但是,在user 中,如果您将address 信号连接到sram_1port_instructions 模块的to address_in 端口,您将写入不同的地址。

    变化:

    sram_1port_instructions i0(.clk(clk),.wr_en(wr_en),.address_in(address_in),.wr_data(wr_data),.rd_data(rd_data));
    

    到:

    sram_1port_instructions i0(.clk(clk),.wr_en(wr_en),.address_in(address),.wr_data(wr_data),.rd_data(rd_data));
    

    您的代码将常量address_in 信号连接到address_in 端口。

    当我进行更改时,我看到所有不同的值都从 RAM 中读取。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多