This is my Testbench for a design and I am applying inputs to the design using the function ‘$readmemb’.
I have opened a file using ‘$fopen’ and wish to write the result ‘out’ in the file named ‘jaja.txt’ but I am unable to do so.
Sometimes the file ‘jaja.txt’ shows nothing and sometimes don’t care ‘x’.
module trimmed_tb();
reg clk,rst; // clock and reset
reg [7:0]P;
wire [7:0]out;
reg [12:0] vectornum; // bookkeeping variables
reg [7:0] testvectors[4096:1]; //array of testvectors
integer outfile;
//instantiate device under test
median_fil_final dut(.clk(clk),.rst(rst),.P(P),.out(out));
// generate clock
always #5 clk=~clk;
// at start of test, load vectors
initial
begin
$readmemb("C:/Users/OneDrive/Desktop/Noisy_pixels.mem",testvectors); // Read vectors
outfile = $fopen("C:/Users/OneDrive/Desktop/jaja.txt","w");
vectornum = 0;
rst=0;
end
// apply test vectors on rising edge of clk
always @(posedge clk)
begin
P = testvectors[vectornum];
end
// increment index on falling edge of clk
always @(negedge clk)begin
if(~rst)begin
vectornum = vectornum + 1; // read next vector
if (testvectors[vectornum] === 8'bx)
begin
$display("tests completed");
$finish;// End simulation
end
end
end
initial begin
$fclose(outfile);
end
endmodule
I tried writing to the file by putting the ‘$fdisplay’ in the negedge clk block and then with the ‘$fclose’.
I am expecting to get my ‘out’ result to be written in the ‘jaja.txt’ file.
Fraser is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.