EmbDev.net

Forum: FPGA, VHDL & Verilog help in reading a large text file using verilog.


Author: Alangs Kannan (Company: Kenit) (alangs)
Posted on:

Rate this post
0 useful
not useful
I am having a large text file which contains only the pixel values of an 
image.....here i can able to read the pixels using $readmemh system 
task..... but the prolem is memory......am using only 1000 words of 
memory as below
reg [31:0] Mem [0:999];
initial $readmemh("pixels.txt",Mem);
By this i can get only 1000 pixles from the text file and i will give 
these pixels to the next module for furthur processing....then i have to 
read the next 1000 pixels from the text file and put it in the 
Mem....similarly i want all the pixels to be readed from the txt file 
with the Mem size as 1000 and give those to the next module for furthur 
processing......so how i can do this plz i will be very thank full to 
u...plz help me.....

Author: Harald Flügel (hfl)
Posted on:

Rate this post
0 useful
not useful
The Verilog system tasks $readmemb/h are prepared to fill only a part of 
the memory but not to read only a part of the file. This is different 
from C. So, I would suggest that you increase the size of the memory so 
that the complete file is read with one single call of $readmemh. 
Afterwards you may process the data in chunks of 1000 samples out of the 
memory.

Author: Alangs Kannan (Company: Kenit) (alangs)
Posted on:

Rate this post
0 useful
not useful
Is there any method where we can read chunks of datas from a file using 
verilog....

Author: Harald Flügel (hfl)
Posted on:

Rate this post
0 useful
not useful
No.

It's quite simple to read the complete file. Why don't you do this?

Author: Alangs Kannan (Company: Kenit) (alangs)
Posted on:

Rate this post
0 useful
not useful
i have tried but in icarus simulator the its reading upto 1980 
words....after that it is giving error as below
Error: Invalid input character

Author: Harald Flügel (hfl)
Posted on:

Rate this post
0 useful
not useful
That's surprising! Are you sure that there is no invalid character in 
the file. If you delete the first n items does the error number stay the 
same?

Author: Alangs Kannan (Company: Kenit) (alangs)
Posted on:

Rate this post
0 useful
not useful
thanks a lot for ur reply......s u r right sir....i found one invalid 
charachter over there now it is reading properly...

Author: Naz Saheb (naz)
Posted on:

Rate this post
0 useful
not useful
Hi

I have converted an image into text file in hex format. I want to 
further process these pixel values in verilog code. how should i do 
it..? i tried using $readmemh ... but i am not able to read the text 
file.. please can any one send me the entire code to access the pixel 
value...

Thanking you in advance.

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Naz Saheb wrote:
> i tried using $readmemh ...
Show a little bit more of your code. And also some lines of the 
hex-file.

> but i am not able to read the text file..
Why not? What problem do you encounter?

Author: Naz Saheb (naz)
Posted on:
Attached files:

Rate this post
0 useful
not useful
thanks for the reply sir

i am not able to get where exactly i have to use $readmemh in my 
attached code.

i tried for simple program below but it resulted in an error that no 
ports are declared, whats wrong?
module text_read_write;
  reg [7:0] mem [0:4];
  integer m,i;

  initial
    begin
      $readmemh("mem_in.txt", mem);      
      m=$fopen("mem_out.txt");
      for(i=0;i<5;i=i+1)
         begin
           $fdisplay(m,"%h",mem[i]);
         end
      $fclose(m);
end
endmodule

text file values :
1
2
4
A
B...

: Edited by Moderator
Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Naz Saheb wrote:
>>> I have converted an image into text file in hex format.
Naz Saheb wrote:
> text file values :
If the attached img.txt has anything to do with your problem: there is 
no hex value inside this file! Its plain ASCII integer.

Naz Saheb wrote:
> i am not able to get where exactly i have to use $readmemh in my
> attached code.
Maybe you must generate a testbench for that module imageedge and feed 
that imageedge with stimuli read out of the img.txt. Am I wrong? Or what 
is this code snippet for?

BTW: Why the heck did you pack a 4kB Verliog file with the file 
extension .txt into a ZIP?
I unpacked it and attached is as a .v Verilog file to your post. Next 
time think and do it yourself, please.

: Edited by Moderator
Author: Lattice User (Guest)
Posted on:

Rate this post
0 useful
not useful
For reading a file in chunks you have to use $fopen and $fread or 
$fscanf.
Easiest is reading binary data with $fread. Also saves you the trouble 
to create a txt file from your image file.

Author: Naz Saheb (naz)
Posted on:
Attached files:

Rate this post
0 useful
not useful
sorry for the mistake sir...

sir can you please suggest how and where to assign the  text file values 
of hex format as an input to an INOUT port in verilog ???

Is it in the main module or the test bench???


In the attached code file 'bus' is declared as an inout port which is a 
bidirectional bus. i want to give text file values as an input to the 
bus..

how can i proceed sir??

Author: DINESH B. (dinesh_b)
Posted on:
Attached files:

Rate this post
0 useful
not useful
Can't we read 2-dimensional text file to verilog test bench? I want to 
make it read like that. please help me in this regard. Whether its 
possible or not? if possible the way? Here I'm attaching the text file.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.