How to initialize RAM in Verilog?

Status
Not open for further replies.

littlestewie

Newbie level 4
Joined
Mar 8, 2012
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,306
Hi,
I am trying to initialize a RAM using the following code,but Quartus says

Error (276000): Cannot synthesize initialized RAM logic "ram:my_ram|mem"

Code:
initial
begin

$readmemh("init.dat",mem);


end

How can i initialize this RAM?Do i have to enter the 256 value by hand?
 

$readmem is said to be supported by Quartus. I guess there's something special with your design.
 

$readmem is said to be supported by Quartus. I guess there's something special with your design.



this is my module ,what may be wrong?

Code:
module ram(

address , // Address input
q    , // Data output
qin	,// Data input
we		//write enable
);
input [15:0] address;
output wire [7:0] q; 
input [7:0] qin;
input we;
           
reg [7:0] mem [0:255] ;  
//reg [7:0] q;    
reg [7:0] data_out;


  //$readmemb("memory.list", mem); // memory_list is memory file
  
  
  
  assign q = (!we) ? data_out:8'bz;
  
  
  always @ (  address or we)
begin
if (we)
begin
mem[address] = qin;
end
else 
begin
data_out = mem[address];
end

  
end

initial
begin

$readmemh("init.dat",mem);


end
endmodule
 

The error message is misleading. Your design doesn't infer block RAM with or without $readmem() because it's not a synchronous RAM description. You need something like this:

Code:
module ram(

address , // Address input
clk,
q    , // Data output
qin	,// Data input
we		//write enable
);
input [15:0] address;
output wire [7:0] q; 
input [7:0] qin;
input we;
input clk;
           
reg [7:0] mem [0:255] ;  
reg [7:0] data_out;

assign q = (!we) ? data_out:8'bz;
  
always @ (posedge clk)
begin
  if (we)
  begin
    mem[address] = qin;
  end
  data_out = mem[address];
end

initial
begin
  $readmemh("init.dat",mem);
end
endmodule
 
thanks a lot.

your solution worked ,but i didn't understand why my code didn't work.
 

Altera block RAM is synchronous and doesn't work without a clock.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…