Verilog代码故障排除,部分写入过程中的数据丢失,然后在内存模块中进行读取操作

时间:2019-05-07 04:07:12

标签: verilog

因此,对于一项作业,我必须使用现有的内存模块创建一个内存模块。我需要打开一个将ram64x8存储到ram128x16的模块。当我尝试从内存中读取或写入时,我将丢失一半的存储数据。我不确定我的问题在哪里。我确实知道它应该在我的模块ram128x16中,因为我为ram64x8模块编写了一个测试平台,并且所有内容均可正确读写。有人能弄清楚为什么当我尝试将FFFF存储到数据中时,它只会读出00FF吗? 所以我的思考过程是因为我需要两个模块,为什么不只做16x8模块的工作,将地址和数据分成两半。不是吗?

根据这里的提示,我用完成的操作更新了当前代码,但是我仍然对如何管理地址感到困惑。

这些是模块

module ram128x16(
  input [6:0] adrs,
  inout [15:0] data,
  input _ce, _we, _oe

);
  reg [3:0] _cee;

  ram64x8 u1(adrs[5:0], data[15:8], _cee[0], _we, _oe);
  ram64x8 u2(adrs[5:0], data[7:0], _cee[0], _we, _oe);

  ram64x8 u3(adrs[5:0], data[15:8], _cee[1], _we, _oe);
  ram64x8 u4(adrs[5:0], data[7:0], _cee[1], _we, _oe);


  ram64x8 u5(adrs[5:0], data[15:8], _cee[2], _we, _oe);
  ram64x8 u6(adrs[5:0], data[7:0], _cee[2], _we, _oe);


  ram64x8 u7(adrs[5:0], data[15:8], _cee[3], _we, _oe);
  ram64x8 u8(adrs[5:0], data[7:0], _cee[3], _we, _oe);


  //1 - to - 2 decode
  always @ (*)
begin
    if(_ce == 0)
      case(adrs[6:5])
    0: _cee = 4'b1110;
    1: _cee = 4'b1101;
    2: _cee = 4'b1011;
    3: _cee = 4'b0111;
    default: _cee = 4'hf;
    endcase
    else
        _cee = 4'hf;
end
  endmodule


module ram64x8(
    input [5:0] adrs,
    inout [7:0] data,
    input _ce, _we, _oe
);
  reg [3:0] _cee;
ram16x8 u1(adrs[3:0], data, _cee[0], _we, _oe);
ram16x8 u2(adrs[3:0], data, _cee[1], _we, _oe);
ram16x8 u3(adrs[3:0], data, _cee[2], _we, _oe);
ram16x8 u4(adrs[3:0], data, _cee[3], _we, _oe);
//2 - to - 4 decode
always @ (*)
begin
    if(_ce == 0)
    case(adrs[5:4])
    0: _cee = 4'b1110;
    1: _cee = 4'b1101;
    2: _cee = 4'b1011;
    3: _cee = 4'b0111;
    default: _cee = 4'hf;
    endcase
    else
        _cee = 4'hf;
end
endmodule

module ram16x8(
    input [3:0] adrs,
    inout [7:0] data,
    input _ce, _we, _oe
);

    ram16x4 u1(adrs, data[7:4], data[7:4], _ce, _we, _oe);
    ram16x4 u2(adrs, data[3:0], data[3:0], _ce, _we, _oe);

endmodule

module ram16x4(
    input [3:0] adrs,
    input [3:0] dataIn,
    output [3:0] dataOut,
    input _ce, _we, _oe
);
  reg [3:0] mem[0:15]; // 16 X 4 ram
assign dataOut = ~_ce & _we & ~_oe ? mem[adrs]:4'hz;
always@(*)
begin
if(_ce==0)
    if(_we == 0 && _oe ==1)
        mem[adrs] = dataIn;
end
endmodule

这是我的测试台

module ram();

  reg [11:0] adrs;
  reg [15:0] content;
  reg _ce, _we, _oe;
  wire [15:0] data;
  assign data = ~_ce & ~_we & _oe ? content : 16'hz;
  ram128x16 u1(adrs, data, _ce,_we,_oe);
  initial begin
    $monitor ("%4d: adrs = %h _ce + %b _we = %b _oe = %b data =%h", $time, adrs, _ce, _we, _oe, data);

    adrs = 12'd0; 
    content = 16'd0;
    _ce = 1'b0; _we = 1'b0; _oe = 1'b1;
    #10
    _ce = 1'b1; _we = 1'b1; _oe = 1'b1;
    #50
    adrs = 12'b011111; 
    content = 16'hFFFF;
    _ce = 1'b0; _we = 1'b0; _oe = 1'b1;
    #10
    _ce = 1'b1; _we = 1'b1; _oe = 1'b1;
    #40
    adrs = 12'b100000; 
    content = 8'd0387+127;
    _ce = 1'b0; _we = 1'b0; _oe = 1'b1;
    #10
    _ce = 1'b1; _we = 1'b1; _oe = 1'b1;
    #40
    adrs = 12'b110000; 
    content = 8'd0387-127;
    _ce = 1'b0; _we = 1'b0; _oe = 1'b1;
    #10
    _ce = 1'b1; _we = 1'b1; _oe = 1'b1;
    #40

    //read

    adrs = 12'b000000; 
    _ce = 1'b0; _we = 1'b1; _oe = 1'b0;
    #10
    _ce = 1'b1; _we = 1'b1; _oe = 1'b1;
    #50
    adrs = 12'b011111; 
    _ce = 1'b0; _we = 1'b1; _oe = 1'b0;
    #10
    _ce = 1'b1; _we = 1'b1; _oe = 1'b1;
    #40
    adrs = 12'b100000; 
    _ce = 1'b0; _we = 1'b1; _oe = 1'b0;
    #10
    _ce = 1'b1; _we = 1'b1; _oe = 1'b1;
    #40
    adrs = 12'b110000; 
    _ce = 1'b0; _we = 1'b1; _oe = 1'b0;
    #10
    _ce = 1'b1; _we = 1'b1; _oe = 1'b1;
    #40


    $finish;



end


endmodule

1 个答案:

答案 0 :(得分:1)

您需要从一些基本数学开始。

您具有64x8位的内存。就是512位。
您需要128x16位的内存。那是2048位。

因此,您需要四个 64x8的内存来获得该位数。

您必须进行两种类型的扩展:

  1. 从8位宽扩展到16位宽的宽度扩展。
  2. 深度扩展从64深度扩展到128深度。

第一个要求您并行使用内存。
第二个要求您“顺序”使用内存。

在您的代码中,通过并行放置两个内存,您完成了宽度扩展。但是,您的地址位完全混乱了。

提出所有建议后,我会把剩下的留给您,因为我怀疑这是家庭作业。

相关问题