3
\$\begingroup\$

Problem:

I'm trying to create a .step list of values based on another parameter but none of the syntax I've tried seems to work.

Example:

In the voltage divider below, I'd like to step the values of R2 in multiples (1x, 1.5x, 2x) of R1. I can do this manually for a given R1 but I'd like to be able to vary R1 and still have the .step values of R2 calculated by LTspice.

Both of the forms I tried yield the same error message:

Syntax error in .step command (2nd dimension)

enter image description here

Related:

LTSpice - Printing resultant parameters based on expressions looks similar, but using single quotes doesn't work either.

Question:

Is there a way to do this? If so, what's the correct syntax?

\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

Your general usage of curly braces is incorrect as it should be: .step param R2 list {R1} {R1*1.5} {R1*2}. But it doesn't matter since you cannot evaluate expressions within a .step command, so you'll always get those syntax errors. You either need to make multiple copies of your circuit, or create a behavioral resistor which can evaluate the resistance based on other information on your circuit.

Here is one such way to do it. Independent voltage source V1 is stepped through 1, 1.5, and 2 and the behavioral resistor is evaluated as R1 multiplied by the value of the node at the top of the voltage source: R=R1*V(step)

enter image description here


You can also step the independent voltage source directly without using a param as follows. Just like a .dc sweep, you need to give the voltage source a default value (I simply picked zero).

enter image description here

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Please vote for the other answer. This one is bad. LOLE. \$\endgroup\$
    – Ste Kulov
    Mar 2 at 22:08
2
\$\begingroup\$

Simple method:

It is possible to achieve the results posited by Ste Kulov even without using an independent voltage source. All that is needed is a single parameter, which can be defined in the .step directive and referenced directly.

As per Ste Kulov's comment below:

Since you don't need the voltage source then you don't even need the behavioral resistor. It's always better to use a regular resistor whenever possible. So I would replace the R=R1*multiplier with {R1*multiplier} so a regular resistor is used.

Putting it all together we get:

Stepping Component Value

Note: the .param multiplier=0 is commented out in this case. If you have a programmer's mindset you might want to have it in there as a directive (i.e. uncommented) just to be pedantic... but it's not required, .step will override the initialisation value anyway.

Ste Kulov's answer was as an essential stepping stone in figuring this out. It just seemed too convoluted to define a voltage source with the sole purpose of acting as an input parameter. So I tried to eliminate this additional step and got lucky. Thanks a bunch, Ste Kulov!

\$\endgroup\$
5
  • \$\begingroup\$ Duh. Of course! Good job. I can't believe my brain overlooked this and over-complicated the solution. My bad. Since you don't need the voltage source then you don't even need the behavioral resistor. It's always better to use a regular resistor whenever possible. So I would replace the R=R1*multiplier with {R1*multiplier} so a regular resistor is used. You should definitely accept this answer once the timeout period expires. \$\endgroup\$
    – Ste Kulov
    Mar 2 at 22:03
  • 1
    \$\begingroup\$ I've just edited in your further excellent suggestions. Thanks for helping me piece this together! \$\endgroup\$
    – pfabri
    Mar 2 at 22:21
  • \$\begingroup\$ No problem! Glad I was able to help. \$\endgroup\$
    – Ste Kulov
    Mar 3 at 2:00
  • \$\begingroup\$ Oh ya. Just noticed the new photo still shows the R=. You have to get rid of that so the behavioral resistor is not used. It should look like this: i.stack.imgur.com/YEKy2.png \$\endgroup\$
    – Ste Kulov
    Mar 3 at 5:15
  • 1
    \$\begingroup\$ @SteKulov Ach, well spotted! ... and now corrected too. :) \$\endgroup\$
    – pfabri
    Mar 3 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.