The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Apr 23rd, 2024, 6:23am
Pages: 1
Send Topic Print
$fdisplay output not working with $finish (Read 2253 times)
va_user
New Member
*
Offline



Posts: 6

$fdisplay output not working with $finish
Jul 04th, 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?
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2384
Silicon Valley
Re: $fdisplay output not working with $finish
Reply #1 - 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
Back to top
 
 
View Profile WWW   IP Logged
va_user
New Member
*
Offline



Posts: 6

Re: $fdisplay output not working with $finish
Reply #2 - 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.
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.