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.

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
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
 
  • Like
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. :p
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top