Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[Verilog] How to save data to a file?

Status
Not open for further replies.

davyzhu

Advanced Member level 1
Advanced Member level 1
Joined
May 23, 2004
Messages
494
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,298
Location
oriental
Activity points
4,436
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
 

verilog $fwrite

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]
 

    davyzhu

    Points: 2
    Helpful Answer Positive Rating
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
 

    davyzhu

    Points: 2
    Helpful Answer Positive Rating
$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.
 

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
 

    davyzhu

    Points: 2
    Helpful Answer Positive Rating
$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.
 

    davyzhu

    Points: 2
    Helpful Answer Positive Rating
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
 

modelsim $fopen

put fwrite in always
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top