The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
May 13th, 2024, 12:06am
Pages: 1
Send Topic Print
VCO behavioral model (Read 2788 times)
Prathap
New Member
*
Offline



Posts: 7
India
VCO behavioral model
Oct 16th, 2007, 4:49am
 
Hi,

I am currently working on modeling a VCO. I went through this piece of code from the Designer's Guide website.

module vco1 (out, in);

input in; voltage in;                        // input terminal
output out; voltage out;                  // output terminal
parameter real vmin=0;                        // input voltage that corresponds to minimum output frequency
parameter real vmax=vmin+1 from (vmin:inf);      // input voltage that corresponds to maximum output frequency
parameter real fmin=1 from (0:inf);            // minimum output frequency
parameter real fmax=2*fmin from (fmin:inf);      // maximum output frequency
parameter real vl=-1;                        // high output voltage
parameter real vh=1;                        // low output voltage
parameter real tt=0.01/fmax from (0:inf);      // output transition time
parameter real ttol=1u/fmax from (0:1/fmax);      // time tolerance
real freq, phase;
integer n;

analog begin
   // compute the freq from the input voltage
   freq = (V(in) - vmin)*(fmax - fmin) / (vmax - vmin) + fmin;

   // bound the frequency (this is optional)
   if (freq > fmax) freq = fmax;
   if (freq < fmin) freq = fmin;

   // bound the time step to assure no cycles are skipped
   $bound_step(0.6/freq);

   // phase is the integral of the freq modulo 2p
   phase = 2*`M_PI*idtmod(freq, 0.0, 1.0, -0.5);

   // identify the point where switching occurs
   @(cross(phase + `M_PI/2, +1, ttol) or cross(phase - `M_PI/2, +1, ttol))
     n = (phase >= -`M_PI/2) && (phase < `M_PI/2);

   // generate the output
   V(out) <+ transition(n ? vh : vl, 0, tt);
end
endmodule


In this code i couldnt understand the cross statement used for identifying the point where the switching occurs. I mean i could understand the basic functionality of a sinusoidal VCO. But since this is a VCO whose output is a square wave i couldnt understand why the phase + `M_PI/2 is used to identify the switching. Moreover why is the phase limited from -PI/2 to PI/2. Is it the characteristic of the idtmod function?

Thanks.
Back to top
 
 

Regards,
Prathap
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2384
Silicon Valley
Re: VCO behavioral model
Reply #1 - Oct 16th, 2007, 12:11pm
 
The last two arguments of the idtmod operator indicate that its output should range from -0.5 to -0.5+1.0=0.5. The return value is multiplied by 2π before it is assigned to the variable phase. Thus, phase is a sawtooth waveform that ranges from -π to π. The cross functions are set to trigger at -π/2 and π/2 to produce a square wave. You can produce a rectangular wave by changing those thresholds.

-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.