The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Jul 17th, 2024, 10:32pm
Pages: 1
Send Topic Print
veriloga code of a switch (Read 8106 times)
jovial
Junior Member
**
Offline



Posts: 19

veriloga code of a switch
Jun 25th, 2013, 6:20am
 
Hello everyone!!
I am modeling a simple voltage controlled switch which shld be a short ckt when control voltage is high, and open otherwise.
But the switch doesn't seem to work..
Can someone tell the mistake in my code given below...

--------------------------------------------------------------------------------
---
`include "disciplines.vams"

module dig_ctrl_switch_va (p, n, ps, ns);
   parameter real thresh=0.9;                  // threshold (V)
   parameter real ron=10 from (1:inf);            // on resistance (Ohms)
   parameter real roff=100M from [1:inf);       // off  resistance (Ohms)
   input ps, ns;
   electrical p, n, ps, ns;

   analog begin
     @(cross( V(ps,ns) - thresh, 0 ))
         $discontinuity(0);
     if (V(ps,ns) > thresh)
         I(p,n) <+ V(p,n)/ron;
     else
         I(p,n) <+ V(p,n)/roff;
   end
endmodule
Back to top
 
 
View Profile   IP Logged
Frank Wiedmann
Community Fellow
*****
Offline



Posts: 678
Munich, Germany
Re: veriloga code of a switch
Reply #1 - Jun 25th, 2013, 8:40am
 
You don't tell us what exactly is not working (error messages, simulation results, ...). However, it is obvious that your coding style can be improved. Take a look at chapter 3 "AMS Behavioral Modeling" of the Mixed-Signal Methodology Guide, which is available in four pdf files from http://www.eetimes.com/electronics-blogs/eda-designline-blog/4397605/Book-excerp.... I would recommend you to use a transition function as shown on page 59 (the example is in Verilog-AMS, but a similar approach can be used in Verilog-A). By the way, Spectre has a similar component already built in, see http://www.cadence.com/community/forums/T/26543.aspx.
Back to top
 
 
View Profile WWW   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: veriloga code of a switch
Reply #2 - Jun 25th, 2013, 8:41am
 
Jovial,
see LRM:
"You must declare the port direction for every port in the list of ports section of the module
declaration. To declare the direction of a port, use one of the following three syntaxes. ..."

Otherwise the code seems OK.

- B O E
Back to top
 
 
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: veriloga code of a switch
Reply #3 - Jun 25th, 2013, 8:43am
 
Frank,
I fully agree. However, the V-AMS section of this site does offer a very similar example. So it should work.
- B O E
Back to top
 
 
View Profile   IP Logged
Frank Wiedmann
Community Fellow
*****
Offline



Posts: 678
Munich, Germany
Re: veriloga code of a switch
Reply #4 - Jun 25th, 2013, 8:49am
 
It will probably work in simple circuits, but it might cause convergence problems in more complex ones.
Back to top
 
 
View Profile WWW   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: veriloga code of a switch
Reply #5 - Jun 25th, 2013, 8:53am
 
Frank,
I also prefer the transition method...
- B O E
Back to top
 
 
View Profile   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.