The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> order of calculation last_crossing() and cross()
https://designers-guide.org/forum/YaBB.pl?num=1261554844

Message started by Ari on Dec 22nd, 2009, 11:54pm

Title: order of calculation last_crossing() and cross()
Post by Ari on Dec 22nd, 2009, 11:54pm

I wish to measure the delay between an enable signal and the clock signal's edge which occurred just before the rise of the enable signal.
I want this measurement to be accurate, therefore I use the last_crossing() function

I thought of this code, but it does not give the desired results due to order of execution. Apparently the simulator first calculates the expressions inside the cross block , and only then it calculates the last_crossing() block.
Therefore, when calculating dly ,en_time equals -1.



Code:
@(cross(V(clk)-vth,1));
   clk_time=last_crossing(V(clk)-vth,1);

 @(cross(V(en)-vth,1)) begin      
     dly=en_time-clk_time;
   end

   en_time=last_crossing(V(en)-vth,1);



Is there a different way to have accurate time calculation using last_crossing() and yet get the behavioral I need?


Regards,

Ari

Title: Re: order of calculation last_crossing() and cross()
Post by Ken Kundert on Dec 23rd, 2009, 12:21am

Consider using http://www.designers-guide.org/VerilogAMS/functional-blocks/periods.tgz as an example.

-Ken

Title: Re: order of calculation last_crossing() and cross()
Post by Ari on Dec 23rd, 2009, 12:39am

Ken,

Thank you for your quick reply.

From the example you gave me I notice that the order of execution depends on the order of the lines.
Putting last_crossing() before the cross() make the expressions inside the cross() block to get the updated value calculated in the last_crossing() statement.

This is the code that works properly:


Code:
@(cross(V(clk)-vth,1));
   clk_time=last_crossing(V(clk)-vth,1);

  en_time=last_crossing(V(en)-vth,1);
 @(cross(V(en)-vth,1)) begin      
     dly=en_time-clk_time;
   end
 



Yet, I wonder where in the LRM it says about this dependency.


Thanks again,

Ari


Title: Re: order of calculation last_crossing() and cross()
Post by Geoffrey_Coram on Dec 23rd, 2009, 7:34am

I think, in the LRM, it says that statements are executed in the order in which they appear in the source code.

The cross event forces the simulator to take timepoints to resolve the crossing accurately, but at (every iteration of) every timepoint, the statements are executed as written.  Thus, you want to be sure that en_time is assigned before you use it to compute dly.  (Otherwise, it's "hidden state" that the simulator has to remember between timepoints.)

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