- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks amilcar, how do I assign the parameter within the code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
after the memory instantiation add:
defparam ram_inst.altsyncram_component.init_file = "your_file_here.mif";- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 :)

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page