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: OpAmpModelImplementations§
§impl OpAmpRoot
impl OpAmpRoot
pub fn new(model: OpAmpModel) -> 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
pub fn unity_gain(model: OpAmpModel) -> OpAmpRoot
Create a unity-gain buffer (alias for new).
pub fn new_inverting(model: OpAmpModel, gain: f64) -> OpAmpRoot
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
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)
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 set_gbw_gain(&mut self, gbw_gain: f64)
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 is_non_inverting(&self) -> bool
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)
pub fn set_soft_clip(&mut self, diode_vf: f64)
Enable soft clipping mode for feedback diodes.
pub fn clear_soft_clip(&mut self)
pub fn clear_soft_clip(&mut self)
Disable soft clipping.
pub fn set_sample_rate(&mut self, sample_rate: f64)
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
pub fn sample_rate(&self) -> f64
Get the current sample rate.
pub fn set_v_max(&mut self, v_max: f64)
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)
pub fn set_v_rails(&mut self, v_rail_pos: f64, v_rail_neg: f64)
Set asymmetric rail limits (from bias analysis).
pub fn set_feedback_config(&mut self, cfg: FeedbackConfig)
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>
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)
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)
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
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)
pub fn reset(&mut self)
Reset internal state.