Forum Discussion

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

Initialize ram block with different filename using generate loop.

I want to generate several instance of ram block and initialize it with different filename in Quartus II (Verilog 2001)

It seems that verilog does not support 2D parameter array, and part select on parameter is also not supportted.

How to solve this problem?

I find somebody has asked similar problem in VHDL, here http://www.alteraforum.com/forum/showthread.php?t=40003.

And in Xilinx community Verilog also, http://forums.xilinx.com/t5/new-users-forum/intializing-different-block-ram-instances-created-from-a/td-p/222139

(http://forums.xilinx.com/t5/new-users-forum/intializing-different-block-ram-instances-created-from-a/td-p/222139)In the post above, the author using some commented code.

I don't know whether it is applicapable in Quartus, and how to use like that?

4 Replies

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

    --- Quote Start ---

    How to solve this problem?

    --- Quote End ---

    If you were writing VHDL, I would recommend writing a function that takes the loop parameter (integer) and returns a string. I'm sure the same is possible with Verilog/SystemVerilog.

    Cheers,

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

    --- Quote Start ---

    If you were writing VHDL, I would recommend writing a function that takes the loop parameter (integer) and returns a string. I'm sure the same is possible with Verilog/SystemVerilog.

    Cheers,

    Dave

    --- Quote End ---

    Perhaps the constant function is a solution, but how can i convert the loop parameter into string?

    I found the $sformatf can do that, but the system function is not available in constant function.

    Can you give me a short example on that?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    $sformatf will work as a constant function as long all of its arguments are constants in Modelsim.

    The alternative is to have the generate loop block of code execute the code that does the initialization, then it doesn't need to be a constant.

    genvar I;
    for (I=0;i<NUM;i++) begin : block
      RAM inst(...);
      initial $readmemh($sformatf("file%2d.dat",I),inst.mem_inst);
    end : block
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    i need a synthesible code not a test bench&#65292;the ram block is used for pll reconfig module which can be initialized by mif files