Forum Discussion

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

Memory Initialization File for multiple RAMs

Hi,

I'm new to FPGA development and maybe this question is simple, but I couldn't find an answer yet.

I am developing a system with multiple M4K memories which are instatiated inside a generate block over a genvar loop (I'm using Verilog and a Stratix II). For simulation I need them to be initialized with different data. I can specifiy a Memory Initialization File in the MegaWizard but this will initialize all memories with the same data. Is there an easy way to specify a different .mif for each memory?

5 Replies

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

    yes, slightly edit the generated file, and add a parameter to it.

    Then assign a different string to that parameter each time you instanciate it in the for loop.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    after the memory instantiation add:

    defparam ram_inst.altsyncram_component.init_file = "your_file_here.mif";
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Ok I got it so far. I am using the M4K memory within an other design unit. Here is the simplified code:

    module LocalMem(...);
    parameter cpuid = 0;
    M4K memory (
        .clock(clk),
        .data(m4k_data),
        .rdaddress(m4k_rdaddress),
        .wraddress(m4k_wraddress),
        .wren(m4k_wren),
        .q(m4k_q)
        );
    defparam memory.altsyncram_component.init_file = {"mem", cpuid, ".mif"};
    endmodule
    module TestLocalMem(...);
    LocalMem# (.cpuid(1)) localmem_inst(...);
    endmodule
    This does not work. Within the defparam line, cpuid seems to be empty. No matter what I set cpuid to, the file "mem.mif" gets loaded. I have also tried this to make cpuid the correct ASCII value:

    defparam memory.altsyncram_component.init_file = {"mem", 8'd48 + cpuid, ".mif"};
    but no change...

    Maybe you have another hint for me?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I found a solution :)

    In case someone has the same problem here is my solution:

    To have a parameter concatenated with a string, it needs to represent the number's ASCII value. Therefore 48 needs to be added to its value. An other thing has to be considered: all chars in a string are represented as 8-bit numbers, therefore the parameter has to be 8 bits wide:

    parameter  cpuid = 0;
    and

    defparam memory.altsyncram_component.init_file = {"mem", 8'd48 + cpuid, ".mif"};
    fixed my problem :)