Simple NMOS Simulation with gEDA

I’m currently taking a micro- and nanoelectronics lecture, and the exercises include some simulations of electronic circuits. However, the software introduced in class was some Windows-based proprietary stuff, so I had to look for a free software alternative that would work on Linux and support SPICE-style component specifications. I quickly found out that gEDA (GPL Electronic Design Automation) combined with Gnucap should meet the requirements, but sadly its documentation is not exactly beginner-friendly. The most helpful source I used was “GEDA and GnuCap for Beginners“, but although I can recommend it, it didn’t cover some things I would’ve liked to know while including stuff I don’t need, so after getting things to work I decided to write my own small tutorial. As an example, I’m going to show you how to create the set of characteristic curves of an NMOS transistor. There may be better ways to do this, but here’s what worked for me. If you have an idea how to improve this tutorial, please leave a comment!


I simply installed gEDA and Gnucap from the Ubuntu packet repository. To draw graphs, you’ll also need Gwave or Gnuplot. In Ubuntu, the relevant packages are called geda, gnucap, gwave and gnuplot.

Creating a circuit layout

The first thing you need is a layout for the circuit to simulate. To measure the set of characteristic curves of an NMOS transistor, you’ll need the transistor, two voltage supplies (one for the gate, one to provide the drain-source current) and a ground connector. The gEDA component for this task is called gschem.

Gschem window showing the example layout with NMOS transistor, two voltage supplies, ground and various labels

In gschem, use the Add → Component menu entry or press i. The component dialog will open. Find the following components for transistor, voltage supplies and ground using the filter below the component list, and add them (don’t forget that you’ll need two voltage supplies):

  • asic-nmos-1.sym
  • voltage-3.sym
  • ground.sym

After you have added the components, you can move them around using the mouse, if you want. You can also rotate (Keyboard shortcut: er) or mirror (ei) components.

Use the menu entry Add → Nets or n to change to net mode to connect the components. Click left to draw a connection and right to stop. s takes you back to select mode.

Component attributes

To use this circuit for simulation, you’ll need to change and add some attributes on the components (except the ground connector, which is quite simple ;-)). In selection mode, double click a component or press ee while a component is selected to bring up the attributes dialog for this component.

Adding a value attribute in the gschem attribute editor

First of all, each component needs a unique identifier, called refdes. The first letter in the identifier depends on the type of component, with V for voltage supplies and and M for MOSFETs. After adding a component, its identifier contains a question mark after the letter. Replace the question marks with a numbers so that each refdes is unique.

The components also need a value. For the voltage supplies, this is simply the desired output voltage, so you can set value=3 on V2 if you want 3 Volt between V2‘s + and - connectors. You can choose for each attribute if name or value or both are visible in the schematic.

For the NMOS transistor, value specifies the transistor’s model. Set the NMOS’ value to test, we’ll load an example model description during the simulation. If you want to simulate a real transistor later, use the part name and load the appropriate model description.

Now your circuit should look similar to the first picture, save it to example.sch. Before Gnucap can simulate the layout, it needs to be compiled into a SPICE netlist using the gEDA component gnetlist. The command looks like this:

$ gnetlist -g spice -o example.sch

Simulation in Gnucap

Gnucap is simply started by running gnucap in the shell of your choice. Gnucap has its own command line, and while I’ll briefly explain what the commands do, I recommend looking at the Gnucap manual (PDF) for details and more commands. The first thing to do is loading the netlist:

gnucap> get 
* Spice netlister for gnetlist

Next, you have to load a transistor specification for the NMOS. I have to use the specification we got from the TA for exercises, so I had to figure out how to load it. If you don’t need that and want to use a generic NMOS specification included in Gnucap instead, just run


and skip the next section. This creates a MODEL with the name TEST of type NMOS. Just keep in mind that the generic NMOS has other characteristics that the example one, so the results will be slightly different.

Loading a transistor model file

I’m not sure if I’d be allowed to publish the NMOS model specification we use in the lecture, so for this tutorial I just took one from the Gnucap example code (nmosgen.c). It looks like the previous MODEL command, but with details for the NMOS’ properties:

