Ngspice to PSpice conversion

1. Jun 1, 2012

captainkirk86

Hi All,

I have a piece of Ngspice code that I need to convert to PSpice. I feel it is a simple matter of syntax but I have so far failed to make it work.

The code models a Memristor with thresholding ability (the fourth fundamental component along with resistors, capacitors, and inductors)

The code is as follows:

.subckt memristor plus minus PARAMS: Ron=1K Roff=10K Rinit=5K alpha=0 beta=1E13 Vt=4.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}'
Cx x 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

The code explanation is as follows:
- The memristive system is realized as a sub-circuit combining a behavioral resistor R, a current source ↑, and a capacitor C.
- The second line of code (Bx ...) defines the current source with the current specified through ternary functions. (A ternary function is defined in the code as a ? b : c , which means ”IF a, THEN b, ELSE c” [17].) The purpose of these functions is to limit RM between Ron and Roff.
- The third line of the code specifies the capacitor C (Cx ...) with an initial condition.
- The fourth line (Rmem ...) defines the behavioral resistor whose resistance takes the same numerical value as the voltage across the capacitor.
- The next line (.func ...) provides the function f according to Equation (not important here)

If you can help me in any way that would be great!!

Many thanks
Captainkirk

2. Jun 1, 2012

Kholdstare

I can help you. But can you be a little more clear with simple circuit diagram and simple expressions?

3. Jun 1, 2012

captainkirk86

I've attached the circuit diagram as image.

PLEASE NOTE - I dont need help with the Model, I just need help with syntax. Thats the code I gave in my first post just needs its syntax tweaked so it is compatible with Pspice.

The research paper that I'm referring to states the following for the Spice model:

"SPICE model: The memristive devices with threshold that we consider are those described by
I = X-1VM
X ̇ = (βVM +0.5(α−β)[|VM +Vt|−|VM −Vt|])

where Vt is the threshold voltage, Ron and Roff are limiting values of the memristance RM ≡ X, and the θ-functions

Note - These equations are represented in ngspice code I gave in my first post.

- The important model parameters are the coefficients α and β that characterize the rate of memristance change at |VM|<Vt and |VM|>Vt , respectively.
- These two coefficients define the slopes of the f (VM) curve below and above the threshold. When α = 0, the device state changes only if |VM| > Vt"

Please let me know if this makes it clearer.

Many thanks again
CaptainKirk

Last edited: Jun 1, 2012
4. Jun 1, 2012

captainkirk86

attached file

File size:
9.2 KB
Views:
139
5. Jun 1, 2012

Kholdstare

Captainkirk, I really did not try to understand the model. Actually I could not make out the ngspice syntax. I am working on it. You'll get your spice model after sometime.

6. Jun 3, 2012

h_vogt

Kholdstare,

see the ngspice-users forum (I am not allowed to give the link here).

captainkirk is engaging at least three forums ...

But is was nice just to get it up and running.

Regards

Holger

7. Jun 3, 2012

Kholdstare

Here's your PSpice macromodel as requested. To use it in your circuit just copy the "* memres ... begins" to "* memres ... ends" portion to your circuit and call the model using "X(ref) (node1) (node2) R_MEMR PARAMS: VCUT=(param) ALPHA=(param) BETA=(param)" device card.

Code (Text):
* memresistor model begins

.MODEL SWD D IS=1E-16 N=0.001

.FUNC GET_R1(ALPHA) {1/ALPHA}
.FUNC GET_R2_R3(ALPHA,BETA) {1/ABS(BETA-ALPHA)}
* ABS is given to prevent negative resistance

.SUBCKT R_MEMR 1 2
* Default parameters defined below
+ PARAMS: VCUT=1V ALPHA=0.1M BETA=0.2M
R1 1 2 {GET_R1(ALPHA)}
D2 1 3 SWD
V2 3 4 {VCUT}
R2 4 2 {GET_R2_R3(ALPHA,BETA)}
D3 5 1 SWD
V3 6 5 {VCUT}
R3 6 2 {GET_R2_R3(ALPHA,BETA)}
.ENDS

* memresistor model ends

*Test ckt

* The voltage source
V1 1 0 0Vdc
* The memresistor (new parameters are passed as arguments)
XMEMR_1 1 0 R_MEMR PARAMS: VCUT=4.6V ALPHA=0 BETA=1E-3

.DC V1 -8 8 0.01
.PROBE
.END
The test parameters I used are Vcut = 4.6V, alpha = 0, beta = 1e-3
The test result is in the attachment.

I simplified your expression as written below,
I = a*V for |V| < Vt
= a*V+(b-a)(V-Vt) for V>Vt
= a*V+(b-a)(V+Vt) for V<Vt

I could not model capacitance as you did not give its expression clearly.

File size:
43.6 KB
Views:
132
8. Jun 3, 2012

Kholdstare

Sorry for the late. I had actually forgotten about it after your last post. Shows kinda lazy person I am. haha

9. Jun 4, 2012

Kholdstare