The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> $fdisplay output not working with $finish
https://designers-guide.org/forum/YaBB.pl?num=1467648729

Message started by va_user on Jul 4th, 2016, 9:12am

Title: $fdisplay output not working with $finish
Post by va_user on Jul 4th, 2016, 9:12am

I am brand new to verilog-A and cannot seem to get $fdisplay statements to work in conjunction with $finish.  I have the following code (header and variable declarations not shown):


Code:
   analog begin
   
       @(initial_step) begin
           fh_1 = $fopen("./va_output_1.log");
                   
           $fdisplay(fh_1, "starting verilog-A module\n");
       end

       
       @(cross(V(test_signal)-threshold, -1)) begin
           test_signal_falling_edge_time = $abstime/1p;
           test_signal_falling_edge_value = V(test_signal);
           test_signal_threshold_detected = 1;
           
           $fdisplay(fh_1, "test_signal falling edge detected at t=%f ps, value=%f V\n", test_signal_falling_edge_time, test_signal_falling_edge_value);
           
       end


       @(timer($abstime, test_signal_sample_period)) begin
           if (test_signal_threshold_detected == 1) begin
           
               $fdisplay(fh_1, "threshold detected\n");
               $fflush(fh_1);
               $fclose(fh_1);
               $finish;
           
           
           end
       end

   end


Basically I want to monitor the value of test_signal, and then when it falls below a given threshold, perform the actions inside the timer loop, then exit.  For now, the only action in the timer loop is to print that the threshold was detected, then exit.

The problem I am having is that the $fdisplay statement inside the timer loop is not making it into the output file.  All other $fdisplay statements are writing their output to the file.

If I remove the $finish statement, then the $fdisplay statement inside the timer loop does write its output to the file.  I am not sure why the inclusion/exclusion of $finish would affect whether or not the $fdisplay statements work.

The inclusion of $fflush and $fclose don't seem to make any difference.

If I check the spice log file, I can see that the $finish statement is being reached:


Code:
$finish in mode 64 at time 5e-08


Does anyone know what is going on here?

Title: Re: $fdisplay output not working with $finish
Post by Ken Kundert on Jul 4th, 2016, 5:58pm

Why are you passing $abstime into the timer function. That is not right. You probably want that to be 0.

Why do you even have a timer block?

As to why the $finish is interfering with $fdisplay, I suspect it is a bug. You might want to try working around it with something like this ...

Code:
integer done;
real tcross;
analog begin
   @(initial_step)
       f = $fopen("./va_output_1.log");
   if (done)
       $finish;

   tcross = last_crossing(V(test_signal)-threshold, -1));

   @(cross(V(test_signal)-threshold, -1)) begin
       $fdisplay(f, "test_signal falling edge detected at t=%rs\n", tcross);
       done = 1;
   end
end

This tries to address the underlying problem by putting the $finish at the time point after when the $fdisplay is executed.

It also uses last_crossing to get better accuracy, and uses %r to naturally output time with SI scale factors.

-Ken

Title: Re: $fdisplay output not working with $finish
Post by va_user on Jul 4th, 2016, 7:01pm


Ken Kundert wrote on Jul 4th, 2016, 5:58pm:

Why do you even have a timer block?


Once test_signal falls, I want to start taking periodic samples of another signal until the difference between the current and the previous sample is less than some threshold, then end the simulation.  

I have not added that code yet because my $fdisplay statements were not working with the $finish.

I will try your suggestion of using the done signal.

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.