The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> frequency measurement without hidden state
https://designers-guide.org/forum/YaBB.pl?num=1238391689

Message started by Aigneryu on Mar 29th, 2009, 10:41pm

Title: frequency measurement without hidden state
Post by Aigneryu on 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

Title: Re: frequency measurement without hidden state
Post by Ken Kundert on 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

Title: Re: frequency measurement without hidden state
Post by Aigneryu on 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,

Title: Re: frequency measurement without hidden state
Post by Aigneryu on 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.

Title: Re: frequency measurement without hidden state
Post by Ken Kundert on 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

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