cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Contributor
Contributor
910 Views
Registered: ‎01-14-2019

Can't read in memory using $readmemb

Jump to solution

I'm trying to load in memory data using &readmemb. Part of the code is as shown below.

 

    // Load Transmit Pattern
    reg mem_buf [0:14];
   
    initial begin
        $readmemb("C:/Users/mhc/Desktop/Vivado/serializer/generate_15/test_pattern.txt", mem_buf);
    end

//~~~~~~~~~~~~~~~~~~~//

always @
//
o_buf[0] <= mem_buf[0];
o_buf[1] <= mem_buf[1];
...
//

 

When I synthesize & implement the design, the design doesn't use any of the resources. mem_buf[] determines the output, so I'm assuming that Vivado just blanks the whole design since no data read from txt file = no output data.

I have tried using readmemb in other pc, with same version of Vivado (2018.3), and it worked fine then, strangely.

Is there a fix, or any way around?

 

+) One of the posts concluded that I put the txt file in project directory (where project.xpr is), but that didn't work. generate_15 is the project directory.

++) test_pattern.txt is as below :

1 0 1 0 1 1 1 1 0 0 0 0 1 1 1
1 0 1 0 1 0 1 1 0 0 0 0 1 1 1
1 0 1 1 0 1 1 1 0 1 0 0 1 1 1
1 1 1 0 1 1 0 1 0 0 0 0 1 1 1
1 0 1 0 1 1 1 1 0 0 0 0 1 1 1
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Xilinx Employee
Xilinx Employee
760 Views
Registered: ‎06-14-2018

Hi @mh9840 ,

Mostly your memory is never initialized. Like @viviany mentioned you should have 2D array for memory.

Here is working example of 2D array inferred as Block RAM and is initialized using txt file.

Try to code on same lines and check if it works.

 

Thanks,

Ajay

 

 

View solution in original post

Capture.JPG
14 Replies
Highlighted
Xilinx Employee
Xilinx Employee
887 Views
Registered: ‎06-14-2018

Hi @mh9840 ,

I have not tried your testcase, is your o/p tied to constants probably all 1's.

Thanks,

Ajay

0 Kudos
Highlighted
Contributor
Contributor
879 Views
Registered: ‎01-14-2019

I don't think I understood what you mean.

But anyways, o_buf[] is just a temporary reg memory within the code, later it will be used as :

serial_data <= o_buf[index]    //index: 0~14

It's a serializer design, so I first put the data from memory to reg buffer 'o_buf', and transmit it with faster clock. (Though, the current design reads only one line from txt file, and sends same stuff over and over)

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
855 Views
Registered: ‎06-14-2018

Hi @mh9840 ,

What I see is mem_buf is array of word size 1 and depth of 15.

However memory initialization file has word size of 15.

Do you see any warning related to reading test_pattern.txt file

Could you please provide more of your testcase.

Thanks,

Ajay

0 Kudos
Highlighted
Contributor
Contributor
821 Views
Registered: ‎01-14-2019

I originally tried to read 2D array (5 rows, 15 column), which did not work, so I attempted to read only one row (1-bit data, 15 depth) with the code above.

the txt pattern has the numbers separated with space, so each should be 1-bit data, unless I've completely misunderstood how the function works...

I see two errors related to mem_buf[].

  • [Synth 8-2898] ignoring malformed $readmem task: invalid memory name ["C:/Users/mhc/Desktop/Vivado/serializer/generate_15/generate_15.srcs/sources_1/new/main.v":92]
  • [Synth 8-3848] Net mem_buf[0] in module/entity main does not have driver. ["C:/Users/mhc/Desktop/Vivado/serializer/generate_15/generate_15.srcs/sources_1/new/main.v":89]
0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
783 Views
Registered: ‎05-14-2008

mem_buf should be a 2-D array to describe a memory.

When you tried 2-D for mem_buf, what did you get?

How did you know it did not work?

-vivian

-------------------------------------------------------------------------------------------------
Don’t forget to reply, kudo, and accept as solution.
-------------------------------------------------------------------------------------------------
如果提供的信息能解决您的问题,请标记为“接受为解决方案”。
如果您认为帖子有帮助,请点击“奖励”。谢谢!
-------------------------------------------------------------------------------------------------
0 Kudos
Highlighted
Contributor
Contributor
781 Views
Registered: ‎01-14-2019