.MODEL TEST NMOS (level=2 KP=28U VTO=0.7 LAMBDA=0.01 GAMMA=0.9 PHI=0.5)

Put this into a file called models/test.mod using your favorite editor, then load it into the running Gnucap session with the following command:

gnucap> include models/test.mod

You can display the currently loaded netlist with the list command.

gnucap> list
V2 ( 1 0 )  DC  3.
V1 ( 2 0 )  DC  2.
M1 ( 1 2 0 unconnected_pin-1 )  test  l=3u w=1u
.model TEST nmos2 ( level=2 kp=28U nfs=NA( 0.) delta=NA( 0.) vto=0.7 gamma=0.9 phi=0.5 lambda=0.01 tox= 100.n uo=NA( 600.) tpg=1 tnom=NA( 27.) fc=NA( 0.5) pb=NA( 0.8) cj=NA( 0.) mj=NA( 0.5) cjsw=NA( 0.) mjsw=NA( 0.33) kf=NA( 0.) af=NA( 0.) is=NA( 10.f) cgso=NA( 0.) cgdo=NA( 0.) cgbo=NA( 0.) ld=NA( 0.))

Running the simulation

Before running the simulation, you need to tell Gnucap which data you want to see. Our example circuit is small, so let’s print pretty much everything:

gnucap> print dc i(M1) v(V1) v(V2)

The print command tells Gnucap what data to print for a certain kind of simulation. The example uses DC, so that’s the type. After the simulation type list the values you want printed, in this case the current through M1 (i(M1)) and the voltages over V1 and V2 (v(V1) and v(V2)).

Use the dc command to run the simulation. The parameters here are, in order: a voltage to vary, its start and end values, and the step size. Note that this command overrides the previously set value for V2.

gnucap> dc V2 0 4 0.5
#           i(M1)      v(V1)      v(V2)
 0.         0.         2.         0.
 0.5        4.5044u    2.         0.5
 1.         5.7161u    2.         1.
 1.5        5.7969u    2.         1.5
 2.         5.8617u    2.         2.
 2.5        5.9183u    2.         2.5
 3.         5.9702u    2.         3.
 3.5        6.0191u    2.         3.5
 4.         6.0659u    2.         4.

To plot the results, you can redirect the output to a file the same way as on a shell. It’s a good idea to use a smaller step size for plotting.

gnucap> dc V2 0 4 0.01 >example.out

Now run

$ gwave example.out

on the shell. Gwave should open two windows, one listing the variables and one with black plot areas. Drag and drop variables to the black areas to plot them. If you put both voltages into the upper and the current into the lower area, the result should look like the picture below.

Gwave with two graphs, showing input voltages (top) and drain-source current (bottom)

Creating the set of characteristic curves

To draw the full set of characteristic curves, we have to vary the gate voltage as well. Gnucap’s sweep command is useful here. It creates a loop: A number of commands are executed with one or more variables changing between runs. Let’s change V1 from 1 to 5 Volt in 5 steps. After running the sweep command, the Gnucap prompt will change to >>>. On this prompt, run the command you want sweeped, in this case the dc command from before, with one small change: When > is used to redirect output, as on the shell the target file will be overwritten with each run. Here, >> is better, because the new data will be appended instead, but you should delete example.out first to avoid mixing new and old results. go ends the list of loop commands and starts the sweep.

gnucap> sweep 5 V1=1,5
>>>dc V2 0 7 0.01 >>example.out 

I couldn’t make Gwave understand this kind of concatenated file without splitting it up, but Gnuplot can understand it with just a minor change: there must be an empty line before each new set of data. Gnucap puts a comment line starting with # at the top of each set of output data, so we can easily use sed to insert a newline before each dataset.

$ sed -e "s/#/\n#/g" example.out >example.out.split

Now start Gnuplot and run the following commands:

gnuplot> set xlabel "Voltage supplied by V2 [V]"
gnuplot> set ylabel "Current through M1 [A]"
gnuplot> plot 'example.out.split' index 0 notitle with lines

The label commands aren’t really necessary, but the diagram looks better with labels. 😉 That’s it!

Set of characteristic curves for an NMOS transistor plotted in Gnuplot

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: