【问题标题】:Quartus Failure for initialization ROM memory by using $readmemh task使用 $readmemh 任务初始化 ROM 内存的 Quartus 失败
【发布时间】:2022-09-27 22:15:05
【问题描述】:

我使用 $readmemh 任务初始化了我的 ROM 内存(instr_mem)。 ROM编译成功,仿真成功,但instr_mem中波形显示32\'hxxxxxxxx。似乎 \'instr_mem\' 没有从 mem_instruction.txt 文件中获取值。

更新: instr_mem 的内容可以通过 $display 值打印出来。编译器似乎成功读取了“mem_instruction.txt”文件。

module mips_mem(addr1,data_in1,data_out1,we1,
    addr2,data_in2,data_out2,we2,
    rst_b,clk);

// Boundaries and lengths of each segment
// Note that \'_top\' addresses off by one; the actual top is one less
//      than the values below.
// \'_w\' values are word addresses

input         rst_b;
input         clk;

// Inputs and ouptuts: Port 1
input [5:0]  addr1;         // Memory address
input [31:0]  data_in1;      // Memory write data
output [31:0] data_out1;     // Memory read data
reg [31:0]   data_out1;
input [0:3]      we1;           
     

// Inputs and outputs: Port 2
input [5:0]  addr2;         // Memory address
input [31:0]  data_in2;      // Memory write data
output [31:0] data_out2;     // Memory read data
reg [31:0]   data_out2;
input [0:3]  we2;          


// Memory segments
reg [31:0]   data_mem[0:63];
reg [31:0]   instr_mem[0:63];

 // Verilog implementation stuff
 integer     i;
 wire [31:0] write_mask1 = {we1[3], we1[3], we1[3], we1[3],
                  we1[3], we1[3], we1[3], we1[3],
                we1[2], we1[2], we1[2], we1[2],
                we1[2], we1[2], we1[2], we1[2],
                we1[1], we1[1], we1[1], we1[1],
                we1[1], we1[1], we1[1], we1[1],
               we1[0], we1[0], we1[0], we1[0],
              we1[0], we1[0], we1[0], we1[0]};


// Handle Port 1 Read
initial
 begin

$readmemh(\"mem_instruction.txt\", instr_mem);
 end
always @(posedge clk or negedge rst_b) begin
     if(rst_b==1\'b0) begin
          data_out1 <= 32\'hxxxxxxxx;  
      end
      else begin
          data_out1 <=instr_mem[addr1];
      end
 end

端模块

试验台

`timescale 1ns/100ps

 module testbench;

 reg [31:0] i;
 reg [29:0] addr;
 reg           rst_b;
 wire halted;

  //parameter
  parameter start = 0, halfPeriod = 50;
  reg        clk;
  // The clock
  initial
    clk = start;

   always
    #halfPeriod clk = ~clk;

   // The mips_top core
   mips_top inst_mips(.clk(clk), .rst_b(rst_b), .halted(halted));

  initial
    begin
  rst_b = 0;
   #75;
   rst_b <= 1;
    end

  always @(halted)
    begin
  #0;
    if(halted === 1\'b1)
     $finish;
    end


  endmodule

波形截图 enter image description here enter image description here

  • 您发布的代码看起来不错。发布测试台代码和几行自述文件输入文件,以便我们可以运行 sim:minimal reproducible example

标签: verilog system-verilog fpga quartus intel-fpga


【解决方案1】:

将此代码片段添加到 mips_mem 模块以确定内存样式变量是否正在获取文件内容。

initial
 foreach(instr_mem[i])
  $display("instr_mem[%0d] = %0h",i,instr_mem[i]);

如果这打印内存内容,那么它不是文件位置的问题(另一个问题??)。

如果这打印 x's 那么问题可能是模拟器需要帮助来查找文件。
使用 simlink 链接到执行仿真的目录中的 .txt 文件。

【讨论】:

  • 嗨,非常感谢你。是的,我将您的代码包含在 mips_mem 模块中。内存内容被打印出来。
  • 似乎 mem_instruction.txt 已成功包含在设计中。
  • 所以有一个不同的问题。由于 rst_b 被断言且从未释放,因此设计可以保持在复位状态。时钟可能不会翻转。信号 addr1 可能不会被驱动。接下来检查这些东西。发布您的测试平台将帮助我们帮助您缩小范围。
  • 1. 设计中的“rst_b”信号低电平有效。在第一个时钟之后,它在整个仿真时间内被驱动为逻辑 1。
  • 1. 设计中的“rst_b”信号低电平有效。在第一个时钟之后,它在整个仿真时间内被驱动为逻辑 1。 2. 时钟在模拟中切换。 3)addr1 被驱动到 6'd0。
猜你喜欢
  • 2019-06-05
  • 1970-01-01
  • 1970-01-01
  • 2018-07-17
  • 1970-01-01
  • 2015-01-15
  • 1970-01-01
  • 1970-01-01
  • 2016-03-25
相关资源
最近更新 更多