Need help with SPICE, following the textbook

Thread Starter

Sixth

Joined Nov 9, 2023
1
Hello all, I'm currently following the textbox to learn electrical and electronics for my job. I'm on Ch.1 and on the Ohm's Law section.

https://www.allaboutcircuits.com/te...chpt-2/computer-simulation-electric-circuits/

I'm trying to follow along with him with LTSpice for Windows, but I don't know if what he is doing is just plain in compatiable with the newer version? I've got the first bit in:

v 0 1 dc 10
r 0 1 5
.trans 3
.end

And if I'm reading the text right, this is supposed to generate a graph or circuit possibly? Mine doesn't do anything, but I'm not getting any errors. Did I just read the text wrong? Or do I need to find an old version of SPICE?

Thanks all.
 

Papabravo

Joined Feb 24, 2006
21,225
The text file describes a voltage source connected from node 0 (GROUND) to node 1 with a value of +10 Volts
The next line is a resistor, connected between node 0(GROUND and node 1, with a value of 5 Ω. What spice will do is show you the current in the resistor of 2 Amperes.

Normally in LTspice you would create a schematic the would be converted to the netlist, but it tune sout you can enter thos spice commands on the schematic and get the same result. See Below:

Ohm's Law example as a schematic
with the following netlist created from that schematic:
* C:\Users\GenericUser\AppData\Local\LTspice\examples\Temp\OL_Schematic.asc
V 001 0 10 V
R 001 0 5Ω
.tran 3
.backanno
.end
1699570940771.png

Using just the text instead of a schematic. Notice that I had to swap the node numbers to get the right signs. I could also have made the source -10 Volts.

1699571320328.png

I think you will agree that the schematic is easier.
 

WBahn

Joined Mar 31, 2012
30,055
LTSpice is not SPICE -- and I think this might be where your difficulty is coming from.

The text book is talking about a SPICE program where you create a circuit file (as a text file) and then you run the SPICE program, telling it to use that circuit file.

Almost no one does this any more.

LTSpice (and most circuit simulators) are actually front-ends of one kind or another for SPICE. You use a graphical front end to draw a schematic and use a few menus to set various parameters. Then you click a button to simulate things and what is actually happening is that LTSpice is first converting your graphical schematic into a netlist (i.e., the circuit file you would have created with a text editor) and then running SPICE in the background on that circuit file. It is then taking the output that is generated by SPICE and using that as the source of data that it provided back to you, say in the form of a waveform plot.

While you NORMALLY work with a graphical schematic with LTSpice, you CAN work with manual circuit files like you are trying to do.

To do that, you open the file and then click the Simulate icon -- which I'm guessing you've already done.

Now you are probably seeing a completely blank plot window, possibly with the x-axis having values from 0 to 3 (because you said that you wanted to run a transient analysis for 3 seconds).

The reason that you aren't seeing any data in the plot window is that you haven't yet told it to actually plot any data -- just to run the simulation and record the data. So where is this data?

I took your circuit and put it in a file named simple.cir. I then ran the simulation. If I look in the folder where the circuit file is located, I now see three other files:

simple.log
simple.op.raw
simple.raw

Let's look at the log file:

Code:
Circuit: v 0 1 dc 10

WARNING: Less than two connections to node 1.  This node is used by R.
.OP point found by inspection.

Date: Thu Nov 09 16:20:51 2023
Total elapsed time: 0.019 seconds.

tnom = 27
temp = 27
method = modified trap
totiter = 2092
traniter = 2092
tranpoints = 1047
accept = 1047
rejected = 0
matrix size = 1
fillins = 0
solver = Normal
Matrix Compiler1: off  [0.0]/0.0/0.0
Matrix Compiler2:       4 opcodes  0.0/[0.0]/0.0
Two things stand out: First, it's telling use that the circuit is ... well... the first line in the file. That doesn't seem very reasonable. Second, it's telling us that Node 1, used by R, has fewer than two connections. Huh? Node 1 is connected to both R and V. It's like the voltage source doesn't exist.

That's because it doesn't. The first line of a circuit file is the title line. It MUST be there -- though it can be blank. So let me add a line as follows:

Code:
My first circuit file!
v 0 1 dc 10
r 0 1 5
.trans 3
.end
Now when I run it, I get the following in the log file:

Code:
Circuit: My first circuit file!

Direct Newton iteration for .op point succeeded.

Date: Thu Nov 09 16:24:17 2023
Total elapsed time: 0.015 seconds.

tnom = 27
temp = 27
method = modified trap
totiter = 2095
traniter = 2092
tranpoints = 1047
accept = 1047
rejected = 0
matrix size = 2
fillins = 0
solver = Normal
Matrix Compiler1:       2 opcodes  0.0/[0.0]/0.0
Matrix Compiler2: 96 bytes object code size  0.0/0.0/[0.0]
Within LTSpice, I can now put my mouse over the plot window and right click the mouse to bring up the dialog that lets me add traces to the plot. If I pick V(1), it tells me that it is -10 V, and if I pick I(R) it tells me that it is -2 A.
 

WBahn

Joined Mar 31, 2012
30,055
LTSpice is a product that USES SPICE -- it is a wrapper around SPICE and SPICE is just one of the things that it has.

SPICE has no schematic capture feature, or the ability to generate netlists, or a plot display feature, or GUI, or anything else that we interact directly with when we are using LTSpice in the way that we almost always do.

The only time that SPICE comes into play is when we actually run the simulation, at which point LTSpice generates the input files that SPICE expects and invokes the SPICE engine to produce output files. It then takes our commands related to things like plotting waveforms and fetches the necessary data values from the SPICE output files to produce the plots.

It's much the same with many tools that we use. For example, many IDEs for programming languages are NOT compilers in and of themselves. They are front-ends for a separate compiler (for instance, gcc or mingw) that they invoke behind the scenes as needed.
 

eetech00

Joined Jun 8, 2013
3,949
LTSpice is a product that USES SPICE -- it is a wrapper around SPICE and SPICE is just one of the things that it has.
I don't think I'd call it a wrapper, but thats just my opinion.

SPICE can only process a text based representation of the schematic (a spice netlist). LTspice can process either type of schematic, either, a text-based spice netlist, or an LTspice graphical representation of a schematic.


To the TS:
I think the chapter is either poorly written and/or outdated with regards to spice simulation.
 
Top