The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Jul 17th, 2024, 8:09am
Pages: 1
Send Topic Print
order of calculation last_crossing() and cross() (Read 2734 times)
Ari
Junior Member
**
Offline



Posts: 17
Israel
order of calculation last_crossing() and cross()
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
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2386
Silicon Valley
Re: order of calculation last_crossing() and cross()
Reply #1 - Dec 23rd, 2009, 12:21am
 
Back to top
 
 
View Profile WWW   IP Logged
Ari
Junior Member
**
Offline



Posts: 17
Israel
Re: order of calculation last_crossing() and cross()
Reply #2 - 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

Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1999
Massachusetts, USA
Re: order of calculation last_crossing() and cross()
Reply #3 - 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.)
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   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.