3

I am doing automation of LTSpice using PyLTSpice library in Python.

I need to know the types of the components in the netlist or in the raw file.

  • How can I know programmatically that R1 corresponds to a resistor, and that C1 is a capacitor?

  • And how does the LTSpice solver "knows"?

The netlist is built as follow (simple example):

* C:path_to_folder\example\example.asc
R1 voltage N001 1e3
V1 N001 0 PULSE(0 5 0.1 0.1 0.1 0.1 0.5 1)
C1 voltage 0 10e-6
.tran 1
.backanno
.end

and the raw file looks like this:

Title: * C:path_to_folder\example\example.asc
Date: Mon Jun 05 10:34:20 2023
Plotname: Transient Analysis
Flags: real forward
No. Variables: 6
No. Points:           69
Offset:   0.0000000000000000e+000
Command: Linear Technology Corporation LTspice XVII
Variables:
    0   time    time
    1   V(voltage)  voltage
    2   V(n001) voltage
    3   I(C1)   device_current
    4   I(R1)   device_current
    5   I(V1)   device_current
Binary:
              馚香香㾹          飸荌뵹뾹떲㣁㝵㳠໳㘷໳똷໳똷顖泿㾹㦾 ...
Rémi Baudoux
  • 292
  • 1
  • 11

1 Answers1

6

It knows that R1 is a resistor because it starts with an R.
It knows that C1 is a capacitor because it starts with a C.

This is integral to how SPICE works; what type of component something is is fully decided by what the first letter of the component name is, and that in turn determines how the subsequent parameters are interpreted. R for resistor, C for capacitor, D for diode, X for subcircuit, and so on.

You can find a complete listing in the manual. (§LTspice®>Circuit Elements. See also §LTspice®>Introduction>General Structure and Conventions and generally everything under §LTspice®.)

Hearth
  • 27,177
  • 3
  • 51
  • 115
  • You mean that if I add a resistor in the schematics and I name it Cx, it will behave as a capacitor? – Rémi Baudoux Jun 08 '23 at 14:53
  • 2
    @RémiBaudoux Yes, but I would argue that you're adding a capacitor if you do that. The netlist has no concept of something being a resistor other than "the first character of the line is R", so if you change the first character to C, it won't be a resistor anymore. – Hearth Jun 08 '23 at 14:54
  • ah, I tested, if I add a resistor, name it R1, I see R1 in the netlist, if I name it Cx in the schematics, it remains a resistor, and the netlist is compiled with the name R§Cx – Rémi Baudoux Jun 08 '23 at 14:58
  • 2
    @RémiBaudoux Yes, the LTspice schematic capture program does that to allow you to name things whatever you want, but as you asked about the *solver*, I answered based on that. You can just skip the schematic capture entirely and simply write a netlist manually if you want, that's allowed. – Hearth Jun 08 '23 at 15:00
  • 1
    yes, that was the core of my question indeed, thanks for the answer, just that I did not expect the compiler to rename things in the background. Thank you very much! – Rémi Baudoux Jun 08 '23 at 15:20
  • 3
    @RémiBaudoux You can override that by ctrl-right-clicking on the element and changing the "prefix" field. I do that a lot to use the built-in MOSFET symbols with subcircuit models (which need the X prefix), for instance. – Hearth Jun 08 '23 at 15:27