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