$fwrite usage clarification

OP #5822820
Trying to create a .csv file from my verilog testbench. The testbench is 
for a microprocessor and I can't figure out how to get any data to 
appear in the output file. The $fwrite's at the bottom are for the 
processor module only, but they have a header which includes variables 
from another module. Those columns will be filled by the variables from 
the other module, I just need help fixing my $fwrite portion so that 
actual data appears. Thanks.



`timescale 1ns / 1ps
module tb_processor();

logic reset;
logic clk;
logic [7:0] PC;
logic [7:0] alu_out;
logic [3:0] OPCODE;
logic [7:0] W_Register;
logic [7:0] A;
logic [7:0] B;
logic [15:0] IR;
integer logfile;

task apply_reset ();
    #100 reset <= 1;
    #100 reset <= 0;
endtask


initial begin
   clk = 0;
   apply_reset ();
end

// Instance Declarations
processor processor (
   .reset(reset),
   .clk(clk),
   .PC(PC),
   .alu_out(alu_out),
   .OPCODE(OPCODE),
   .W_Register(W_Register),
   .A(A),
   .B(B),
   .IR(IR)
);

always #10 clk = ~clk;

initial begin

logfile = $fopen("logfile.csv");
$fwrite(logfile, "PC, IR, OPCODE, RA, RB, RD, A, B, RF[RD]\n");
$fwrite(logfile, "%b, %b, %b, %b, %b, \n", PC, IR, OPCODE, A, B);
$fwrite(logfile, "%b, %b, %b, %b, %b, \n", PC, IR, OPCODE, A, B);
$fwrite(logfile, "%b, %b, %b, %b, %b, \n", PC, IR, OPCODE, A, B);
$fclose(logfile);
end

endmodule

Reply

A question of your own? This thread is over 7 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.