Forum Discussion

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

Generate-for loop to reset array?

Using Modelsim, I can do this in some module:

...

reg [7:0] ram0 [63:0];

reg [7:0] ram1 [63:0];

reg [7:0] ram2 [63:0];

reg [7:0] ram3 [63:0];

wire strobe;

wire [7:0] addr;

wire [7:0] data;

integer i;

always @(posedge clock or negedge reset)

begin

if (~reset)

begin

for(i=0; i<64; i=i+1)

begin

ram0 <= 8'h0;

ram1 <= 8'h0;

ram2 <= 8'h0;

ram3 <= 8'h0;

end

end

else if (strobe)

case(addr[1:0])

2'h0: ram0[addr[7:2]] <= data;

2'h1: ram1[addr[7:2]] <= data;

2'h2: ram2[addr[7:2]] <= data;

2'h3: ram3[addr[7:2]] <= data;

default:;

endcase

end

...

No problem under Modelsim, and it simulates fine and inits the memory to all zeroes (or whatever I select). Since it can be synthesized with the loop unrolled, the loop should synthesize.

Under Quartus II 9.1, I get a warning about inferred latches on the variable "i". Bracketing the above with generate/endgenerate and/or using genvars just gets me piles of errors.

How, exactly, does one specify this kind of register array init using Quartus. Right now the only way to do this without any flags is to unroll the loop.

7 Replies

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

    The latch warnings for the variable "i" are bogus. This is an annoyance from Quartus synthesis that has been there for years. You can ignore it.

    Yeah the generate would not be appropriate here I don't think.

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

    You should consider, that introducing a reset action prevents implementation of the register file in internal RAM. A power on reset to zero or a defined content is possible, however.

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

    --- Quote Start ---

    You should consider, that introducing a reset action prevents implementation of the register file in internal RAM. A power on reset to zero or a defined content is possible, however.

    --- Quote End ---

    That is quite the intent. This allows me to clock the register file on the (rare) writes and read it statically. Saves power, FWiW (and in the vanilla-version ASIC I'm modeling, it does matter). I actually intend to use the "strobe" signal as the clock, but simplified it here for clarity.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    The latch warnings for the variable "i" are bogus. This is an annoyance from Quartus synthesis that has been there for years. You can ignore it.

    Yeah the generate would not be appropriate here I don't think.

    Jake

    --- Quote End ---

    Thanks. I'll ignore it then.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I will second FvM's counsel. If you are trying to infer a RAM block, you need to remove the reset condition.

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

    As I said I am NOT desiring a RAM block. Quite the contrary. I want a register file so that I can read the array via an unclocked mux.

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

    for-loops are often used as a short form to reduce the length of repetitive but parallel code segments.