Sunday 20 January 2019

linux - How to get started using ngspice?


I've recently finished some work with hspice, and now I don't have access to the server. I've installed ngspice on my Fedora 15 machine, but I'm unfamiliar with how it works. In hspice, I was able to produce an output file with measured values and a set of waveforms that were plotted out with cosmosscope easily.


However, I'm unsure of how to do this in ngspice. Here's some basic SPICE code:


Transient Response of a Linear Network


** Circuit Description **

* input signal source
Vi 1 0 SIN ( 0V 10V 60Hz )
* linear network
R1 1 2 1Ohm
C1 2 0 2.65mF
Rload 3 0 10Ohm
E1 3 0 2 0 10


** Analysis Request **
* compute transient response of circuit over three full
* periods (50 ms) of the 60 Hz sine-wave input with a 1 ms
* sampling interval
.TRAN 1ms 50ms 0ms 1ms

** Output Request **
* print the output and input time-varying waveforms
.PRINT TRAN V(3) V(1)
* plot the output and input time-varying waveforms

* set the range of the y-axis between -100 and +100 V
.PLOT TRAN V(3) V(1) (-100,+100)

.END

How to I get ngspice to output the values requested as well as plot the values requested AT ONCE?


UPDATE: I've gotten more familiar with ngspice. It seems it was indeed able to output the data I wanted and it can plot data. However, I have to do this separately with different commands in the ngspice interpreter. I'm wondering how can I get ngspice to simply plot everything and output all the data in a single go. Here's a picture of how it works:



Answer



You can put interpreter command between .control and .endc commands in the circuit file. This way they should run together with the simulation.


PS. For more involved plotting and post-processing you can start with tabular data from SPICE and feed it to gnuplot or Python+numpy+matplotlib.



PS. Keep in mind that ngspice is based on Berkeley Spice 3 (rewritten in C) while most commercial SPICE engines were based on the 2nd version (in Fortran). Differences are mostly with ngspice supporting textual node names and arbitrary mathematical functions in dependent current/voltage sources. This last thing frequently causes headaches when trying to use manufacturer provided IC models which use the old (and unsupported in ngspice) POLY declaration.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...