The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Jul 16th, 2024, 4:48pm
Pages: 1
Send Topic Print
Verilog A question (Read 3529 times)
MarkG
New Member
*
Offline



Posts: 1

Verilog A question
Jul 24th, 2012, 2:31pm
 
I have a question about the Cadence library ahdlLib -> analog_mux,  the code is copied below.

Why do you need *BOTH* the following type of lines?

    selector = (V(vsel) > vth) ? 1: 0;

    @ (cross(V(vsel) - vth, 1, 1.0, vsel.potential.abstol))
        selector = 1;


won't the conditional operator (?:) , make it so that the selector value is always correct?  Or, do you need the @cross() so that you force the simulator to ALSO evaluate the value of "selector" at the crossings too (so that you get the value of selector changing at the correct time)?

code below:
---------------------------------------------------------------
module analog_mux(vin1, vin2, vsel, vout);
input vin1, vin2, vsel;
output vout;
electrical vin1, vin2, vsel, vout ;
parameter real vth  = 2.5;

  integer selector;
  real vout_val;

  analog begin
     selector = (V(vsel) > vth) ? 1: 0;

     @ (cross(V(vsel) - vth, 1, 1.0, vsel.potential.abstol))
        selector = 1;

     @ (cross(V(vsel) - vth, -1, 1.0, vsel.potential.abstol))
        selector = 0;

     if (selector == 1)begin
        vout_val = V(vin1);
     end
     else if (selector == 0)begin
        vout_val = V(vin2);
     end

     V(vout) <+ vout_val;
  end
endmodule


---------------------------------------------------------------


thanks
M
Back to top
 
 
View Profile   IP Logged
ywguo
Community Fellow
*****
Offline



Posts: 943
Shanghai, PRC
Re: Verilog A question
Reply #1 - Jul 25th, 2012, 1:48am
 
Hi MarkG,

@cross() is not evaluate at the initial time step. So the model gives X state until V(vsel) crosses vth for the first time unless selector is assigned using selector = (V(vsel) > vth) ? 1 : 0;

Another solution is replace @cross() with @above(), which is evaluate at the initial time step. Then the model needs not that conditional assignment.

Best Regards,
Yawei
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1999
Massachusetts, USA
Re: Verilog A question
Reply #2 - Jul 25th, 2012, 7:18am
 
cross() does also control the timestep so that the module is evaluated within timetol of a crossing.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
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.