Forum
 Ken Kundert Global Moderator Offline Posts: 2294 Silicon Valley Re: variable resistor(current across resistor constant, voltage varying) Reply #2 - 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 Back to top IP Logged
 Paritosh Sahu New Member Offline Posts: 2 Re: variable resistor(current across resistor constant, voltage varying) Reply #3 - 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)); end endfunction analog function real res1; input arg2; real arg2; begin res1= abs((609.22*arg2 + 0.01255)/arg2); end endfunction analog function real res2; input arg3; real arg3; begin res2=abs((823.08*arg3 + 0.03566)/arg3); end endfunction 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); end endmodule ```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 Back to top IP Logged
 Ken Kundert Global Moderator Offline Posts: 2294 Silicon Valley Re: variable resistor(current across resistor constant, voltage varying) Reply #4 - Feb 28th, 2019, 7:12am   Wow. You kind of buried the lead with your original question.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 Back to top IP Logged