I also have tried making mem_buf a 2D array, but I got same errors.

I'm checking pin output with oscilloscope, so I can tell that it's not working, and also, I see no resources utilized in synthesis & implementation report, which tells me something is wrong.

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
761 Views
Registered: ‎06-14-2018

Hi @mh9840 ,

Mostly your memory is never initialized. Like @viviany mentioned you should have 2D array for memory.

Here is working example of 2D array inferred as Block RAM and is initialized using txt file.

Try to code on same lines and check if it works.

 

Thanks,

Ajay

 

 

View solution in original post

Capture.JPG
Highlighted
Contributor
Contributor
715 Views
Registered: ‎01-14-2019

Alright, just got the time to test the code out and it did work.

101011110000111
101010110000111
101101110100111
// more...

I modified the txt file to have 15-bit data (no space dividing them) per row and depth 100 as shown above . In the code, addressed each bit by mem_buf[index][0], mem_buf[index][1], ...

No idea why it did not work as 2D array of 1-bit data though...

0 Kudos
Highlighted
Observer
Observer
703 Views
Registered: ‎07-01-2020

Hi,

i'm encountering a similar problem. i cannot get results by reading an array red by $readmemb.

from simulation image seems like that the file is going into memory..

 


module STRETCHblock(

input [9:0] counter,
input [15:0] STRETCH_VAL,
output reg[31:0] ROM1F
);

(* rom_style = "block" *)

reg [15:0] ROM1[0:1023];
reg [15:0] ROM1B;

initial begin
$readmemb("sine.mem", ROM1);

end

 

always @ (counter)

ROM1B <= ROM1[counter];
assign ROM1F = ROM1B

endmodule

 

test bench as below


module STRETCHblock_tb;


reg [9:0] counter=0;
reg [15:0] STRETCH_VAL=0;
wire[31:0] ROM1F=0;

(* rom_style = "block" *)


reg [15:0] ROM1[0:1023];
reg [15:0] ROM1B;

initial begin
$readmemb("sine.mem", ROM1);


end

STRETCHblock uut (

.counter (counter),
.STRETCH_VAL (STRETCH_VAL),
.ROM1F (ROM1F)


);

 

initial
begin
STRETCH_VAL=0;

#5 counter=0;
#10 counter=10'd1;
#15 counter=10'd2;
#20 counter=10'd3;
#25 counter=10'd4;
#30 counter=10'd5;
#35 counter=10'd6;
# 40 $finish;
end
endmodule

 

 

i attach code and test bench and an image from simulation

q1.jpg
0 Kudos
Highlighted
Observer
Observer
554 Views
Registered: ‎07-17-2019
 
Excuse me, i'm encountering a similar problem. I might know what happened
Did you copy and paste the file path you originally wrote from the file properties like below?
 

QQ图片20200808012636.png

 

0 Kudos
Highlighted
Observer
Observer
549 Views
Registered: ‎07-01-2020

Hi, @doggie_ovo 

well the text file should be renamed to .mem and uploaded in your design sources to be used.

I did all this, my problem was related to syntax used in the code to fetch data from the file.

thx for your interest, i opened a new thread and got it sorted

 

0 Kudos
Highlighted
Observer
Observer
448 Views
Registered: ‎07-17-2019
OK,i can use .txt file for simulation but not know whethe use it for design.i recommend use .coe file.
The problem I encountered before is that the the value which read by $readmemb function is always X .
After a long period of debugging,I found that it was caused by the non ASCII garbled code in the file path I copied
0 Kudos
Highlighted
Observer
Observer
318 Views
Registered: ‎07-01-2020

@doggie_ovo 

could you send me a formatted coe file?, i never have done that formatting

0 Kudos
Highlighted
Observer
Observer
301 Views
Registered: ‎07-17-2019

@ViennaAudio The coe format like this.You can generate it by some script .

memory_initialization_radix = 16;
memory_initialization_vector = 
00001234,
12340000,
5555AAAA,
12345678;
0 Kudos