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.....
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.
Is there any method where we can read chunks of datas from a file using verilog....
No. It's quite simple to read the complete file. Why don't you do this?
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
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?
thanks a lot for ur reply......s u r right sir....i found one invalid charachter over there now it is reading properly...
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.
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?
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
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
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.
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??
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.
Hi, Anyone please help me to read a large text file using verilog. I need to do edge detection without using FPGA. Thanks in advance.
Hi, Anyone can please help me to read a text file and load read value on some variables in verilog.