Skip to main content

OpAmpRoot

Struct OpAmpRoot 

pub struct OpAmpRoot {
    pub model: OpAmpModel,
    /* private fields */
}
Expand description

Models op-amp behavior in two topologies:

  • Inverting: Vout = -(Rf/Ri) * Vin, input from WDF wave (virtual ground)
  • Non-inverting: Vout = (1 + Rf/Ri) * Vp, input via set_vp()

Unity-gain buffer (voltage follower) is just NonInverting with gain=1. The “third mode” doesn’t exist - it’s the same circuit with Rf=0, Ri=∞.

Non-idealities:

  • GBW-limited closed-loop bandwidth (single-pole rolloff at f_cl = GBW / gain)
  • Slew rate limiting (LM308’s slow slew = RAT’s character)
  • Output saturation at supply rails
  • Soft clipping via feedback diodes (optional)

Fields§

§model: OpAmpModel

Implementations§

§

impl OpAmpRoot

pub fn new(model: OpAmpModel) -> OpAmpRoot

Create a unity-gain buffer (voltage follower).

This is a non-inverting amplifier with gain=1 (Rf=0, Ri=∞). Input via set_vp(), output tracks Vp exactly.

pub fn unity_gain(model: OpAmpModel) -> OpAmpRoot

Create a unity-gain buffer (alias for new).

pub fn new_inverting(model: OpAmpModel, gain: f64) -> OpAmpRoot

Create an inverting op-amp: Vout = -gain * Vin.

pub fn new_non_inverting(model: OpAmpModel, gain: f64) -> OpAmpRoot

Create a non-inverting op-amp: Vout = gain * Vin.

pub fn set_vp(&mut self, vp: f64)

Set the non-inverting input voltage (V+).

For non-inverting mode (including unity buffer), this is the input signal. For inverting mode, this is typically ground or a bias voltage.

pub fn vp(&self) -> f64

Get the current non-inverting input voltage.

pub fn set_gain(&mut self, gain: f64)

Set the closed-loop gain. Recomputes GBW rolloff coefficient.

pub fn set_gbw_gain(&mut self, gbw_gain: f64)

Set only the GBW gain used for bandwidth calculation, without changing the VCVS gain.

Used by the 3-port adaptor path where the VCVS mode gain is 1.0 (the scattering matrix handles port impedance), but the GBW rolloff filter must use the true closed-loop gain to compute f_cl = GBW / gbw_gain correctly.

pub fn gain(&self) -> f64

Get the current gain.

pub fn is_non_inverting(&self) -> bool

Check if this op-amp is in non-inverting mode.

Non-inverting op-amps require input via set_vp(). Inverting op-amps get input from the WDF wave variable.

pub fn set_soft_clip(&mut self, diode_vf: f64)

Enable soft clipping mode for feedback diodes.

pub fn clear_soft_clip(&mut self)

Disable soft clipping.

pub fn set_sample_rate(&mut self, sample_rate: f64)

Set the sample rate (for slew rate limiting and GBW filter).

pub fn sample_rate(&self) -> f64

Get the current sample rate.

pub fn gbw_coeff(&self) -> f64

Get the current GBW filter coefficient (for testing).

pub fn set_v_max(&mut self, v_max: f64)

Set the maximum output voltage (supply rails). Set symmetric rail limits (both positive and negative).

pub fn set_v_rails(&mut self, v_rail_pos: f64, v_rail_neg: f64)

Set asymmetric rail limits (from bias analysis).

pub fn v_max(&self) -> f64

Get the symmetric v_max (minimum of both rails).

pub fn set_feedback_config(&mut self, cfg: FeedbackConfig)

Set feedback configuration for pot-driven gain control.

After this is set, set_feedback_pot_r() can be called to recompute the gain from the pot’s current resistance.

DEPRECATED: Only used in test code. The compiler pipeline uses WdfStage::notify_pot_changed() + incremental recompute instead.

pub fn feedback_pot_id(&self) -> Option<&str>

Get the feedback pot component ID, if configured.

pub fn set_feedback_pot_r(&mut self, pot_r: f64)

Recompute gain from the feedback pot’s current resistance.

Called by the stage when it detects the feedback pot changed. The gain formula depends on the topology:

  • Pot in Rf, inverting: gain = effective_rf / ri
  • Pot in Rf, non-inverting: gain = 1 + effective_rf / ri
  • Pot in Ri, non-inverting: gain = 1 + rf / effective_ri

pub fn set_feedback(&mut self, _ratio: f64, _vm_external: f64)

Configure feedback topology (for advanced use). This is a no-op for gain stages; use set_gain() instead.

pub fn compute_vs_voltage(&mut self, input: f64) -> f64

Compute the voltage source value for a DiodePair stage with opamp feedback.

Applies inverting gain + GBW rolloff + slew limiting, but NOT soft clipping (the DiodePair NR solver handles the actual clipping).

For an inverting opamp with feedback diodes, the signal path is: input → Ri → virtual ground (neg) → diodes in feedback → output The opamp gain sets the drive level into the diode clipping stage.

Returns the magnitude (positive) of the gained voltage, since WDF DiodePair convention already negates the VS voltage.

pub fn reset(&mut self)

Reset internal state.

Trait Implementations§

§

impl Clone for OpAmpRoot

§

fn clone(&self) -> OpAmpRoot

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for OpAmpRoot

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl WdfRoot for OpAmpRoot

§

fn process(&mut self, a: f64, _rp: f64) -> f64

Op-amp processing based on mode.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more