The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
May 2nd, 2024, 12:01am
Pages: 1 2 
Send Topic Print
Current switching (Read 16557 times)
noreng
Junior Member
**
Offline



Posts: 20

Current switching
Aug 24th, 2005, 3:40am
 
I want to make a verilog-ams module which routes an incoming current through 2 voltage controlled resistors. The resistors are connected to a common node p and separate nodes n1 and n2.

Part of the code is shown below where reff1 and reff2 are the VCRs.

I(p,n1) <+ I(<p>)*reff1/(reff1+reff2);
I(p,n2) <+ I(<p>)*reff2/(reff1+reff2);

When running a simulation, the output currents approach zero amps. Seems like the simulator isn't able to have sort of the same current on both sides of the expressions.
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2384
Silicon Valley
Re: Current switching
Reply #1 - Aug 24th, 2005, 6:47am
 
Those are not resistors. They are current controlled current sources.

-Ken
Back to top
 
 
View Profile WWW   IP Logged
noreng
Junior Member
**
Offline



Posts: 20

Re: Current switching
Reply #2 - Aug 24th, 2005, 7:08am
 
reff1 and reff2 are defined as resistors, but have not been included since it is only the enclosed code which should be of interest.
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2384
Silicon Valley
Re: Current switching
Reply #3 - Aug 24th, 2005, 10:28am
 
With the code you have given, if I(<p>) is zero then both I(p,n1) and I(p,n2) will be zero. Is there any reason to believe that I(<p>) should not be zero?

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



Posts: 1998
Massachusetts, USA
Re: Current switching
Reply #4 - Aug 24th, 2005, 10:37am
 
I always get myself confused when thinking about the "p" and "n" nodes of current sources ... maybe you've set something up so that zero is the only valid solution?

Since you're intending for the currents to add up to zero, let's build that assumption into the model:

I(n1) <+ I(p)*reff1/(reff1+reff2);
I(n2) <+ I(p)*reff2/(reff1+reff2);

Now, if there's a KCL problem because of the signs, you'll be dumping the excess into ground -- I(p) measures the short-circuit current on the branch from p to ground.  Then you can multiply by -1 if the currents are all going in.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
noreng
Junior Member
**
Offline



Posts: 20

Re: Current switching
Reply #5 - Aug 24th, 2005, 11:21pm
 
The simulation result of zero is wrong.

In fact, I want to pass a dc current from spice into the verilog-a module and that the sum of the currents exiting from n1 and n2 should be equal to the current entering at p.

However, running a simulation gives a result near zero.
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2384
Silicon Valley
Re: Current switching
Reply #6 - Aug 25th, 2005, 12:05am
 
You have given us so little information it is very difficult to help you. Perhaps you give us the whole model definition, or at least more of it.

So far, if we just focus on node p, what we have is that
I(p) + I(p) =  I(p)*(reff1+reff2)/(reff1+reff2)
which simplifies down to
2 = 1
This suggests that the model is ill-formed. Is there another path for the current entering p?

-Ken
Back to top
 
 
View Profile WWW   IP Logged
noreng
Junior Member
**
Offline



Posts: 20

Re: Current switching
Reply #7 - Aug 25th, 2005, 12:26am
 
The spice code follows below.

vdda avdd 0 vdd
iref avdd top iref

ys1 test_switch port: top out1 out2 0

rl1 out1 0 rload
rl2 out2 0 rload

Thus, current from the iref source should enter at top which is the same node as p in the verilog-a module.

The current should exit at out1 and out2 (corresponding to n1 and n2 in the verilog-a module).

Thus, Itop = Iout1 + Iout2
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1998
Massachusetts, USA
Re: Current switching
Reply #8 - Aug 25th, 2005, 5:29am
 
