The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Jul 17th, 2024, 1:37am
Pages: 1
Send Topic Print
frequency measurement without hidden state (Read 929 times)
Aigneryu
Senior Member
****
Offline



Posts: 102

frequency measurement without hidden state
Mar 29th, 2009, 10:41pm
 
To contnue my other thread, I quicky wrote a frequency/period measurement module without hidden states. However, it does not work for all cases. Sometimes it cause convergence problem in PSS. Can anybody check if there is any potential problem?

----Start from here-----------------------------------------------------

module period_meas (vp, vn, period, freq);
input vp, vn; electrical vp, vn;

output period; electrical period;
output freq; electrical freq;

parameter real vth=0;      // threshold (V)
parameter integer dir =1;
parameter real ttol=1f;  // in sec
parameter real outStart = 100n; // in sec
parameter integer period_save_flag =1;

parameter real freq_ini = 1G; // estimated frequency
parameter real unit_period = 1n;
parameter real unit_freq = 1G;


real cross_cur, cross_cur_d, cross_prev;
real period_inst, period_inst_d;
integer fp_periods;

integer actNow_p1, actNow_p2, actNow_p3;


analog begin

@(initial_step)
begin
 actNow_p1=0;
 actNow_p2=0;
 actNow_p3=0;
 cross_prev=0;
 cross_cur=0;
 cross_cur_d=0;
 period_inst=1/freq_ini;
 period_inst_d=1/freq_ini;
 if(period_save_flag==1)
 fp_periods=$fopen("periods.m");
end


actNow_p1 = 0;
actNow_p2 = 0;
actNow_p3 = 0;        

cross_cur=last_crossing(V(vp,vn)-vth, dir);

@(cross(V(vp,vn)-vth, dir, ttol))
 actNow_p1 = 1;

@(cross(V(vp,vn)-vth, -dir, ttol))
 actNow_p2 = 1;

@(cross(V(vp,vn)-(vth+0.1), dir, ttol))
  actNow_p3 = 1;

     
period_inst = idt(0, cross_cur_d-cross_prev, actNow_p3);
period_inst_d = ((period_inst>0)? period_inst:1/freq_ini);
cross_cur_d =  idt(0, cross_cur, actNow_p1);
cross_prev = idt(0, cross_cur_d, actNow_p2);

//preiod strobe
@(cross(V(vp,vn)-vth, dir, ttol))
begin
 if(($abstime >= outStart)&&(period_save_flag==1))    
      $fstrobe(fp_periods, period_inst);
end


V(period) <+ period_inst_d/unit_period;
V(freq) <+ 1.0 / period_inst_d / unit_freq;

end
endmodule
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2386
Silicon Valley
Re: frequency measurement without hidden state
Reply #1 - Mar 29th, 2009, 11:57pm
 
Why don't you use the Verilog-A period measurement model given on www.verilog-ams.com. It is simpler, more efficient, more accurate, and works with Spectre-RF.

-Ken
Back to top
 
 
View Profile WWW   IP Logged
Aigneryu
Senior Member
****
Offline



Posts: 102

Re: frequency measurement without hidden state
Reply #2 - Mar 30th, 2009, 10:49am
 
Thanks Ken,

 I just notice that you use (*instrument_module*) before the module. Does it make the PSS simulation ignore the variable with hidden state issues? If I remove this line, the simulation will start to complain about hidden states from period and t.

 My original frequency meter is more or less like yours, using last_cross. Will (*instrument_module*) also make it work? anyway, I can try myself. Thank you so much.


Sincerely,
Back to top
 
 
View Profile   IP Logged
Aigneryu
Senior Member
****
Offline



Posts: 102

Re: frequency measurement without hidden state
Reply #3 - Mar 30th, 2009, 11:31am
 
I found I made a mistake in my model, I use timing tol control on the cross event block, which is not really needed since I am using last_cross to estimate the crossing time. with the tolerance control, I found it sometimes causes problems during PSS even I use intrument module.
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2386
Silicon Valley
Re: frequency measurement without hidden state
Reply #4 - Mar 30th, 2009, 4:02pm
 
Yes, (*instrument_module*) is the key to making it work, that and eliminating the frequency/period as an output.

-Ken
Back to top
 
 
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.