The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> Problem with the timer event
https://designers-guide.org/forum/YaBB.pl?num=1238682356

Message started by Rooney on Apr 2nd, 2009, 7:25am

Title: Problem with the timer event
Post by Rooney on Apr 2nd, 2009, 7:25am

@(cross(V(FIN) -VTH, +1))
t1  = $abstime;
@(cross(V(FIN) -VTH, -1))
t2 = $abstime;

in_period = (abs(t1 -t2)) *2;
out_period = 4/in_period;

@(initial_step) z=1;
@(timer(0, out_period/2)) z = !z;

V(OUT) <+ transition (vdd*z, 0.0, 10p);

The output frequency is not 4 * FIN. After certain interval of time there is a change of pulse width for one pulse. After that for few pulses the freq is 4*FIN. After that, agin same pulse width mismatch is happening causing the difference is frequency. Meaning that there is no monotonicty of the pulse width causing variation of frequency.


Can any one explain what is the problem with this code?








Title: Re: Problem with the timer event
Post by Geoffrey_Coram on Apr 3rd, 2009, 3:57am

What are t1 and t2 initialized to?  Variables in Verilog-A start at zero, and the cross doesn't trigger during the dc solution, so t1=t2=0 at time=0, and the out_period equation will cause a division by zero.

I'm not sure what the language guarantees regarding the timer event when you change the period.  Suppose you had the timer set to go off at 2us, starting from 0.  Now, at 1us, you change the period to 3us.  Does the timer go off at:
a) 2us, because that event was scheduled and the LRM doesn't specify that it should be deleted?
b) 3us, because the simulator remembers that the timer was set at time 0?
c) 4us, which is 3us after the period was changed?

Actually, c) is wrong, but it reminds me that the first argument is the start time.  So, if you had timer(0,4u) and then at 24.1us, you changed the period to 5u (out_period=10u), then you've just made it timer(0, 5u) and so it will fire at 25us, because that's an integer number of periods from the start time of 0, even though it's only 1us from the last time it fired (24us).

Title: Re: Problem with the timer event
Post by Ken Kundert on Apr 3rd, 2009, 9:37pm

A likely source of the problem is this line ...
out_period = 4/in_period;

Your output period has units of frequency. Did you mean to say
out_period = in_period/4;

-Ken

Title: Re: Problem with the timer event
Post by jbdavid on Apr 8th, 2009, 7:31pm

And it looks like the outperiod can Change..
This will make the same mistake as a variable oscillator output implemented as
V(osc) <+ Ampl*cos(2*`M_PI*Freq);

If you Change the variable referenced in the periodic parameter of the timer, your next event will be based on the new period, as applied from the starting time of the timer. .. Not on the new period from the last event.

for a variable (digital) oscillation , you might do better with an always block.
if you are stuck with Verilog-A (rather than AMS) you could just do

Code:
@(timer(next_edge)) begin
 next_edge = $abstime + out_period;
 z = !z;
end


good luck, and keep trying

Title: Re: Problem with the timer event
Post by Paul Floyd on Apr 23rd, 2009, 1:20am

Hi

Just a little remark. Rather than write


Code:
@(cross(V(FIN) -VTH, +1))
t1  = $abstime;


why not write


Code:
t1 = last_crossing(V(FIN) -VTH, +1);


Paul

Title: Re: Problem with the timer event
Post by Ken Kundert on Apr 23rd, 2009, 9:45am

Paul,
   Using last_crossing is an improvement, but you still need the @cross statement. last_crossing is not very accurate without the @cross.

-Ken

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