Skip to content

Commit

Permalink
fix schmitt trigger bad behavior with nonlinear circuits (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfalstad committed Oct 27, 2024
1 parent 83650c7 commit b041f8c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/com/lushprojects/circuitjs1/client/SchmittElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit b041f8c

Please sign in to comment.