electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

[Verilog] How to read data from a file?


Post new topic  Reply to topic    EDAboard.com Forum Index -> ASIC Design Methodologies & Tools (Digital) -> [Verilog] How to read data from a file?
Author Message
davyzhu



Joined: 23 May 2004
Posts: 521
Helped: 3
Location: oriental


Post07 Jul 2005 13:45   

[Verilog] How to read data from a file?


Hi all,

I want to read one data per clock from a flie, and send them to a pipelined circuit.
After that, save one data per clock to a file.

I am new to testbench. Now I decide to read a data (in) from file @(negedge clk).
And pass this data to the module that I want to test @(posedge clk).
After that, save data (out) to a file.

Is my test method right? Any suggestions will be appreciated!

// Code list below seems not work
//------code-----------
`define clk_cycle 10
module testbench_tb;

reg gclk;
integer os1,os2;
integer i,j;

wire [5:0] in;
reg [5:0] out;

initial begin
gclk = 0;
os1 = $fopen("tb_1.txt","r");
os2 = $fopen("tb_2.txt","w");
end

always # (`clk_cycle / 2) gclk = ~gclk;

always @ (negedge gclk)
begin
$fscanf(os1, "%d", in);
$fwrite(os2, "%d", out);
end

// pipelined circuit under test
always @ (posedge gclk)
begin
if(greset == 0)
begin
out <= 0;
end
else
begin
out <=in;
end
end
endmodule

Best regards,
Davy
Back to top
eeeraghu



Joined: 03 Jun 2005
Posts: 215
Helped: 17


Post07 Jul 2005 14:15   

Re: [Verilog] How to read data from a file?


Use $readmemb or $readmemh to load a reg array (memory) with file data.

$readmemb — The file contains binary ASCII data

$readmemb ("filename", memory_name, [start_addr, [finish_addr]]);

$readmemh — The file contains hexadecimal ASCII data

$readmemh ("filename", memory_name, [start_addr, [finish_addr]]);

You can default the addresses, or provide them in the system task or in the data
file (or both). The system task by default writes from the left memory address (as
declared) toward the right memory address. Addresses (if any) in the data file
must reside with the range (if any) specified in the system task.

this might help u,
Back to top
Google
AdSense
Google Adsense




Post07 Jul 2005 14:15   

Ads




Back to top
visualart



Joined: 21 Dec 2001
Posts: 588
Helped: 26


Post08 Jul 2005 4:00   

[Verilog] How to read data from a file?


It is obligatory that be couple the task $fopen and the task $fclose, Only $fopen, you will occupy the deal with memory.
Back to top
jarodz



Joined: 12 Mar 2005
Posts: 100
Helped: 14


Post10 Jul 2005 17:05   

[Verilog] How to read data from a file?


hi, davyzhu
You can declare two large reg arrarys as input/output buffer.
If your input data is in ASCII format, use $readmem* as eeeraghu's describption. Otherwise use $fgetc in initial block.
Then save the data in output buffer to file before $finish.

Regards,
Jarod
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> ASIC Design Methodologies & Tools (Digital) -> [Verilog] How to read data from a file?
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
how to read data from a txt file in verilog (4)
how i can read data from file to computations (4)
How can i read ip data from a text file (2)
How can i read two columns data from a text file with Matlab (1)
Verilog-A Read from file (1)
how to read a bin file in matlab-eeg data file. (2)
How to read data file by VHDL (1)
[Matlab] How to read in Hex data file? (2)
How can i read a text file inut in verilog (1)
VHDL: How do i read from file? (5)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS