0

When I was config pll_reconfig module in Quartus II, the generate for statement in design have to specify different string parameter (filenames) to different instances. I have tried these code:

genvar i;
generate 
   for (i=0; i<2; i=i+1) begin:u
      rom #($sformatf("mif%d.mif",i)) U(
         //signals connected.
      );
   end
endgenerate

It is said that the code is not synthesizable. How can I specify variable string parameter in generate for block?

3
  • 1
    Would you not be better creating an array of strings and just selecting s[i], or I think you can concatenate strings with {} some thing like {"mif", i, ".mif"}.
    – Morgan
    Commented Jun 27, 2013 at 10:21
  • but loop variable "i" must be convertted into string, before that. Commented Jun 28, 2013 at 2:11
  • Strings are not synthesizable. Can you share your rom module with us? It will help us understand how you intend to use the parameter?
    – Greg
    Commented Jul 1, 2013 at 16:13

1 Answer 1

1

I had a similar problem but on a system that did not support $sformatf. My solution is a little dirty but may help others:

genvar i;
generate
  for (i=0; i<10; i=i+1)
  begin
    mymodule #(.NAME("NAME0" + i) instance(.RESET(mreset) ... );
  end
endgenerate

This works, I believe, by treating the string "NAME0" as a number (a 40-bit number). By adding i, you just increase the value by i and the result is the last ASCII char changes. Luckily '0' + i gives you '1', '2', '3' etc

The obvious flaw is this only works for 0-9, however there is a simple extension using divide and modulo arithmatic:

mymodule #(.NAME("NAME00" + (256 * (i / 10)) + (i % 10) ) ) ...

As a side note, I ran into issues using string concatenation {"NAME", i} because Verilog was treating i as 32-bit value so the string ends up as:

NAME   1

due to the extra 'unwanted' 24 bits which equate to 3 null characters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.