Forum: FPGA, VHDL & Verilog $fwrite usage clarification

von Andrew M. (amiotto11)

Rate this post
0 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;

initial begin
   clk = 0;
   apply_reset ();

// Instance Declarations
processor processor (

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);



Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.