title: SystemVerilog assigning values to generated blocks
body: <p>So I've used generate statements to make some oscillators in a testbench that I've been working on.</p>
  
  <p>I also have an array of reals called OSC_PER where each element in the array is the period in ns for the oscillator.</p>
  
  <p>I've been trying to make my testbench work such that I give it a parameter (number of devices to test) and the generate statements in my testbench and simulation go out, instantiate the modules and wire everything up. So far, this has been going well, but I think I've ran into a wall with assigning the periods to my oscillators.</p>
  
  <pre><code>generate
    for(i=1; i&lt;=num_duts; i++)
    begin: generate_my_oscillators
      osc osc_c_osc( .en(osc_en[i]), .out(osc_c[i]));
    end
  endgenerate
  </code></pre>
  
  <p>So here's how I've tried to assign the values:</p>
  
  <pre><code>foreach(OSC_PER[i])
    generate_my_oscillators[i].osc_c_osc.per = OSC_PER[i];
  </code></pre>
  
  <p>This gives me a NOTPAR error; I guess it's illegal to try and iterate over the instance number outside of a genvar statement. Okay, so maybe I can be brute and just lay it all out manually:</p>
  
  <pre><code>generate_my_oscillators[1].osc_c_osc.per = OSC_PER[1]
  if(number_devices &gt;= 2)
  generate_my_oscillators[2].osc_c_osc.per = OSC_PER[2]
  if(number_devices &gt;= 3)
  generate_my_oscillators[3].osc_c_osc.per = OSC_PER[3]
  .
  .
  .
  </code></pre>
  
  <p>However, if I have number_devices = 2, then on the third conditional, I get CUVFGS (Invalid for-generate index) followed by a CUVUNF (failure to lookup the component name for the third device).</p>
  
  <p>If I have values I want to assign to each instance of the oscillator being generated, how should I go about doing that? I'm a little stumped at this point. Maybe I can have it assigned in the generate-for loop?</p>
  
  <p><strong>EDIT</strong>: I've tried some more things:</p>
  
  <p>If I move over the definitions of OSC_PER to my testbench and attempt to assign the value of the period in the generate statement like this I get EXPEND "Expecting keyword 'end'":</p>
  
  <pre><code>generate
    for(i=1; i&lt;=num_duts; i++)
    begin: generate_my_oscillators
      osc osc_c_osc( .en(osc_en[i]), .out(osc_c[i]));
      .per = OSC_PER[i];
    end
  endgenerate
  </code></pre>
  
  <p>Okay, I tried this:</p>
  
  <pre><code>generate
    for(i=1; i&lt;=num_duts; i++)
    begin: generate_my_oscillators
      osc osc_c_osc( .en(osc_en[i]), .out(osc_c[i]));
      osc_c_osc.per = OSC_PER[i];
    end
  endgenerate
  </code></pre>
  
  <p>... and I get EXPLA: expecting left parenthesis. </p>
  
  <p>period is an internal signal in each osc, so I cannot place it as such:</p>
  
  <pre><code>generate
    for(i=1; i&lt;=num_duts; i++)
    begin: generate_my_oscillators
      osc osc_c_osc( .en(osc_en[i]), .out(osc_c[i]), .per(OSC_PER[i]);
    end
  endgenerate
  </code></pre>
  
  <p>If I do, I get CUVPOM: Port name 'per' is invalid or has multiple connections.</p>
  
  <p>Now I'm really out of ideas. Any suggestions?</p>