Skip to content

Commit 20ce4d7

Browse files
esaruohoclaude
andcommitted
fix comparator output spike by forcing re-convergence on switch state change (#90)
When the analog switch changes state during Newton-Raphson subiterations, force sim.converged = false to ensure additional iterations settle the circuit. This prevents brief voltage spikes when the switch transitions between open and closed states, particularly in the ComparatorElm where the OpAmp output and AnalogSwitch react with a one-subiteration lag. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7755622 commit 20ce4d7

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

src/com/lushprojects/circuitjs1/client/AnalogSwitchElm.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,12 @@ void stamp() {
148148
}
149149
}
150150
void doStep() {
151+
boolean wasOpen = open;
151152
open = (volts[2] < threshold);
152153
if (hasFlag(FLAG_INVERT))
153154
open = !open;
155+
if (open != wasOpen)
156+
sim.converged = false;
154157

155158
// if pulldown flag is set, resistance is r_on. Otherwise, no connection.
156159
// if pulldown flag is unset, resistance is r_on for on, r_off for off.

0 commit comments

Comments
 (0)