In 2009, Biolek et al. published a paper showing an idealized memristor model for a newly publicized memristor created at HP labs. The paper can be downloaded here. The model is referred to in a fews ways: “The Ideal Memristor”, “The nonlinear Dopant Drift” or “The Resistance Switch”. For anyone starting out simulating memristors in SPICE, this is probably the first thing you will try before getting into more complicated (and accurate) models. So after reading that paper and understanding the basic idea, the next step is to fire up SPICE and repeat the results in the paper. This blog post is about taking the model from the paper and getting the classic memristor hysteresis I-V plot in LTSpice. These concepts can be adapted for different SPICE simulators and models.

## Model Overview

The model is described quite well in the above referenced paper, but lets review the most critical pieces needed to understand how SPICE implementation works. In the model, there is a window function:

Which looks like this:

Notice that both the x axis domain and the y axis range are bound between 0 and 1.

If you plot the integral of this function between 0 and 1, you get this:

In this model the integral of the window function represents the state `x`

, between 0 and 1, and is used to dynamically change a `delta R`

value. `delta R`

is `Roff - Ron`

, and when in series with `Roff`

(and given a minus sign) defines the memristor resistance. Conveniently a current source in series with a `1F`

capacitor and a resistor creates an integrator circuit, where the voltage on node `x`

represents the integral.

## Download and Install LTSpice

If you haven’t already, you need to download and install LTSpice. I’m using a Mac so I installed it via homebrew: `brew cask install ltspice`

.

Note where the application installed, as we need to add some files in appropriate places. In my case the root directory is at `~/Library/Application\ Support/LTspice/`

.

## Add the Memristor Subcircuit and Symbol Files

The following code can be found on the memristor-models-4-all project.

Create a file called `memristor.sub`

and save it in `.../LTSpice/lib/sub`

. Put the following text in it:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
*********************************************** * HP Memristor SPICE Model * For Transient Analysis only * created by Zdenek and Dalibor Biolek *********************************************** * Ron, Roff - Resistance in ON / OFF States * * Rinit - Resistance at T=0 * * D - Width of the thin film * * uv - Migration coefficient * * p - Parameter of the WINDOW-function for * modeling nonlinear boundary conditions * * x - W/D Ratio, W is the actual width * of the doped area (from 0 to D) * *********************************************** .SUBCKT memristor plus minus PARAMS: + Ron=100 Roff=16K Rinit=11K D=10N uv=10F p=1 *********************************************** * DIFFERENTIAL EQUATION MODELING * *********************************************** Gx 0 x value={I(Emem)*uv*Ron/D**2*f(V(x),p)} Cx x 0 1 IC={(Roff-Rinit)/(Roff-Ron)} Raux x 0 1000000 *********************************************** * RESISTIVE PORT OF THE MEMRISTOR * *********************************************** Emem plus aux value={-I(Emem)*V(x)*(Roff-Ron)} Roff aux minus {Roff} *********************************************** * FLUX COMPUTATION * *********************************************** Eflux flux 0 value={SDT(V(plus,minus))} *********************************************** * CHARGE COMPUTATION * *********************************************** Echarge charge 0 value={SDT(I(Emem))} *********************************************** * WINDOW FUNCTIONS * FOR NONLINEAR DRIFT MODELING * *********************************************** * window function, according to Joglekar .func f(x,p)={1-(2*x-1)**(2*p)} .ENDS memristor |

Note that I changed the `p`

variable to 1. With `p=1`

the results will match what’s in the paper.

Create a file called `memristor.asy`

and save it in `.../LTSpice/lib/sym`

. Put the following text in it:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
Version 4 SymbolType BLOCK LINE Normal 8 33 -4 33 LINE Normal 0 -48 0 -32 LINE Normal 0 48 0 33 CIRCLE Normal 4 33 -4 0 CIRCLE Normal 4 -32 -4 0 SYMATTR SpiceModel memristor SYMATTR Prefix X SYMATTR Description Parameterized Memristor SYMATTR ModelFile memristor.sub PIN 0 -48 RIGHT 8 PINATTR PinName A PINATTR SpiceOrder 1 PIN 0 48 RIGHT 8 PINATTR PinName B PINATTR SpiceOrder 2 |

This file defines a new graphical symbol for the memristor.

## Add the Simulation File

Create a file called `memristor_sim.asc`

and save it in somewhere in your normal documents directory such as `~/Documents/LTSpice`

. This is the directory created by LTSpice on my machine and contains some example simulation files already.

## Open the Simulation File

## Set up a Few Things before Running SPICE Simulation

In the schematic window, click the tools button.

Make sure the following options are checked:

## Run Simulation and View Results

After clicking the run button, a blank plot will pop up. You need to select all the correct traces by right-clicking and selecting `add Traces`

. Just select `Ix(Memristor:A)`

.

Next, on the plot, click on the X axis and change `time`

to `V(n001)`

.

Now you should see the I-V pinched hysteresis plot.

Next you can clear the plot pane and add several other simulation results as a function of time:

Here we see from top down:

- The state variable
`x`

. Note it’s between 0 and 1 - The charge through the device
- The flux through the device

## Conclusion

While we wouldn’t claim that this memristor model is an ideal model for Knowm’s memristors (or any memristor really), understanding how the mathematics of the model works as well as the mechanics of the SPICE simulation and the memristor subcircuit is an important step towards developing better models. Be sure to stay tuned by signing up for our newsletter and/or subscribing to our RSS feed to get the latest information about our memristor modeling progress. In the future, we will be blogging about other SPICE tools, our Metastable Switch memristor model, and other memristor modeling advancements!

## Further Resources

- Knowm Memristors
- The Generalized Metastable Switch Memristor Model
- The Problem is Not HP’s Memristor–It’s How They Want To Use It
- memristor-models-4-all Project on Github
- The Pershin Voltage Threshold Memristor Model in NGSpice
- Build Xyce from Source for ADMS Verilog-A Model Integration
- Well-posed Memristor Modeling with Xyce and Verilog-A

## Subscribe To Our Newsletter

Join our low volume mailing list to receive the latest news and updates from our team.