0
votes

First of all I want to say that I'm running the simulation in ADS (Advanced Design System 2017) through a Verilog model compiled in ModelSim.

My objective is loading data from a .txt file into the testbench as input in order to run the simulation, and afterwards save the results of this simulation in another .txt file.

Here is the content for the input test .txt file called "param.txt":

1
2
3
4
5

And here is my Verilog testbench code:

`include "disciplines.vams"


module resistor(p,n);
electrical p,n;
parameter real R=50.0;
integer file;
integer out;
real pwm_A[0:10];
integer i;
integer count;


analog begin

    @(initial_step) // Initial Conditions
    begin


////////////// Read

file=$fopen("param.txt","r");

    if (file)  $display("File was opened successfully : %0d", file);
    else       $display("File was NOT opened successfully : %0d", file);

    for (i=1; i<=5; i=i+1) begin  
         count = $fscanf(file,"%d",pwm_A[i]);
    end



////////////// Write


out=$fopen("out.txt","w");

    for (i=1; i<=5; i=i+1) begin  
        $fwrite(out,"%d\n",pwm_A[i]);
    end


$fclose(file);
$fclose(out);


end

// Simulation (doesnt matter)
V(p,n) <+ R * I(p,n);


end
endmodule

The simulation throws this error:

Error: Incorrect target supplied to integer-valued $fscanf field.

May anyone spot the problem?

Thanks in advance.

1
It's not duplicated, i'ts just another issue!davmc
Hi davmc! Yes, but your source code still contains the same issue as the previous question, where Matthew suggested to change pwm_A[i]=$fscanf(file,"%d",j); to count = $fscanf(file,"%d",pwm_A[i]);.Silicon1602
You declared pwm_A as a real. Did you try to declare it as an integer? Based on the error message you provided, this could be the problem. If you actually need to load real numbers instead of integers, you might want to change the %d specifier. See this reference on the several C specifiers.Silicon1602
There are differences between C and Verilog-AMS formatted input and output. Go for the Verilog-AMS standard accellera.org/images/downloads/standards/v-ams/VAMS-LRM-2-4.pdf.Paul Floyd

1 Answers

4
votes

You have declared pwm as an array of reals whilst using the %d format specifier to both read and write the file. You need to either

i) change pwm to be an array of integers or

ii) change the %d format specifier to %f in the $fscanf and $fwrite system function calls.

The %d format specifier is expecting to read and will write a decimal integer.