Converting Ngspice to PSpice for Memristor Modeling

  • Thread starter captainkirk86
  • Start date
  • Tags
    Pspice
In summary, Captain Kirk can help you convert your Ngspice code to PSpice. However, you need to provide more information to help him, such as a circuit diagram and simple expressions.
  • #1
captainkirk86
4
0
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
 
Engineering news on Phys.org
  • #2
I can help you. But can you be a little more clear with simple circuit diagram and simple expressions?
 
  • #3
Hi there, thanks for replying.

I've attached the circuit diagram as image.

PLEASE NOTE - I don't 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.

I appreciate any help you can provide here!

Many thanks again
CaptainKirk
 
Last edited:
  • #4
attached file
 

Attachments

  • circuit.png
    circuit.png
    8.2 KB · Views: 548
  • #5
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
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
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:
* 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.
 

Attachments

  • test.jpg
    test.jpg
    43.6 KB · Views: 507
  • Like
Likes mamuu
  • #8
Sorry for the late. I had actually forgotten about it after your last post. Shows kinda lazy person I am. haha
 
  • #9
Kholdstare

Thank you were much with your reply!

I can hardly call you lazy, after all you did come up with something very interesting.

I'm very impressed with your model. Its is different from what I came up with but I still like the output graph that you attached!

Thank you once again

Kind regards,
Kirk
 

What is Ngspice to PSpice conversion?

Ngspice to PSpice conversion is the process of converting a circuit design from the Ngspice software to the PSpice software. This allows for compatibility and simulation of the same circuit in both software programs.

Why would someone want to convert from Ngspice to PSpice?

There are a few reasons why someone may want to convert from Ngspice to PSpice:

  • Compatibility: If a circuit design was created in Ngspice, it may need to be converted to PSpice in order to be used by someone who only has access to PSpice.
  • Simulation differences: Ngspice and PSpice have different simulation engines, so converting a circuit design from one software to the other may provide different results and allow for comparison.
  • Personal preference: Some users may prefer the interface or features of PSpice over Ngspice.

What are the steps to convert from Ngspice to PSpice?

The general steps to convert from Ngspice to PSpice are:

  1. Export the Ngspice netlist file (.cir) from Ngspice.
  2. Open the PSpice software and create a new project.
  3. Import the Ngspice netlist file into the PSpice project.
  4. Adjust any syntax differences between Ngspice and PSpice in the netlist file.
  5. Run the simulation in PSpice and compare results to the Ngspice simulation.

Are there any limitations or challenges when converting from Ngspice to PSpice?

Yes, there can be limitations and challenges when converting from Ngspice to PSpice. Some of these include:

  • Syntax differences: Ngspice and PSpice have some differences in their netlist syntax, so the netlist file may need to be manually adjusted.
  • Simulation differences: As mentioned before, Ngspice and PSpice have different simulation engines, so the results may not be exactly the same.
  • Component libraries: PSpice and Ngspice may have different component libraries, so some components may not be available in the other software.

Is there a way to automate the conversion process?

Yes, there are some tools and scripts available that can automate the conversion process from Ngspice to PSpice. However, it is important to double check the results and make any necessary adjustments, as automation may not always be perfect.

Similar threads

  • Advanced Physics Homework Help
Replies
6
Views
2K
  • Calculus and Beyond Homework Help
Replies
7
Views
1K
Replies
7
Views
2K
  • Introductory Physics Homework Help
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
275
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
  • Programming and Computer Science
Replies
6
Views
5K
  • Advanced Physics Homework Help
Replies
7
Views
4K
  • Introductory Physics Homework Help
Replies
8
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
Back
Top