Forum Discussion

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

how to pass a file name in a generate loop

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

2 Replies

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

    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).