The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Jul 17th, 2024, 4:38pm
Pages: 1
Send Topic Print
Problem with the timer event (Read 4093 times)
Rooney
New Member
*
Offline



Posts: 9

Problem with the timer event
Apr 02nd, 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?







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



Posts: 1999
Massachusetts, USA
Re: Problem with the timer event
Reply #1 - 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).
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2386
Silicon Valley
Re: Problem with the timer event
Reply #2 - 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
Back to top
 
 
View Profile WWW   IP Logged
jbdavid
Community Fellow
*****
Offline



Posts: 378
Silicon Valley
Re: Problem with the timer event
Reply #3 - 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
Back to top
 
 

jbdavid
Mixed Signal Design Verification
View Profile WWW   IP Logged
Paul Floyd
New Member
*
Offline



Posts: 8
France
Re: Problem with the timer event
Reply #4 - 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
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2386
Silicon Valley
Re: Problem with the timer event
Reply #5 - 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
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.