Browse Source

memristor code model in extradev

h_vogt 14 years ago
parent
commit
f53eb5cf78
  1. 76
      examples/memristor/memristor_x.sp
  2. 109
      src/xspice/icm/xtradev/memristor/cfunc.mod
  3. 86
      src/xspice/icm/xtradev/memristor/ifspec.ifs
  4. 1
      src/xspice/icm/xtradev/modpath.lst

76
examples/memristor/memristor_x.sp

@ -0,0 +1,76 @@
Memristor with threshold as XSPICE code model
* Y. V. Pershin, M. Di Ventra: "SPICE model of memristive devices with threshold",
* arXiv:1204.2600v1 [physics.comp-ph] 12 Apr 2012,
* http://arxiv.org/pdf/1204.2600.pdf
* XSPICE code model, parameter selection and plotting by
* Holger Vogt 2012
.param stime=10n
.param vmax = 3
* send parameters to the .control section
.csparam stime={stime}
.csparam vmax={vmax}
*Xmem 1 0 memristor
* triangular sweep (you have to adapt the parameters to 'alter' command in the .control section)
*V1 1 0 DC 0 PWL(0 0 '0.25*stime' 'vmax' '0.5*stime' 0 '0.75*stime' '-vmax' 'stime' 0)
* sinusoidal sweep
V1 0 1 DC 0 sin(0 'vmax' '1/stime')
* memristor model with limits and threshold
* "artificial" parameters alpha, beta, and vt. beta and vt adapted to basic programming frequency
* just to obtain nice results!
* You have to care for the physics and set real values!
amen 1 2 memr
.model memr memristor (rmin=1k rmax=10k rinit=7k alpha=0 beta='20e3/stime' vt=1.6)
vgnd 2 0 dc 0
* This is the original subcircuit model
.subckt memristor plus minus PARAMS: Ron=1K Roff=10K Rinit=7.0K alpha=0 beta=20e3/stime Vt=1.6
Bx 0 x I='((f1(V(plus)-V(minus))> 0) && (V(x) < Roff)) ? {f1(V(plus)-V(minus))}: ((((f1(V(plus)-V(minus)) < 0) && (V(x)>Ron)) ? {f1(V(plus)-V(minus))}: 0)) '
Vx x x1 dc 0
Cx x1 0 1 IC={Rinit}
Rmem plus minus r={V(x)}
.func f1(y)={beta*y+0.5*(alpha-beta)*(abs(y+Vt)-abs(y-Vt))}
.ends
* transient simulation same programming voltage but rising frequencies
.control
*** first simulation ***
* approx. 100 simulation points
let deltime = stime/100
tran $&deltime $&stime uic
* plot i(v1) vs v(1)
*** you may just stop here ***
* raise the frequency
let newfreq = 1.1/stime
let newstime = stime/1.1
let deltime = newstime/100
alter @V1[sin] [ 0 $&vmax $&newfreq ]
tran $&deltime $&newstime uic
* raise the frequency even more
let newfreq = 1.4/stime
let newstime = stime/1.4
let deltime = newstime/100
alter @V1[sin] [ 0 $&vmax $&newfreq ]
tran $&deltime $&newstime uic
* the resistor currents
plot tran1.alli tran2.alli alli title 'Memristor with threshold: currents'
* calculate resistance (avoid dividing by zero)
let res = v(1)/(I(v1) + 1e-16)
let res1 = tran1.v(1)/(tran1.I(v1) + 1e-16)
let res2 = tran2.v(1)/(tran2.I(v1) + 1e-16)
* resistance versus time plot
settype impedance res res1 res2
plot res vs time res1 vs tran1.time res2 vs tran2.time title 'Memristor with threshold: resistance'
* resistance versus voltage (change occurs only above threshold!)
plot res vs v(1) res1 vs tran1.v(1) res2 vs tran2.v(1) title 'Memristor with threshold: resistance'
* current through resistor for all plots versus voltage
plot i(v1) vs v(1) tran1.i(v1) vs tran1.v(1) tran2.i(v1) vs tran2.v(1) title 'Memristor with threshold: external current loops'
.endc
.end

109
src/xspice/icm/xtradev/memristor/cfunc.mod

