Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

how to read the memory initialized by "lpm_ram_dq"

If I have a block of memory initialized by an instance of lpm_ram_dq.

// instantiating lpm_ram_dq

lpm_ram_dq ram (.data(datain), .address(addr), .we(we), .inclock(inclk), .outclock(outclk), .q(dataout));

If I want to read out data at "addr (e.g. addr = 2)" to an output variable outdata using nonblocking assignment, how should do it? Is there a similar format like "outdata <= mem[2]" or "assign outdata = mem[2]"?

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    If I have a block of memory initialized by an instance of lpm_ram_dq.

    // instantiating lpm_ram_dq

    lpm_ram_dq ram (.data(datain), .address(addr), .we(we), .inclock(inclk), .outclock(outclk), .q(dataout));

    If I want to read out data at "addr (e.g. addr = 2)" to an output variable outdata using nonblocking assignment, how should do it? Is there a similar format like "outdata <= mem[2]" or "assign outdata = mem[2]"?

    --- Quote End ---

    In case if you havent solved the above problem, here is my suggestion. I believe you instantiate the lpm_ram_dq in a custom module, for e.g. as in the following code fragment:

    module LPM_RAM_DQ_1024_16_DM (din, dout, addr, clk, wr, outdata);

    parameter width = 16;

    parameter depth = 10;

    input clk, wr;

    input [depth-1:0] addr;

    input [width-1:0] din;

    output [width-1:0] dout, outdata;

    wire high;

    assign high = 1;

    lpm_ram_dq myRAM (.data(din),

    .q(dout),

    .address(addr),

    .we(wr),

    .inclock(clk),

    .outclock(high));

    defparam myRAM.lpm_width = width;

    defparam myRAM.lpm_widthad = depth; // 2^10 = 1024 addresses

    defparam myRAM.lpm_indata = "REGISTERED";

    defparam myRAM.lpm_outdata = "UNREGISTERED";

    defparam myRAM.lpm_file = "RAM_1024_16bits.mif";

    assign outdata = dout;

    endmodule

    i.e. use the assign statement to point your outdata output to the lpm_ram_dq .q output