Skip to content

Fix unrealistic stability for positive-feedback opamp buffer#295

Open
esaruoho wants to merge 1 commit intopfalstad:devfrom
esaruoho:fix-opamp-metastable
Open

Fix unrealistic stability for positive-feedback opamp buffer#295
esaruoho wants to merge 1 commit intopfalstad:devfrom
esaruoho:fix-opamp-metastable

Conversation

@esaruoho
Copy link
Copy Markdown

@esaruoho esaruoho commented Mar 3, 2026

Summary

  • Adds a tiny initial offset (1e-6 V) to the opamp lastvd state in a new reset() override, breaking the metastable equilibrium that causes positive-feedback configurations to unrealistically track the input signal
  • A reversed-wired opamp buffer (non-inverting input connected to output, inverting input driven by signal) should immediately rail to a supply voltage, but the Newton-Raphson solver was finding the exact metastable solution due to perfectly symmetric initial conditions
  • The 1e-6 V perturbation mimics the real-world input offset voltage present in all physical opamps and is orders of magnitude too small to affect normal negative-feedback circuits

Fixes sharpie7#1009

Test plan

  • Load a positive-feedback opamp buffer circuit (output wired to non-inverting input, signal on inverting input) and verify the output rails to a supply voltage instead of tracking the input
  • Load a normal negative-feedback opamp buffer and verify it still tracks the input correctly
  • Load existing opamp example circuits (inverting amp, non-inverting amp, etc.) and verify they behave identically
  • Run the Schmitt trigger example (amp-schmitt.txt) and verify correct hysteresis behavior

Generated with Claude Code

@pfalstad
Copy link
Copy Markdown
Owner

pfalstad commented Mar 3, 2026

The op amp has a number of issues but I'm very nervous about changing it because I've tried to fix them in the past and whenever I make a change, there's always one example circuit that breaks. I will take a look at this but it might be lower priority.

@esaruoho
Copy link
Copy Markdown
Author

esaruoho commented Mar 5, 2026

Understood -- no rush on this one. The change only adds a tiny random perturbation (1e-8V) to break the exact metastable equilibrium at startup. It should not affect any circuit that is not already sitting on the knife-edge. Happy to test against all the opamp example circuits if that would help you feel more confident about it.

@esaruoho esaruoho changed the base branch from v3-dev to dev April 15, 2026 09:50
Add a tiny initial offset (1e-6 V) to the opamp lastvd state on
reset to break metastable equilibrium.  Without this, a positive-
feedback buffer (non-inverting input wired to output) unrealistically
tracks the input because the Newton-Raphson solver converges on the
exact metastable solution.  Real opamps have input offset voltage that
would immediately push the output to a supply rail.  The perturbation
is small enough to have no effect on normal negative-feedback circuits.

Fixes sharpie7#1009

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@esaruoho esaruoho force-pushed the fix-opamp-metastable branch from d358a78 to 64ec688 Compare April 15, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants