4

I'm reading an EE book that references SPICE so to follow along on my linux machine I installed ngspice. I can't output current for any circuits! I've tried passing the file with -r option and multiple circuits. Can never get a current output!

I googled and tried other posts this but nothing seems to work. I'm starting to wonder if this is an install / configuration issue?

Starting with a simple series circuit with the intent to print voltage at each resistor and current at my source I loaded the following netlist:

series circuit
v1 1 0
r1 1 2 3k
r2 2 3 10k
r3 3 0 5k
.dc v1 9 9 1
.print dc v(1,2) v(2,3) v(3,0) i(v1)
.end

and received errors: Warning: v1: has no value, DC 0 assumed Warning: can't parse '0': ignored

My voltage outputs are correct per hand calcs so I know ngspice is calculating the right current.

reducing .print line to just get current::

.print i(v1)

yields error:

Error: .print: no i(v1) analysis found.

I've also tried defining my source different as:

v1 1 0 dc 9

same errors.

I've tried many different circuits and can never get ngspice to output current for my sources (I have created 0 voltage sources near resistances on parallel circuits as well). The voltage outputs are all correct

I also tried a netlist with no .print line (I thought I've seen others with default output):

series circuit
v1 1 0 dc 9
r1 1 2 3k
r2 2 3 10k
r3 3 0 5k
.end

with this error:

Note: No ".plot", ".print", or ".fourier" lines; no simulations run

isn't there a default output without needing a .print line?

More importantly is there a configuration file not setup properly? thoughts?

any direction is greatly appreciate... Thank you

twinturbotom
  • 143
  • 1
  • 5

2 Answers2

2

Your first circuit is correct, you don't have errors, just warnings. You can ignore the warning about v1 or define it with a value like v1 1 0 9. I've just tested your initial circuit with ngspice (linux) and it did give the correct value for the current (-5.00000e-04) through the source v1.

.print i(v1)

yields error:

Error: .print: no i(v1) analysis found.

You forgot the analysis type parameter before the output variable: .print dc i(v1).

Note: As mentioned on this answer How to plot current in ngspice? with ngspice you only can get currents through independent voltage sources. If you have a more complex circuit you would need to add a zero volt source (in series) with the component to get its current.

Gilberto J
  • 38
  • 5
1

there are some problems with your .cir file.

.dc v1 9 9 1

you forgot a minus sign.

.dc v1 -9 9 1

this will cause a warning

v1 1 0

be more verbose and write

v1 1 0 DC=0V

the node 0 is something special, thus

.print dc v(3,0)

should be

.print dc v(3)

and ngspice cant process i(node) expressions. replace this with

.print dc v1#branch

then be sure to have a copy of the ngspice manual.pdf, its precious.

and perhaps learn the .control/.endc language, for example try ngspice thisfile.cir with

series circuit

v1 1 0 DC=0
r1 1 2 3k
r2 2 3 10k
r3 3 0 5k

.control
dc v1 -9 9 1
* this will show you which vectors are available
display
* this will plot some of them
plot v(1,2) v(2,3) v(3)
plot v1#branch
plot v(3)^2
.endc

.end
robert
  • 26
  • 1