veriloga code of a switch

Status
Not open for further replies.

pankaj jha

Full Member level 3
Joined
Apr 16, 2010
Messages
170
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
jaipur
Visit site
Activity points
2,457
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
 

But the switch doesn't seem to work..

That isn't much to go on. Are you getting syntax errors, or is your circuit just not doing what you want in your testbench? (I didn't throw down the code to try to run it yet)

One question though, are 'p' and 'n' supposed to be inputs, outputs, or inouts? The code you posted is missing the port direction statements for those ports. I would suppose they are supposed to be 'inout'.
 

I would recommend that you treat it as a voltage controlled
resistor, and that you make the control of resistance be a
tanh() based function. This, to eliminate discontinuities in
the transfer function which will drive numerical solutions
crazy if their search range straddles the switchpoint. The
tanh() is bounded and has bounded derivatives as well.
Using the $discontinuity, whatever that means, looks more
like a patch or error trap than a clean math approach.
 



Dear dick_freebird,
Ya that may be the problem.. can u provide me an example code with the tanh()
function?? appropriate link/reference is welcome.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…