[quote author=Ken Kundert  link=1124880048/0#6 date=1124953558]
So far, if we just focus on node p, what we have is that
I(p) + I(p) =  I(p)*(reff1+reff2)/(reff1+reff2)
which simplifies down to
2 = 1
[/quote]

Ken -
I thought that I(p,n1) <+ contributes current to the (unnamed) branch from p to n1 -- similar for I(p,n2).  I(<p>) measures the port current -- I visualize it as a 0V voltage source between the terminal p and an internal node, from which the two current-source branches feed out.  So, I don't see the 2=1 problem you claim.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1998
Massachusetts, USA
Re: Current switching
Reply #9 - Aug 25th, 2005, 5:49am
 
This is "test_switch.va"
Code:
`include "discipline.h"

module test_switch(p,n1,n2);
  inout p,n1,n2;
  electrical p,n1,n2;
  parameter real reff1 = 1 from (0:inf);
  parameter real reff2 = 1 from (0:inf);

  analog begin
    I(n1) <+ -I(p) * reff1/(reff1+reff2);
    I(n2) <+ -I(p) * reff2/(reff1+reff2);
  end
endmodule

 


and here is my netlist:
Code:
*
simulator lang=spectre

vdda (avdd 0) vsource dc=5
iref (avdd top) isource dc=1

ahdl_include "test_switch.va"
ys1 (top out1 out2) test_switch reff1=1 reff2=2

rl1 (out1 0) resistor r=1k
rl2 (out2 0) resistor r=1k

save ys1:all rl1:all rl2:currents top out1 out2
dc1 dc dev=iref start=0 stop=5
 



I see the current divided in a 1:2 ratio.

I don't quite understand why I get a different answer if I use
       I(p,n1) <+ I(<p>) * reff1/(reff1+reff2);
       I(p,n2) <+ I(<p>) * reff2/(reff1+reff2);
I get a 1:2 ratio, and the currents aren't all zero, but the currents into test_switch ys1 don't add up to zero.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
noreng
Junior Member
**
Offline



Posts: 20

Re: Current switching
Reply #10 - Aug 25th, 2005, 6:24am
 
I've been experimenting some more with the current switching.

If I let the resistors stay constant in a transient analysis, the output currents are as expected. However, if I let the resistors vary vs. time, i.e. I use voltage controlled resistors controlled by a square wave and its inverse, the output currents become zero.

If I instead calculate the output currents, set them equal to a real variable and write the values to a file, the values in the file look normal.
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2384
Silicon Valley
Re: Current switching
Reply #11 - Aug 25th, 2005, 8:09am
 
Okay, sorry. The 2 = 1 statement was a mistake, but the model as originally given is still ill-conditioned. To see it, call (p,n1) branch 1 and (p,n2) branch 2. Clearly,
I(<p>) = I(branch1) + I(branch2)
Now
I(branch1) = a1*I(<p>)
I(branch2) = a2*I(<p>)
where a1=reff1/(reff1+reff2) and a2 = reff2/(reff1+reff2). Thus,
I(<p>) = (a1+a2)*I(<p>)
which is only true if (a1+a2) is exactly equal to 1. If it is not, there is no solution. Thus, this system is singular, which would explain the odd behavior.

You would be better served reformulating the model as Geoffrey proposed. By doing so, you eliminate the ill-conditioning and cleary define the input impedance of your model to be 0 and your output conductance of both outputs to be 0.

Oh, and reff1 and reff2 are not resistors. They are numbers that determine the current division ratio between two current controlled current sources. Nowhere does the model exhibit a resistance of either reff1 or reff2.

-Ken
Back to top
 
« Last Edit: Aug 25th, 2005, 10:43am by Ken Kundert »  
View Profile WWW   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1998
Massachusetts, USA
Re: Current switching
Reply #12 - Aug 25th, 2005, 8:28am
 
Noreng -
I'm not sure what you mean when you say "resistors" -- as Ken pointed out, reff1 and reff2 are just numbers.  I don't think you're varying the load resistors rl1 and rl2.

Perhaps you are doing something odd to generate the values of reff1 and reff2 from your square wave?  In which case, you should show us how those values vary.

Ken -
Since (a1+a2) = (reff1+reff2)/(reff1+reff2), won't this always be exactly 1?  Are you concerned about roundoff?
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: 2384
Silicon Valley
Re: Current switching
Reply #13 - Aug 25th, 2005, 11:18am
 
Yes.

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



Posts: 1998
Massachusetts, USA
Re: Current switching
Reply #14 - Aug 25th, 2005, 11:28am
 
Actually, the problem is this: noreng has defined a current-source cut-set, which is a topology error.  The node "top" can be isolated by removing a cut-set of only (ideal) current sources, which means that its voltage is arbitrary.

Probably what's happening is noreng's simulator is adding a Gmin from top to ground, and *all* the current from the iref current source is going through this conductance.  The fact that v(top) is now going through the roof doesn't matter; the current sources don't care.

My recommended solution fixes this by shorting "top" to ground, so that its voltage is known.
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 2 
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.