@ -0,0 +1,109 @@
/* ===========================================================================
FILE cfunc.mod
MEMBER OF process XSPICE
Copyright 2012
Holger Vogt
Mülheim, Germany
All Rights Reserved
AUTHORS
6/08/2012 Holger Vogt
MODIFICATIONS
<date> <person name> <nature of modifications>
SUMMARY
This file contains the definition of a memristor code model
with threshold according to
Y. V. Pershin, M. Di Ventra: "SPICE model of memristive devices with threshold",
arXiv:1204.2600v1 [physics.comp-ph] 12 Apr 2012,
http://arxiv.org/pdf/1204.2600.pdf.
** Experimental, still to be tested in circuits !! **
INTERFACES
cm_memristor()
REFERENCED FILES
None.
NON-STANDARD FEATURES
None.
=========================================================================== */
/*=== INCLUDE FILES ====================*/
#include <math.h>
#define RV 0
/* model parameters */
double alpha, beta, vt;
/* forward of window function */
double f1(double y);
void cm_memristor (ARGS)
{
// Complex_t ac_gain;
double partial;
double int_value;
double *rval;
double inpdiff;
/* get the parameters */
alpha = PARAM(alpha);
beta = PARAM(beta);
vt = PARAM(vt);
/* Initialize/access instance specific storage for resistance value */
if(INIT) {
cm_analog_alloc(RV, sizeof(double));
rval = (double *) cm_analog_get_ptr(RV, 0);
*rval = PARAM(rinit);
}
else {
rval = (double *) cm_analog_get_ptr(RV, 0);
}
/* Compute the output */
if(ANALYSIS == TRANSIENT) {
/* input the voltage across the terminals */
inpdiff = f1(INPUT(memris));
if ((inpdiff > 0) && (*rval < PARAM(rmax)))
int_value = inpdiff;
else if ((inpdiff < 0) && (*rval > PARAM(rmin)))
int_value = inpdiff;
else
int_value = 0.0;
/* integrate the new resistance */
cm_analog_integrate(int_value, rval, &partial);
/* output the current */
OUTPUT(memris) = INPUT(memris) / *rval;
PARTIAL(memris, memris) = partial;
}
/* no AC and DC modeling so far !
else if(ANALYSIS == AC) {
ac_gain.real = *vc;
ac_gain.imag = 0.0;
AC_GAIN(memris, memris) = ac_gain;
} */
}
/* the window function */
double f1(double y) {
return (beta*y+0.5*(alpha-beta)*(fabs(y+vt)-fabs(y-vt)));
}

86
src/xspice/icm/xtradev/memristor/ifspec.ifs

@ -0,0 +1,86 @@
/* ===========================================================================
FILE ifspec.ifs
MEMBER OF process XSPICE
Copyright 2012
Holger Vogt
Mülheim, Germany
All Rights Reserved
AUTHORS
06/08/2012 Holger Vogt
MODIFICATIONS
<date> <person name> <nature of modifications>
SUMMARY
This file contains the definition of a memristor code model
with threshold according to
Y. V. Pershin, M. Di Ventra: "SPICE model of memristive devices with threshold",
arXiv:1204.2600v1 [physics.comp-ph] 12 Apr 2012,
http://arxiv.org/pdf/1204.2600.pdf.
** Experimental, still to be tested in circuits !! **
INTERFACES
None.
REFERENCED FILES
None.
NON-STANDARD FEATURES
None.
=========================================================================== */
NAME_TABLE:
Spice_Model_Name: memristor
C_Function_Name: cm_memristor
Description: "Memristor interface"
PORT_TABLE:
Port_Name: memris
Description: "memristor terminals"
Direction: inout
Default_Type: gd
Allowed_Types: [gd]
Vector: no
Vector_Bounds: -
Null_Allowed: no
PARAMETER_TABLE:
Parameter_Name: rmin rmax rinit
Description: "minimum resistance" "maximum resistance" "initial resistance"
Data_Type: real real real
Default_Value: 10.0 10000.0 7000.0
Limits: - - -
Vector: no no no
Vector_Bounds: - - -
Null_Allowed: no no no
PARAMETER_TABLE:
Parameter_Name: alpha beta vt
Description: "model parameter 1" "model parameter 2" "threshold"
Data_Type: real real real
Default_Value: 0.0 1.0 0.0
Limits: - - -
Vector: no no no
Vector_Bounds: - - -
Null_Allowed: no no no

1
src/xspice/icm/xtradev/modpath.lst

@ -7,3 +7,4 @@ lcouple
lmeter
potentiometer
zener
memristor
Loading…
Cancel
Save