Skip to content

Commit 1b0313c

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 6b826de commit 1b0313c

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
@@ -150,9 +150,12 @@ void stamp() {
150150
}
151151
}
152152
void doStep() {
153+
boolean wasOpen = open;
153154
open = (volts[2] < threshold);
154155
if (hasFlag(FLAG_INVERT))
155156
open = !open;
157+
if (open != wasOpen)
158+
sim.converged = false;
156159

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

0 commit comments

Comments
 (0)