# Nested simulation loop in LTSpice

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.

#### sandrohv

Hi guys, does any one know how LTSpice decides on the order of 2 step commands?

For example:
.step param A list 1 2
.step param B list 3 4

When you run, which is the outer loop and which one is the inner loop?

I.e. do we get:

Sim 1: A=1 B=3
Sim 2: A=1 B=4
Sim 3: A=2 B=3
Sim 4: A=2 B=4

- OR -

Sim 1: A=1 B=3
Sim 2: A=2 B=3
Sim 3: A=1 B=4
Sim 4: A=2 B=4

Is there a way to force an order?

Thanks!
- Sandro

#### sgrossklass

Good question. This may be one for the LTspice group (now at groups.io).

My WAG would be: Whatever comes first in the file is run first.

#### sandrohv

Hi Sgrossklass, do you have a link to the LTSpice group forum so I can post the question?
Thanks!

#### sandrohv

Found the answer in the group...

"You can make nested .step loops up to 3 levels.
It's important to have all .step commands in one text box
to get control about its order of execution."

So as long it is in the same text box, it will follow the order you write it in. Therefore, for:
.step param A list 1 2
.step param B list 3 4

It will be:
Sim 1: A=1 B=3
Sim 2: A=2 B=3
Sim 3: A=1 B=4
Sim 4: A=2 B=4

A bit counter intuitive if you ask me, since for loops work the other way, but it is what it is.
- Sandro

Last edited:

#### Ludus Tonalis

Yes, but why?

Is there a way to force an order?

Found the answer in the group...

Sandro, this is interesting and new to me. But I am curious as to why this might be important. For example, the sim where A=2, B=4 will give the same result and plots regardless of whether it is sim 1 or sim 4. What is the situation where the order of execution needs to be controlled?

#### sandrohv

Hi Ludus,
Loop gain simulations (Tian and Middlebrook) require 2 consecutive simulations.
Therefore, if you want to run Loop Gain under different conditions, you need to arrange the simulation order such that the 2 loop gain sims run before the condition changes.
Using my example, you want A to be the loop gain sims and B be changing condition (e.g. changing a cap value).

Best, Sandro

#### Ludus Tonalis

Hi Ludus,
Loop gain simulations (Tian and Middlebrook) require 2 consecutive simulations.
Therefore, if you want to run Loop Gain under different conditions, you need to arrange the simulation order such that the 2 loop gain sims run before the condition changes.

Excellent! I think in the dim and distant past I had wondered if there was a way to automate loop gain sims with different conditions, and had come to the conclusion that I simply had to do them separately. So thanks for showing me a way to circumvent this issue. I can now get more than one loop gain plot on the same chart.

#### sandrohv

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.