Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17267 Discussions

how to pass a file name in a generate loop

Altera_Forum
Honored Contributor II
1,758 Views

Hi,  

I need to instantiate the same module many times, so I'm using a for-generate loop. Each time, however, I've to pass to the module a different file name as a GENERIC to initialize a rom inside the module.  

The file name is function of the i parameter in the generate loop ... so I wrote this code in quartus (vhdl 2008) but I get errors ... can you help to write it in the right way ? 

 

ENGINES : -- engine instantiation 

for i in 0 to ENGINES_NUMBER-1 generate 

 

variable mystringnumber: string (1 to 4); 

variable romfile: string (1 to 30); 

begin 

 

mystringnumber := (to_string(i)); 

romfile := ("./roms/weight_lay0_engine" & mystringnumber & ".hex"); 

 

 

ENGINE_inst : entity work.engine  

GENERIC MAP (ENGINE_WEIGHT_FILE => romfile)  

PORT MAP  

(CLOCK => CLOCK, 

RESET => RESET, 

HITDATA => HITDATA, 

ACC => ACC_ENG(i), 

INTER_X => ENGINE1_INTER_X, 

INTER_Y => ENGINE1_INTER_Y); 

end generate ENGINES; 

 

 

thanks  

 

franco
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
875 Views

the string values need to be a constant. So you need to decalre romfile as such. The bast way would be: 

 

constant romfile : string := "./roms/weight_lay0_engine" & integer'image(i) & ".hex"; 

 

and put this before the begin like you have done with the variables; you cannot put variables where you have them - you can only use variables inside processes, functions and procedures. You dont need to declare the length of the string because it's implicitly declared with the length of the declaration. 

 

You could use the to_string function instead of integer'image, but Quartus doesnt support them yet (but modelsim does).
0 Kudos
Altera_Forum
Honored Contributor II
875 Views

Hi tricky thanks a lot, it works perfectly 

thanks again 

franco
0 Kudos
Reply