write to a file at an event (verilog)

Status
Not open for further replies.

spman

Advanced Member level 4
Joined
Aug 15, 2010
Messages
113
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Visit site
Activity points
2,061
Hi,
I have a problem with simulation.
I want to write the value of a signal into a file at positive edge of another signal. How should I use file commands to achieve it?

I wrote this code
Code:
	initial begin
		FileW = $fopen("dataout.txt", "w");
		forever begin
			if (Enable) begin
				#10;   //prevent writing frequently. clk is 10 ns
				$fwrite(FileW, "A=%d B=%d C=%d\n", A, B, C);
			end
		end
	end
But it doesn't work!
 

try this:

Code:
forever begin
  @ ( posedge clk )
    $fwrite(FileW, "A=%d B=%d C=%d\n", A, B, C);
end
 
Reactions: spman

    spman

    Points: 2
    Helpful Answer Positive Rating
Or for the short short version:

Code:
always @ ( posedge clk )
    $fwrite(FileW, "A=%d B=%d C=%d\n", A, B, C);

Anyways, check out the difference between putting it inside an "initial" block and outside it. As in, take your favorite verilog language reference and read the bit on "initial" block. That might help if I am guessing the thought process correctly.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…