Quickstart guide to run ngspice

1. CMOS inverter netlist

C5_inverter_VTC.cir
*** SPICE deck for C5_inverter_VTC.cir

.global gnd vdd

* MOSTs models
.include ../../class/models/C5_models_bsim3.mod

* circuit (CMOS inverter)
Mnmos out in gnd gnd NMOS L=0.6U W=3U
Mpmos vdd in out vdd PMOS L=0.6U W=6U
Vin in gnd DC 0V
VDD VDD 0 DC 5

* Analysis (VTC)
.DC Vin 0 5 1m

* Outputs
.PLOT DC V(out) v(in)
.END

2. Browse to the location of the netlist

$ cd //VBOXSVR/talarico/ngs406/Electric

3. Create an initialization file .spiceinit with the following configurations

.spiceinit
set ngbehavior=hs
set ng_nomodcheck
set color0=white
set color1=black
set xbrushwidth=2
  • the behavior of ngspice is set in hspice compatibility mode

  • any model parameter check is suppressed

  • color0 is the background

  • color1 is the text and the grid

  • xbrushwidth is the Linewidth of the graphs

4. Start ngspice in interactive mode

$ ngspice
 

5. Have ngspice parsing the netlist

ngspice 1 -> source C5_inverter_VTC.cir

6. Run the simulation

ngspice 2 -> run
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

Warning: Pd = 0 is less than W.
Warning: Ps = 0 is less than W.
Warning: Pd = 0 is less than W.
Warning: Ps = 0 is less than W.

No. of Data Rows : 5001

7. Display all vectors

ngspice 3 -> display
Here are the vectors currently active:

Title: *** spice deck for cell c5_inverter_vtc{sch} from library c5_cmos
Name: dc1 (DC transfer characteristic)
Date: Fri Nov  5 20:28:26  2021

    in                  : voltage, real, 5001 long
    out                 : voltage, real, 5001 long
    v-sweep             : voltage, real, 5001 long [default scale]
    vdd                 : voltage, real, 5001 long
    vdd#branch          : current, real, 5001 long
    vin#branch          : current, real, 5001 long

8. Display all voltages

ngspice 4 -> display allv
    in                  : voltage, real, 5001 long
    out                 : voltage, real, 5001 long
    v-sweep             : voltage, real, 5001 long [default scale]
    vdd                 : voltage, real, 5001 long

9. Display all currents

ngspice 5 -> display alli
    vdd#branch          : current, real, 5001 long
    vin#branch          : current, real, 5001 long

10. Plot v(in) and v(out)

ngspice 6 -> plot v(in) v(out)
 

11. Other common commands that can be used with the interactive interpreter are:

  • listing

  • show

  • showmod

  • history

  • shell [command]

  • getcwd

  • cd

  • load [rawfile]

  • write [rawfile]

12. For more information look up the ngspice manual