Altera_Forum
Honored Contributor
9 years agoCannot initialize a 2-D array of bytes from file directly (ram_init_file / $readmemh)
Hello forum Members,
I have been experimenting with file-based initialization of Verilog multidimensional arrays. Until now i succeeded initializing with the help of flat temp. array ------------------------------------------------------------------------
reg charMem;
reg colMem;
reg charMemTmp;
reg colMemTmp;
initial
begin
$readmemh("DE0_CV_SCREENCHAR.txt",charMemTmp);
$readmemh("DE0_CV_SCREENCOL.txt" ,colMemTmp);
$readmemh("DE0_CV_SCREENPAL.txt" ,palMem);
end and always @(posedge CLOCK_50)
begin
if (~RESET_N)
begin
integer row;
integer kol;
for (row=0;row<25;row++)
begin
for (kol=0;kol<80;kol++)
begin
charMem=charMemTmp;
colMem=colMemTmp;
end
end
end
end => This works fine, i use a flat helper array read in the data and copy everything to a 2-d array. However if i try to read it directly: ------------------------------------- reg charMem;
reg colMem;
initial
begin
$readmemh("DE0_CV_SCREENCHAR.txt",charMem);
$readmemh("DE0_CV_SCREENCOL.txt" ,colMem);
$readmemh("DE0_CV_SCREENPAL.txt" ,palMem);
end
=> I get: "10853 verilog HDL error ... : argument 1 to $readmemh must be a memory identifier ??? I also tried reading from a .mif file (1d file 2000 x 1 byte Width=8 depth=2000): ------------------------------------- (* ram_init_file = "DE0_CV_SCREENCHARMEM.mif" *) reg charMem;
(* ram_init_file = "DE0_CV_SCREENCOLORMEM.mif" *) reg colorMem; => this works fine Does anybody know how to initialize the 2-d array from a file using ram_init_file or $readmemh ? I a using Quartus 15.1 on Win7. Thanks in advance, Johi. Update: I have a hunch (from debgging the .mif files generated by quartus from the .txt initialization files that depth needs to be 25 and widt 640 = 8*80 I will try this and come with an update. Johi.