Difference between revisions of "Ngspice Tutorial"

From Microlab Classes
Jump to navigation Jump to search
Line 12: Line 12:
 
Let's simulate the circuit in Fig. 1 using ngspice. Note that we labeled every device ('''Q1''', '''Vbe''', and '''Vce'''), as well as labeled every unique node ('''b1''', '''c1''', and '''0''').
 
Let's simulate the circuit in Fig. 1 using ngspice. Note that we labeled every device ('''Q1''', '''Vbe''', and '''Vce'''), as well as labeled every unique node ('''b1''', '''c1''', and '''0''').
  
[[File:Eee51 cir 01.png|thumb|350px|Figure 1: Our first circuit.]]
+
[[File:Eee51 cir 01.png|thumb|center|350px|Figure 1: Our first circuit.]]
  
 
First, we need to describe the circuit using a "SPICE deck". In the 1970's, punched cards were used, and hence the reference to a "deck" of cards. Now, this just refers to a text file containing a description of our circuit. Since our description will contain circuit elements and nodes (or "nets"), this file is also commonly known as a "netlist".
 
First, we need to describe the circuit using a "SPICE deck". In the 1970's, punched cards were used, and hence the reference to a "deck" of cards. Now, this just refers to a text file containing a description of our circuit. Since our description will contain circuit elements and nodes (or "nets"), this file is also commonly known as a "netlist".
  
 
This is the [https://github.com/louisalarcon/eee51_tutorials/blob/master/tutorials/circuit1.sp netlist] for the circuit in Figure 1:
 
This is the [https://github.com/louisalarcon/eee51_tutorials/blob/master/tutorials/circuit1.sp netlist] for the circuit in Figure 1:
 +
 +
<syntaxhighlight line>
 +
* Transistor Characteristic Curves
 +
* LPA 2020-04-16
 +
 +
.include 2N2222A.lib
 +
.options savecurrents
 +
 +
Q1  c1 b1 0    Q2n2222a
 +
Vbe b1 0        dc 0
 +
Vce c1 0        dc 0.2
 +
 +
.control
 +
 +
dc Vbe 500m 750m 1m
 +
 +
wrdata circuit1.dat @Q1[ic]
 +
 +
.endc
 +
 +
.end
 +
</syntaxhighlight>

Revision as of 13:50, 4 August 2020

Predicting the behavior of an electronic circuit using simulation tools enables us to run experiments, explore a larger set of alternatives, and verify results quickly and inexpensively.

Most modern circuit simulators are based on the SPICE (Simulation Program with Integrated Circuit Emphasis) simulator, developed at UC Berkeley, and first presented in 1973. In this tutorial, we will use ngspice, and just like the original Berkeley SPICE, it is open source.

Classes Using this Tutorial

  • EE 220 Analog Integrated Circuits

Installing ngspice

ngspice is available for Linux, MacOS, and Windows machines. Visit the ngspice download page for specific installation instructions. The user manual is available here.

Our First Circuit

Let's simulate the circuit in Fig. 1 using ngspice. Note that we labeled every device (Q1, Vbe, and Vce), as well as labeled every unique node (b1, c1, and 0).

Figure 1: Our first circuit.

First, we need to describe the circuit using a "SPICE deck". In the 1970's, punched cards were used, and hence the reference to a "deck" of cards. Now, this just refers to a text file containing a description of our circuit. Since our description will contain circuit elements and nodes (or "nets"), this file is also commonly known as a "netlist".

This is the netlist for the circuit in Figure 1:

* Transistor Characteristic Curves
* LPA 2020-04-16
 
.include 2N2222A.lib
.options savecurrents
 
Q1  c1 b1 0     Q2n2222a
Vbe b1 0        dc 0
Vce c1 0        dc 0.2
 
.control
 
dc Vbe 500m 750m 1m
 
wrdata circuit1.dat @Q1[ic]
 
.endc
 
.end