0

Is there a way to vary resistor R4 in the picture based on if the switch is on or off? For example, if S1 is off, I want R4 to be 10 Ω, and if it's on, I want R4 to be 100 Ω, and if S2 is on as well, another different R4 value.

Is there a way to do this if/else operation in LTspice?

enter image description here

ocrdu
  • 8,705
  • 21
  • 30
  • 42
  • If you reverse the switch polarity it becomes easier: put 10 and 90 in series and short the 90 ohms. – Oldfart Jun 21 '19 at 19:58
  • @Oldfart Thanks, but if I want to change the values from time to time, that wouldn't work right? – Nkechi Esiaba Jun 21 '19 at 20:10
  • 1
    Yes, it would. Use the switch to short the 90 ohms resistor and you have 10 ohm. – Oldfart Jun 21 '19 at 20:20
  • @Oldfart but it would be quite complicated/messy if I have 20 resistors with multiple values and multiple switches. Thanks. – Nkechi Esiaba Jun 21 '19 at 20:43
  • Are you planning to open/close the switches in the middle of a transient simulation? What are you really trying to accomplish? – Elliot Alderson Jun 21 '19 at 20:54
  • Just to be sure: you need R4 with 4 different values, according to the combination of SW1 and SW2? – devnull Jun 21 '19 at 20:56
  • @ElliotAlderson I would like to run the simulation with different switch modes(all on, 1 on, 2 on...) but everytime a switch is turned on, the previous resistor values will change. – Nkechi Esiaba Jun 21 '19 at 20:58
  • @vangelo 3 different values, since SW2 would be ineffective when SW1 is off. – Nkechi Esiaba Jun 21 '19 at 20:58
  • 1
    You still need to clarify. Are you running separate simulations for the different switch positions or are you changing the switches **in the middle** of a given transient simulation? Do you really just want to run the same simulation with different resistor values? – Elliot Alderson Jun 21 '19 at 21:02
  • @ElliotAlderson I will be running separate simulations for different switch positions using the same circuit. – Nkechi Esiaba Jun 21 '19 at 21:05
  • Since you are calculating operating point, what about: https://electronics.stackexchange.com/questions/126659/how-to-use-step-param-with-more-than-two-parameters-in-ltspiceiv and maybe even replace your SWs by simple resistors. – devnull Jun 21 '19 at 21:14
  • @vangelo Thanks! This works with what I have. Appreciate it! – Nkechi Esiaba Jun 21 '19 at 21:30

1 Answers1

1

You are running separate simulations with different resistor values, so adding switches is a needless complication. Resistor values can be parameterized and you can simulate with different specific values, simulate while sweeping over a range of values, or use Monte Carlo simulations to simulate many random resistor values simultaneously.

If you use switches you will have to change the voltage sources that control the switches between the simulations...just change the resistor values themselves.

Elliot Alderson
  • 31,192
  • 5
  • 29
  • 67