electronics forum

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

[Verilog] How to save data to a file?


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



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


Post06 Jul 2005 3:41   

verilog fwrite


Hi all,
I want to save data to a file. And I use $fopen, %fwrite, %fclose. But I found these function only can be called in initial block. When I use them outside initial block, the compiler report errors??

I want to use it in a for block, how?
I use Modelsim 5.6.

Any suggestions will be appreciated!

//-------------------
module tb;
integer os1;
initial
begin
os1 = $fopen("E:\\tb.txt");
$fwrite(os1,"aaaaaaaaaaaa");
$fclose(os1);
end
endmodule
//-------------------

Best regards,
Davy
Back to top
zeese



Joined: 21 May 2002
Posts: 27
Helped: 1


Post06 Jul 2005 4:01   

verilog $fwrite


Quote:
I want to use it in a for block, how?


I don't get your question. Do you mean to use it in a "for loop"?

Even for loop, you may need to write it in an initial block.

initial
begin
for (i=0;i<5;i=i+1)
$fwrite(osi, "aaa");
end

Or, you can use it in always block, something like this

always @ (posedge clk)
begin
if (data_ready)
$fwriteh(osi, "%h",datain);
end[/quote]
Back to top
Google
AdSense
Google Adsense




Post06 Jul 2005 4:01   

Ads




Back to top
eeeraghu



Joined: 03 Jun 2005
Posts: 215
Helped: 17


Post06 Jul 2005 7:50   

fwrite verilog


How about declaring the output i.e writing in seperate always block noting the output, and the function in a seperate i.e applying stimulus in another intitial using the for loop


initial begin
alu_chann = $fopen("alu.log"); if(!alu_chann) $finish;
end

// the given function stimulus.

always @(posedge clock) // print to alu.log
$fdisplay(alu_chann, "acc= %h f=%h a=%h b=%h",acc,f,a,b);

regards raghu
Back to top
echo47



Joined: 07 Apr 2002
Posts: 4206
Helped: 566


Post06 Jul 2005 8:03   

$fwrite verilog


davyzhu, show us your code that's not working.

ModelSim 6.0c lets me put $fopen, $fwrite, and $fclose inside initial blocks, outside initial blocks, inside for loops, wherever I want.
Back to top
dearjohn



Joined: 08 Jun 2005
Posts: 9
Helped: 1


Post06 Jul 2005 9:46   

fwrite in verilog


module tb;
integer os1;
initial
begin
os1 = $fopen("E:\\tb.txt");
//$fwrite(os1,"aaaaaaaaaaaa");
//$fclose(os1);
end

always
begin
$fwrite(os1,"aaaaaaaaaaaa");
end

endmodule
//-------------------

Best regards,
Davy
Back to top
echo47



Joined: 07 Apr 2002
Posts: 4206
Helped: 566


Post06 Jul 2005 10:31   

$fwrite in verilog


No errors here. Runs fine. In a few seconds I had a file with hundreds of megabytes of a's.
Maybe you need a newer ModelSim.
Back to top
davyzhu



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


Post06 Jul 2005 13:33   

verilog fclose


Hi all,

Thanks! I have done it by your methods!
And anyone used Chris Spear's PLI, is it powerful?

Best regards,
Davy
Back to top
jjww110



Joined: 19 Apr 2005
Posts: 262
Helped: 5
Location: china


Post07 Jul 2005 2:55   

modelsim $fopen


put fwrite in always
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 save data to a file?
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
[Verilog] How to read data from a file? (3)
how to read data from a txt file in verilog (4)
How to save a link list to file (2)
How to save 3D image file in eagle (2)
how to save data on power failure (16)
how to save data in internal EEPROM of PIC16F914?? (3)
(Matlab) How to 'save' data *not* in scientific mode? (2)
[Matlab] How to convert vector to string and save it to file (1)
how to save netlist file into ddc format from SOC Encounter (4)
reading stimuls data file using verilog (3)


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