Skip to content

Quartus can't infer RAM memory blocks when preloading data from file #1

@Oxore

Description

@Oxore

Hi!

I am using DE0-nano board with Cyclone IV chip. It turns out that Quartus is not able to infer RAM blocks and it performs LAB-based synthesis for this memory implementation. I tried to use (* ramstyle = "M9K" *) attribute and create assignments of type "Infer RAMs from Raw Logic" for wb_ram_generic in Assignment Editor, but no luck.

I found out that this by-byte writing implementation in wb_ram_generic.v causes the problem:

   reg [31:0] 	 mem [0:depth-1];

   always @(posedge clk) begin
      if (we[0]) mem[waddr][7:0]   <= din[7:0];
      if (we[1]) mem[waddr][15:8]  <= din[15:8];
      if (we[2]) mem[waddr][23:16] <= din[23:16];
      if (we[3]) mem[waddr][31:24] <= din[31:24];
      dout <= mem[raddr];
   end

If I implement writing the whole four bytes as single action, by any of we signals, then I get proper RAM inferring in Quartus. No additional verilog attributes or assignments are needed. I actually decided to stick with this option for my purposes:

  reg [31:0] 	 mem [0:depth-1];

  always @(posedge clk) begin
     if (|we)
        mem[waddr] <= din;
     dout <= mem[raddr];
  end

Also splitting mem in four 8-bit wide reg arrays works fine for memory inferring in Quartus, but then I can't find a way to load data from file using the $readmemh function:

   reg [7:0] 	 mem0 [0:depth-1];
   reg [7:0] 	 mem1 [0:depth-1];
   reg [7:0] 	 mem2 [0:depth-1];
   reg [7:0] 	 mem3 [0:depth-1];

   always @(posedge clk) begin
      if (we[0]) mem0[waddr] <= din[7:0];
      if (we[1]) mem1[waddr] <= din[15:8];
      if (we[2]) mem2[waddr] <= din[23:16];
      if (we[3]) mem3[waddr] <= din[31:24];
      dout <= {mem3[raddr], mem2[raddr], mem1[raddr], mem0[raddr]};
   end

I didn't test this implementation, because I don't know how to load my data in this case, but Quartus looks fine with it and shows pretty compact footprint in Chip Planner.

So, I don't know how to solve this problem properly, according to initial design intents, but anyway, I want this information to be available for anyone who face this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions