0
\$\begingroup\$

In the Ultimate Electronics interactive online book, there is a section called Voltage-Controlled Switch. In this section there are are 7 examples of how to use a voltage-controlled switch.

The last example (#7) states:

  1. Finally, we can use a voltage within the circuit itself as the trigger. This example is a bit more complicated, but it uses the fact that the voltage-controlled switch model has hysteresis. Hysteresis means that after the switch changes from one state to the other, there’s some memory so that a larger wiggle is required to get it to switch back to the first state. This is configured within the V_H parameter of the switch SW2. Double-click SW2, try changing the hysteresis voltage V_H, and re-run the simulation:

with a link to these interactive schematics:

enter image description here

Within this schematic there is a strange node label “+5V” (a “Named node” by the CircuitLab terminology) which I've circled in red. While hovering the mouse over this node, CircuitLab shows that this node's DC voltage is indeed +5 V (shown below), even though it's never connected to a voltage source elsewhere in the schematic.

enter image description here

When converting these schematics to LTspice, I decided to replace this "named node" with an explicit voltage source to obtain the same result (for the output voltage value in the time-domain simulation), but without success. I got either a constant value, or the simulation simply didn't work (no window for the waveform viewer; dimmed icon for the “run simulation” symbol). I was forced to halt the simulation with Ctrl + H.

I also tried a different connection of this voltage source (V2), for example this one:

enter image description here

Its netlist (without the first line):

V1 N001 0 12V
C1 out 0 22mF
R1 out 0 6Ω
R2 out N003 6Ω
SW1 N001 N003 N002 out S1
V2 N002 out 5V
.tran 5
.model S1 SW(Vh=-.75 Ron=.1 Vt=2.5)
* By https://ultimateelectronicsbook.com/switches/#voltage-controlled-switch\n\n(option 7)
.backanno
.end

How can I make this work in LTspice (I use version 17.1.14)?


UPDATE:

My question is expressed in its title. I am not interested in other solutions. I want to substitute that strange CircuitLab label (which implies a DC voltage) with something accessible within LTspice.

Why? For any instance in the future where I encounter this same label type in some totally different circuit in CircuitLab.

Here's another thing I tried (the result of its simulation was a constant voltage, about 2.15 V for the “out” node):

enter image description here


UPDATE 2:

The circuit, which (almost) exactly matches the circuit in CircuitLab, is this one:

enter image description here

The result: no window for the waveform viewer; just a dimmed icon for the “run simulation” symbol. I was forced to halt the simulation with Ctrl + H.

Why almost exactly?

Because:

  1. LTspice doesn't allow zero resistance for a closed switch, so I used 0.001 Ω (1 milliohm) instead.

  2. CircuitLab has only 3 adjustable parameters for a voltage-controlled switch (R_ON, V_T, V_H), and LTspice has an additional 4 (Roff, Lser, Vser, Ilimit). Namely, Lser (series inductance) and Vser (series voltage), both with default values of 0.0, may play some role in the result.

\$\endgroup\$
7
  • \$\begingroup\$ What difference do you see between the sims? Try to use this directive ---> .tran 0 5 0 10u uic. \$\endgroup\$
    – G36
    Commented Oct 14 at 14:45
  • \$\begingroup\$ @G36, you hit the nail on the head, thanks! The uic parameter was important, the .tran 5 uic was sufficient. In spite of the waveform is not exactly the same as in CircuitLab (it begins with 0 V instead of 6 V - probably it's related to the initial state of the switch), the shapes are the same. — If you transfer your comment into an answer and explain the importance of the uic parameter, I'll accept it. \$\endgroup\$
    – MarianD
    Commented Oct 14 at 17:05
  • \$\begingroup\$ I think that is strange that in CircuitLab waveform begins at 6V. It should begins at 0V (the capacitor is initially discharge). Not an open circuit. \$\endgroup\$
    – G36
    Commented Oct 14 at 17:16
  • \$\begingroup\$ @G36, so the LTspice is correct in this particular simulation, and CircuitLab not. \$\endgroup\$
    – MarianD
    Commented Oct 14 at 17:57
  • \$\begingroup\$ @G36 Looks like CircuitLab puts this switch into the ON position when calculating the DC operating point for this circuit. I don't know how it knows to do this since with the feedback it's not determinable. \$\endgroup\$
    – Ste Kulov
    Commented Oct 14 at 19:25

3 Answers 3

2
\$\begingroup\$

Every time CircuitLab encounters a node with a name that implies some fixed potential, like "+5V" or "−12", beheind the scenes it inserts a voltage source to produce that potential. The following are equivalents in CircuitLab:

schematic

simulate this circuit – Schematic created using CircuitLab

The name "P5" is arbitrary, Since CircuitLab interprets "+5V" as being attached to a hidden 5V source, you can't use such names for regular nodes. This can be convenient, since it permits schematics with implied voltage sources, but where none are actually shown, which might otherwise clutter up the schematic:

schematic

simulate this circuit

Using explicit voltage sources, the equivalent would be:

schematic

simulate this circuit

Notice that all the source are with respect to ground. In other words, one side is always connected to ground, otherwise terms like "+5V" and "−100V" would be meaningless.

LTspice doesn't interpret node names like this, so while you can actually use the name "+5V", it will not include any implied voltage source. You can however define those sources explicitly like I did above in one part of the schematic, and make implied connections to them elsewhere:

enter image description here

Your own LTspice schematic can be adapted to use the same technique:

enter image description here

A transient analysis usually begins with an implied .op operating point analysis, to establish starting conditions. A .op is not about stepping through time, it's about state after a long time, long enough for all capacitors to have charged to a steady voltage, and all inductors have settled to some steady current. The .op "thinking" in your case would go like this:

  1. S1 is open. After a long time C1 will have discharged to 0V.
  2. S1 will therefore have 0V input, causing it to close.
  3. S1 is therefore initially closed, in fact. Try again.
  4. S1 is closed. C1 will eventually charge to 6V.
  5. S1 will therefore have 6V input, causing it to open.
  6. S1 is therefore initially open, in fact. Try again from step 1

The loop never ends, and the .tran proper can never even get started.

To solve this problem, tell the .tran analysis to skip the implied .op, using the uic flag. In the above LTspice schematic, notice how the .tran directive has the uic flag, to skip calculation of initial conditions.

You will also find a checkbox in the simulation dialogue box to add the uic flag for you:

enter image description here

Now you should see the correct simulation results:

enter image description here

If you really require an operating point analysis, perhaps for simulation of other parts of the circuit, then an alternative approach would be to have the 12V source start at zero, and rise to 12V after a microsecond or so, so oscillation does not occur initially, and the .tran begins in a state where a steady state can be established. That can be done using a piecewise voltage source PWL(0 0 1u 0 2u 12):

enter image description here

There are probably a dozen ways you can prevent .op from failing like that, and they would all involve avoiding the situation where there exists no steady-state condition that doesn't contradict itself.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ It sounds like the questioner already figured this part out. There is a conflating of two problems here, due to the specific circuit being simulated in the question. The first is what you’re addressing in this answer. The second is that CircuitLab decides the switch is ON for the operating point solution. LTspice however can’t find a stable state for the operating point due to the feedback and stalls. This 2nd discrepancy is what’s causing the confusion when translating the circuit from CircuitLab -> LTspice. I think you need to address this too for your answer to be complete. \$\endgroup\$
    – Ste Kulov
    Commented Oct 15 at 5:45
  • \$\begingroup\$ Check the question’s comments for more info. \$\endgroup\$
    – Ste Kulov
    Commented Oct 15 at 5:46
  • \$\begingroup\$ Thank you @SteKulov, you are absolutely correct. \$\endgroup\$ Commented Oct 15 at 6:44
  • \$\begingroup\$ @Simon Fitch, thank you for very very nice and comprehensible answer, beside the answer to my question you explained me other useful things. \$\endgroup\$
    – MarianD
    Commented Oct 15 at 8:10
  • \$\begingroup\$ Beautiful answer. Thank you! \$\endgroup\$
    – Ste Kulov
    Commented Oct 15 at 11:05
3
\$\begingroup\$

You did not wire up the voltage source correctly. The negative terminal of the voltage source should be connected to ground, not to OUT.

Here is the circuit with the +5V node replaced by a voltage source V2, and closer to the layout of your circuits.

schematic

simulate this circuit – Schematic created using CircuitLab

With the parameters for SW1 set at V_T = 2.5 and V_H = 1.5, the output looks like this:

enter image description here

In the edited version of the question, there is a circuit similar to this, but with the parameters for the switch set at Vt = 2.5 and Vh = -0.75. Try changing Vh to 1.5 as in the original circuit.

\$\endgroup\$
9
  • \$\begingroup\$ "You did not wire up the voltage source correctly. " - I know about it, it was only one of my desperate trials. Your advice I already tried, too - no success. \$\endgroup\$
    – MarianD
    Commented Oct 13 at 17:01
  • \$\begingroup\$ @MarianD Then why didn't you post a schematic that matches the CircuitLab version? \$\endgroup\$ Commented Oct 13 at 17:40
  • \$\begingroup\$ "Then why didn't you post a schematic that matches the CircuitLab version?" — Because I'm not able to provide it, after all, it is the core of my question. If I know how to do it, I didn't write this question. \$\endgroup\$
    – MarianD
    Commented Oct 13 at 17:59
  • \$\begingroup\$ @MarianD. You said you tried it and it didn't work. Please post the schematic that you tried where the negative terminal of the voltage source is connected to ground instead of OUT. \$\endgroup\$ Commented Oct 13 at 18:57
  • \$\begingroup\$ Very nice from you for your effort to help me, I already thought that nobody knows the answer. I appended the schematic you demanded into my answer. \$\endgroup\$
    – MarianD
    Commented Oct 13 at 19:35
0
\$\begingroup\$

If you want the switch to actually "switch", then the voltage that controls it should likely be a pulse voltage source that changes voltage at some point...rather than a solid DC voltage that never changes.

In the example below, the voltage source controlling the switch starts off at zero, which means the switch is open (it is below the switch's threshold voltage of 0.5V).

Initially, the switch is open, so the TRAN does a solution as if the switch resistance is 10MEGohm...so C1 is mostly discharged. The switch is open because V1 is initially 0V.

But very shortly after zero seconds (as the transient run begins), switch S1 closes, and becomes 0.001 ohms...because V1's voltage is above threshold

Then at two seconds, voltage of source V1 falls below 1V, which is below threshold, so the switch resistance changes from .001 ohms to 10MEG in a short span of time. LTspice Xvii

Note that the switch control voltage source (here V1) is grounded. Control is isolated from the switch function. No current flows from V1. Grounding isn't necessary, but having one of V1's terminals at a solidly stable point (ground) eases my mind.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks for your answer, but is is only the option 3) from the 7 options in that book, and with it, I had no problem. :-( \$\endgroup\$
    – MarianD
    Commented Oct 13 at 17:05
  • \$\begingroup\$ Without knowing what the book's seven options actually outline, it is hard to help. I have found LTspice;s HELP menu item (function key F1) useful. Searching for SW brings up clear explanations of how voltage-controlled-switches work for many different scenarios \$\endgroup\$
    – glen_geek
    Commented Oct 13 at 17:27
  • 1
    \$\begingroup\$ 1. "Without knowing what the book's seven options actually outline" — the link is in my question. - 2. " I have found LTspice;s HELP menu item (function key F1) useful. " — me too, long time ago. :-) - 3. "Searching for SW brings up clear explanations of how voltage-controlled-switches work for many different scenarios" - I read this part many times, long time ago your advice, too. -- But in spite of no usefulness of your tips for me, they are all good advice, so thanks for them. \$\endgroup\$
    – MarianD
    Commented Oct 13 at 18:02

Your Answer

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

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