From b041f8c105b16bd1b5475ab6e9b335d54b99102e Mon Sep 17 00:00:00 2001 From: Paul Falstad Date: Sun, 27 Oct 2024 14:21:07 -0700 Subject: [PATCH] fix schmitt trigger bad behavior with nonlinear circuits (#104) --- src/com/lushprojects/circuitjs1/client/SchmittElm.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/com/lushprojects/circuitjs1/client/SchmittElm.java b/src/com/lushprojects/circuitjs1/client/SchmittElm.java index 9b639516c..ce1edfc54 100644 --- a/src/com/lushprojects/circuitjs1/client/SchmittElm.java +++ b/src/com/lushprojects/circuitjs1/client/SchmittElm.java @@ -31,8 +31,13 @@ public SchmittElm(int xa, int ya, int xb, int yb, int f, } int getDumpType() { return 182; } + + double lastOutputVoltage; + + void startIteration() { + lastOutputVoltage = volts[1]; + } void doStep() { - double v0 = volts[1]; double out; if(state) {//Output is high @@ -60,7 +65,7 @@ void doStep() { } double maxStep = slewRate * sim.timeStep * 1e9; - out = Math.max(Math.min(v0+maxStep, out), v0-maxStep); + out = Math.max(Math.min(lastOutputVoltage+maxStep, out), lastOutputVoltage-maxStep); sim.updateVoltageSource(0, nodes[1], voltSource, out); }