The Designer's Guide Community Forum https://designers-guide.org/forum/YaBB.pl Design Languages >> Verilog-AMS >> variable resistor(current across resistor constant, voltage varying) https://designers-guide.org/forum/YaBB.pl?num=1551177912 Message started by Paritosh Sahu on Feb 26th, 2019, 2:45am

 Title: variable resistor(current across resistor constant, voltage varying) Post by Paritosh Sahu on Feb 26th, 2019, 2:45am Hello everyone,I am trying to model a variable resistor where the current across the resistor stays the same and acts as the input, and the voltage drop is dependent on the resistance change.So, will V(t,b)<+I(t,b)*transition(rout,1n,1n); work in this case?The rout transitions between two values at different times which is defined by the timer function.I am getting convergence errors in SPICE when I do it this way. Is it because the resistance value is becoming negative in some case? or some other reason?I have to put this device as feedback in an inverting amplifier op-amp configuration.When I had modeled the device as a voltage-dependent resistor as,I(t,b)<+ V(t,b)/transition(rout,1n,1n), it was working fine.Thanks for the help.-Paritosh

 Title: Re: variable resistor(current across resistor constant, voltage varying) Post by Geoffrey_Coram on Feb 27th, 2019, 5:37am I'm not a big fan of the transition() function; it makes sense when you're modeling logic gates and want the output to "transition" from high to low. But for a resistor or anything "analog", I stay away from it.Is rout set to fixed values at different times by the timer? Or does the timer trigger an evaluation that then depends on voltages or currents? Is the resistance value becoming negative, do you know this is actually happening? In that case, yes, this is very likely to be the cause of convergence problems. Does a negative resistance make any sense in your circuit?

Title: Re: variable resistor(current across resistor constant, voltage varying)
Post by Ken Kundert on Feb 27th, 2019, 1:59pm

I know of no reason why

Code:
 V(t,b)<+I(t,b)*transition(rout,1n,1n);

should cause convergence errors, and I do not share Geoffrey's dislike of the transition function in the case. Presumably you are trying to model some combination of switches and resistors. Including the transition function prevents a discontinuous jump in the resistance, which could cause convergence issues.

The resistance will not go negative as long as rout is always non-negative.

I see a lot of people use short delays and short transition times without thinking. You should be aware that they slow the simulation. You should avoid using the delay at all unless it is important, and the transition time should be as large as you are comfortable with. So something like:

Code:
 V(t,b)<+I(t,b)*transition(rout,0,100n);

would be better.

It is hard to help you with so little information. You would be better served by giving the whole model, and perhaps even enough information so that we could duplicate your situation. For example, one thing that could be causing problems if rout were varying continuously or if it was a function of I or V.

-Ken

Title: Re: variable resistor(current across resistor constant, voltage varying)
Post by Paritosh Sahu on Feb 28th, 2019, 4:59am

Thank you, Geoffrey and Ken, for the feedback. I apologize for the insufficient information. I will write my detailed model code here.

So, the basic conditions of my device are:

1. The device is current dependent, means the input is current.

2. The current across the device remains the same, but the resistance of the device transitions between two specific values. So, basically, the voltage drop across the device follows the resistance change.

3. The values of the resistance are a function of the input current.

4. The transition between the resistance values happens at random time instances within the simulation time. How many of these transitions occur within a particular time interval is again a function of the input current.

As I intend to use this device in the feedback loop of an inverting op-amp configuration, I thought to model it as a variable resistor. Any other suggestions are welcome.

The code is as follows:

Code:
 'include "constants.vams"'include "disciplines.vams"module dev(p1,a1);inout p1,a1;electrical p1,a1;parameter real t_tot=0.1;parameter ref_time=10u;parameter integer x1=0;parameter integer x2=2;integer u1=65;integer f=0;real t1,r1,t2,t3,cur,rout;analog function integer spike;  //return the total no.of transition events                input arg;            real arg;            begin                                    spike=abs(1.493e-26*exp(7.971e4*arg));            endendfunctionanalog function real res1;            input arg2;            real arg2;            begin                  res1= abs((609.22*arg2 + 0.01255)/arg2);            endendfunction      analog function real res2;            input arg3;            real arg3;            begin                  res2=abs((823.08*arg3 + 0.03566)/arg3);            endendfunction      analog begin           cur=I(p1,a1); //Throughout my simulation, the current remains constant           r1=\$rdist_uniform(u1,x1,x2);           t1=r1*(t_tot/spike(cur)); //controls the transition frequency           u1=u1+\$random;           @(timer(t3,,1n)) begin   //start of current transition event                       rout=res1(cur);  //state 1                       t3=\$abstime+t1;    //time for next event start                       t2=\$abstime+ref_time; //time for end of current event           end           if(f>=spike(cur))   //change to state 2 at the end of all events              rout=res2(cur);           @(timer(0.1,0.1,1n)) begin   //reset counter after all events occur                      f=0;           end           @(timer(t2,,1n)) begin   //end of present event                       rout=res2(cur);   //state 2                       f=f+1;   //counter for no.of transitions           end           V(p1,a1)<+ I(p1,a1)*transition(rout,0n,0n,0n);endendmodule

I would really appreciate some feedback on the code. Kindly please let me know if I am doing any mistake anywhere. And what exactly is causing the convergence error here?

As far as I have checked in the values, there are no negative values of rout. The value of rout is dependent on I, but it stays constant throughout the simulation.

Thanks a lot.

-Paritosh Sahu

Title: Re: variable resistor(current across resistor constant, voltage varying)
Post by Ken Kundert on Feb 28th, 2019, 7:12am

Your model seems very complicated, and there is a lot of it where I cannot tell whether it makes sense or not. But I can see two obvious issues:

You should not use 0 for transition times on transition function in this statement:

Code:
 V(p1,a1)<+ I(p1,a1)*transition(rout,0n,0n,0n);
. Making the delay 0 is fine, but you should set the transition time to something nonzero.

This statement is problematic given the rest of your model:

Code:
 if(f>=spike(cur))   //change to state 2 at the end of all events              rout=res2(cur);

When f is greater than spike(cur) then rout varies continuously in time, making it unsuitable as an argument to the transition function. The argument of the transition function must be piecewise constant. Using a continuously varying expression as an argument to a transtion function results in erratic behavior as the transition function wants to generate a continuous stream of transitions, so it keeps interrupting itself.

Also, making rout a function of cur makes the resistor nonlinear, which is likely the ultimate cause of your convergence issues.

Finally, I am always a bit suspicious of the use of the abs() function in device models. They have a tendency of creating non-physical kinks in the IV characteristics.

-Ken