| Author |
Message |
davyzhu
Joined: 23 May 2004 Posts: 521 Helped: 3 Location: oriental
|
06 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
|
06 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

|
06 Jul 2005 4:01 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
eeeraghu
Joined: 03 Jun 2005 Posts: 215 Helped: 17
|
06 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
|
06 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
|
06 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
|
06 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
|
06 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
|
07 Jul 2005 2:55 modelsim $fopen |
|
|
|
|
| put fwrite in always
|
|
| Back to top |
|
 |