$fwrite usage clarification

OP #5822820
Rate this post
• ▲ useful
▼ not useful
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

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

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.