Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17267 Discussions

Memory Initialization File for multiple RAMs

Altera_Forum
Honored Contributor II
2,075 Views

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?
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
985 Views

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.
0 Kudos
Altera_Forum
Honored Contributor II
985 Views

Thanks amilcar, how do I assign the parameter within the code?

0 Kudos
Altera_Forum
Honored Contributor II
985 Views

after the memory instantiation add: 

defparam ram_inst.altsyncram_component.init_file = "your_file_here.mif";
0 Kudos
Altera_Forum
Honored Contributor II
985 Views

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(...); endmoduleThis 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?
0 Kudos
Altera_Forum
Honored Contributor II
985 Views

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 :)
0 Kudos
Reply