1

I have a circuit with several ICs and components. But the circuit will behave differently depending on the inputs or the switches set.

Each time to simulate a combination I have to delete/modify several wires or change the power supply voltage values ect.

Is there a syntax or a way to set some conditions in a short way.

Below is an imaginary example to describe what Im looking for:

For example before running the simulation: just by typing 1 instead of 2 in a syntax, the circuit will change 10 switches and set two power supply voltages to a value which were defined by the user before.

user16307
  • 11,802
  • 51
  • 173
  • 312
  • The custom parameter feature should help you implement this: http://ltwiki.org/index.php5?title=PARAM_User_defined_parameters. It allows you to build some fairly complicated expressions. – Synchrondyne Mar 08 '17 at 18:18
  • have you done that before? can you provide an example with a simple circuit? for example: you set a parameter and 2 switches will be off and another parameter will make Vcc 5V – user16307 Mar 08 '17 at 18:21
  • I'm at work right now so I can't work out a full example (I'll leave that to somebody else who wants the points), but this should get a good way there: http://electronics.stackexchange.com/questions/247396/ltspice-param-if-statement – Synchrondyne Mar 08 '17 at 18:23

3 Answers3

1

Based on your question I think the first part of laptop2d's answer is what you need. Still, it can be improved a bit, at the cost of slightly more complications. It involves two rules.

a) in LTspice, grounding every pin of an element disables it (except current sources and subcircuits), and this is not limited to 2 pins elements only; transitors, switches, etc, are also disabled.

b) nodes' names are treated as labels, but can also be evaluated. For example, a net name x1 will be treated as a label, but can't be evaluated, while 0 and 00 will be treated as two, distinct nodes, but they both evaluate to zero (GND).

Combining the two rules above, you can label a node in such a way that it evaluates to anything but zero, if you need the element between the nodes active, or to zero if you want it disabled. Example:

I1 23 0 1
R1 23 0 1
R2 {x} 0 1
.step param x list 0 23

This netlist will be run twice, for x=0 and x=23, with R2 being disabled at first, and then enabled. Plotting V(23) will show 1V, then 0.5V. The same result can also be achieved using

R2 {23*x} 0 1
.step param list 0 1

or

R2 {x-23} 0 1
.step param x list 23 0

or any other way that results in the same outcome, because whatever expression is within the accolades will be evaluated. Be sure to make the result of the evaluation 0, not -0, or it will count as a different label.

But LTspice doesn't allow naming the nets with accolades, at least not from within the GUI. Pressing F4 and explicitly writing {23} will not be allowed due to illegal characters. This means that R2 needs to be added to the schematic via a SPICE directive (S). This is where it gets a bit awkward, because if you have a fair number of elements, you'll have to do a bit of typing, not to mention choose proper expressions for every node, while making the schematic less readable.

These make more sense when working with subcircuits, where you want to enable/disable elements such that the matrix solver only counts the ones you need for the current simulation, but it can be done, just as well, in a normal schematic, such as yours.

a concerned citizen
  • 21,167
  • 1
  • 20
  • 40
0

There a few ways of doing this but none of them are going to be easy and are 'klugey'. You may not like them spice isn't really 'geared' for this type of simulation, but here we go.

One way is to use a stepped parameter to change resistors values:

You add this line to the file (by the .op button on the toolbar)

.step param Res list 0.1 1e9

and then in the resistor you want to change you put {Res} instead of the normal resistor value. This line runs two simulations, one with 0.1 (pretty much shorted) and one with high resistance (1e9Ω which is close to air and pretty much open). You can use this like a switch.

If you want to change values simultaneously then you can also use a parameter with an if statement, this simulation runs two resistances (determined by the if statement parameters). The two runs are 1Ω because the .step file sets the Res param to 1 and 5 which is not greater than 5 and so it uses 1 as the value of the resistor. The next simulation run is 10Ω because the next simulation is 10 and uses the second value in the if statement. Like the example before you could use a low and high resistance and use this to switch resistors on and off.

(As a side note you can use time as a variable in the if statement to change the resistance value also)

enter image description here

Another way is using PWL voltage sources to set the resistance in a transient simulation. You can set the resistance to a voltage R=V(Res1) to control the resistance (I also prefer to keep the resistance in range so I use R=exp(V(Res1)) to keep the Res1 signal in the same numerical range for better numerical stability)

The third way, which you should consider is generate the netlist file with a scripting language (like matlab or python) to switch components in and out and run the simulation from the command line and gather the data you need. Probably more work than you want but its a possibility worth mentioning

Voltage Spike
  • 75,799
  • 36
  • 80
  • 208
-1

It sounds like the table() functionality built in to the LTSpice arithmetic engine should work for you. This would allow you to set various circuit parameters based on a single index parameter. You define a variable:

.param configuration_index = 1

...and then you set the variable parameters in your circuit using an equation with a table lookup based on this configuration index. For example, if your supply voltage was supposed to be 5 for setups 1-5 and 10 for setups 6-10 you would set the value for your supply to be:

{table(configuration_index,0,5,1,5,2,5,3,5,4,5,6,10,7,10,8,10,9,10,10,10)}

You can change connections by using resistors with values that are defined by a lookup table to be e.g. 1mohm vs 1Gohm depending on whether you want the connection open or closed. Alternatively, you could use SW elements driven by voltage sources that are a function configuration index.

Although this approach can be unwieldy for elaborate setups, it is actually quite flexible.

Note that I am assuming basic knowledge of user defined parameters in LTSpice. Read the provided documentation on .param if you need a basic description of how parameters work.

user49628
  • 1,218
  • 6
  • 7