$(instance)OpAmpDetailed Icon

OpAmpDetailed

Detailed model of an operational amplifier

Usage

OpAmpDetailed(Rdm=2.0e6, Rcm=2.0e9, Cin=1.4e-12, Vos=1.0e-3, Ib=80.0e-9, Ios=20.0e-9, vcp=0.0, vcm=0.0, Avd0=106.0, CMRR=90.0, fp1=5.0, fp2=2.0e6, fp3=20.0e6, fp4=100.0e6, fz=5.0e6, sr_p=0.5e6, sr_m=0.5e6, Rout=75.0, Imaxso=25.0e-3, Imaxsi=25.0e-3, Ts=0.0000012, vcp_abs=abs(vcp), vcm_abs=abs(vcm), I1=Ib+Ios/2.0, I2=Ib-Ios/2.0, Avd0_val=10.0^(Avd0/20.0), Avcm_val=(Avd0_val/(10.0^(CMRR/20.0)))/2.0, sr_p_val=abs(sr_p), sr_m_val=-abs(sr_m), Imaxso_val=abs(Imaxso), Imaxsi_val=abs(Imaxsi))

Parameters:

NameDescriptionUnitsDefault value
RdmInput resistance (differential input mode)Ω2000000
RcmInput resistance (common mode)Ω2000000000
CinInput capacitanceF1.4e-12
VosInput offset voltageV0.001
IbInput bias currentA8e-8
IosInput offset currentA2e-8
vcpCorrection value for limiting by p_supplyV0
vcmCorrection value for limiting by n_supplyV0
Avd0Differential amplifier [dB]dB106
CMRRCommon-mode rejection [dB]dB90
fp1Dominant poleHz5
fp2Pole frequencyHz2000000
fp3Pole frequencyHz20000000
fp4Pole frequencyHz100000000
fzZero frequencyHz5000000
sr_pSlew rate for increaseV/s500000
sr_mSlew rate for decreaseV/s500000
RoutOutput resistanceΩ75
ImaxsoMaximal output current (source current)A0.025
ImaxsiMaximal output current (sink current)A0.025
TsSampling Timenumber of intervals: 2500, stop time: 0.003s
vcp_absPositive correction value for limiting by p_supplyVabs(vcp)
vcm_absPositive correction value for limiting by n_supplyVabs(vcm)
I1Current of internal source I1AIb + Ios / 2
I2Current of internal source I2AIb - Ios / 2
Avd0_valDifferential mode gain10 ^ (Avd0 / 20)
Avcm_valCommon mode gain(Avd0_val / (10 ^ (CMRR / 20))) / 2
sr_p_valValue of slew rate for increaseV/sabs(sr_p)
sr_m_valNegative value of slew rate for increaseV/s-abs(sr_m)
Imaxso_valOrientation out outpAabs(Imaxso)
Imaxsi_valOrientation into outpAabs(Imaxsi)

Connectors

Variables

NameDescriptionUnits
v_posV
v_negV
v_vosV
v_3V
v_inV
v_4V
i_vosA
i_3A
i_r2A
i_c3A
i_4A
q_fr1
q_fr2
q_fr3
q_sumV
q_sum_helpV
q_fp1V
v_sourceV
xAuxiliary variable for slew rateV
v_outV
i_outA

Behavior

\[ \begin{align} \mathtt{v\_pos}\left( t \right) &= \mathtt{p\_supply.v}\left( t \right) \\ \mathtt{v\_neg}\left( t \right) &= \mathtt{n\_supply.v}\left( t \right) \\ \mathtt{p.i}\left( t \right) &= \mathtt{i\_vos}\left( t \right) \\ \mathtt{n.i}\left( t \right) &= \mathtt{i\_4}\left( t \right) - \mathtt{i\_c3}\left( t \right) - \mathtt{i\_r2}\left( t \right) \\ 0 &= \mathtt{i\_3}\left( t \right) - \mathtt{i\_vos}\left( t \right) + \mathtt{i\_c3}\left( t \right) + \mathtt{i\_r2}\left( t \right) \\ \mathtt{p.v}\left( t \right) - \mathtt{n.v}\left( t \right) &= \mathtt{v\_in}\left( t \right) + \mathtt{v\_vos}\left( t \right) \\ \mathtt{v\_4}\left( t \right) &= \mathtt{n.v}\left( t \right) \\ \mathtt{v\_3}\left( t \right) &= \mathtt{p.v}\left( t \right) - \mathtt{v\_vos}\left( t \right) \\ \mathtt{v\_vos}\left( t \right) &= \mathtt{Vos} \\ \mathtt{i\_3}\left( t \right) &= \mathtt{I1} + \frac{\mathtt{v\_3}\left( t \right)}{\mathtt{Rcm}} \\ \mathtt{v\_in}\left( t \right) &= \mathtt{Rdm} \mathtt{i\_r2}\left( t \right) \\ \mathtt{i\_c3}\left( t \right) &= \mathtt{Cin} \frac{\mathrm{d} \mathtt{v\_in}\left( t \right)}{\mathrm{d}t} \\ \mathtt{i\_4}\left( t \right) &= \mathtt{I2} + \frac{\mathtt{v\_4}\left( t \right)}{\mathtt{Rcm}} \\ \frac{\mathrm{d} \mathtt{q\_fr1}\left( t \right)}{\mathrm{d}t} &= 6.2832 \mathtt{fp2} \left( \mathtt{v\_in}\left( t \right) - \mathtt{q\_fr1}\left( t \right) \right) \\ \mathtt{q\_fr2}\left( t \right) + \frac{\frac{\mathrm{d} \mathtt{q\_fr2}\left( t \right)}{\mathrm{d}t}}{6.2832 \mathtt{fp3}} &= \mathtt{q\_fr1}\left( t \right) + \frac{\frac{\mathrm{d} \mathtt{q\_fr1}\left( t \right)}{\mathrm{d}t}}{6.2832 \mathtt{fz}} \\ \frac{\mathrm{d} \mathtt{q\_fr3}\left( t \right)}{\mathrm{d}t} &= 6.2832 \mathtt{fp4} \left( \mathtt{q\_fr2}\left( t \right) - \mathtt{q\_fr3}\left( t \right) \right) \\ \mathtt{q\_sum}\left( t \right) &= \mathtt{Avcm\_val} \left( \mathtt{v\_4}\left( t \right) + \mathtt{v\_3}\left( t \right) \right) + \mathtt{Avd0\_val} \mathtt{q\_fr3}\left( t \right) \\ \mathtt{q\_sum\_help}\left( t \right) &= ifelse\left( \left( \mathtt{q\_sum}\left( t \right) > - \mathtt{vcp\_abs} + \mathtt{v\_pos}\left( t \right) \right) \wedge \left( \mathtt{q\_fp1}\left( t \right) \geq - \mathtt{vcp\_abs} + \mathtt{v\_pos}\left( t \right) \right), - \mathtt{vcp\_abs} + \mathtt{v\_pos}\left( t \right), ifelse\left( \left( \mathtt{q\_sum}\left( t \right) < \mathtt{vcm\_abs} + \mathtt{v\_neg}\left( t \right) \right) \wedge \left( \mathtt{q\_fp1}\left( t \right) \leq \mathtt{vcm\_abs} + \mathtt{v\_neg}\left( t \right) \right), \mathtt{vcm\_abs} + \mathtt{v\_neg}\left( t \right), \mathtt{q\_sum}\left( t \right) \right) \right) \\ \frac{\mathrm{d} \mathtt{q\_fp1}\left( t \right)}{\mathrm{d}t} &= 6.2832 \mathtt{fp1} \left( - \mathtt{q\_fp1}\left( t \right) + \mathtt{q\_sum\_help}\left( t \right) \right) \\ \frac{\mathrm{d} x\left( t \right)}{\mathrm{d}t} &= \frac{\mathtt{q\_fp1}\left( t \right) - \mathtt{v\_source}\left( t \right)}{\mathtt{Ts}} \\ \frac{\mathrm{d} \mathtt{v\_source}\left( t \right)}{\mathrm{d}t} &= ifelse\left( \frac{\mathrm{d} x\left( t \right)}{\mathrm{d}t} > \mathtt{sr\_p\_val}, \mathtt{sr\_p\_val}, ifelse\left( \frac{\mathrm{d} x\left( t \right)}{\mathrm{d}t} < \mathtt{sr\_m\_val}, \mathtt{sr\_m\_val}, \frac{\mathrm{d} x\left( t \right)}{\mathrm{d}t} \right) \right) \\ \mathtt{v\_out}\left( t \right) &= \mathtt{outp.v}\left( t \right) \\ \mathtt{i\_out}\left( t \right) &= \mathtt{outp.i}\left( t \right) \\ \mathtt{i\_out}\left( t \right) &= ifelse\left( \mathtt{v\_out}\left( t \right) > \mathtt{v\_source}\left( t \right) + \mathtt{Imaxsi\_val} \mathtt{Rout}, \mathtt{Imaxsi\_val}, ifelse\left( \mathtt{v\_out}\left( t \right) < \mathtt{v\_source}\left( t \right) - \mathtt{Imaxso\_val} \mathtt{Rout}, - \mathtt{Imaxso\_val}, \frac{ - \mathtt{v\_source}\left( t \right) + \mathtt{v\_out}\left( t \right)}{\mathtt{Rout}} \right) \right) \\ \mathtt{p\_supply.i}\left( t \right) &= 0 \\ \mathtt{n\_supply.i}\left( t \right) &= 0 \end{align} \]

Source

# Detailed model of an operational amplifier
component OpAmpDetailed
  # Positive pin of the input port
  p = Pin() [{
    "JuliaSim": {
      "placement": {"icon": {"iconName": "pos", "x1": -50, "y1": 650, "x2": 50, "y2": 750}}
    }
  }]
  # Negative pin of the input port
  n = Pin() [{
    "JuliaSim": {
      "placement": {"icon": {"iconName": "neg", "x1": -50, "y1": 250, "x2": 50, "y2": 350}}
    }
  }]
  # Output pin
  outp = Pin() [{
    "JuliaSim": {
      "placement": {"icon": {"iconName": "pos", "x1": 950, "y1": 450, "x2": 1050, "y2": 550}}
    }
  }]
  # Positive output voltage limitation
  p_supply = Pin() [{
    "JuliaSim": {
      "placement": {"icon": {"iconName": "pos", "x1": 450, "y1": -50, "x2": 550, "y2": 50}}
    }
  }]
  # Negative output voltage limitation
  n_supply = Pin() [{
    "JuliaSim": {
      "placement": {"icon": {"iconName": "neg", "x1": 450, "y1": 950, "x2": 550, "y2": 1050}}
    }
  }]
  # Input resistance (differential input mode)
  parameter Rdm::Resistance = 2.0e6
  # Input resistance (common mode)
  parameter Rcm::Resistance = 2.0e9
  # Input capacitance
  parameter Cin::Capacitance = 1.4e-12
  # Input offset voltage
  parameter Vos::Voltage = 1.0e-3
  # Input bias current
  parameter Ib::Current = 80.0e-9
  # Input offset current
  parameter Ios::Current = 20.0e-9
  # Correction value for limiting by `p_supply`
  parameter vcp::Voltage = 0.0
  # Correction value for limiting by `n_supply`
  parameter vcm::Voltage = 0.0
  # Differential amplifier [dB]
  parameter Avd0::SoundPowerLevel = 106.0
  # Common-mode rejection [dB]
  parameter CMRR::SoundPowerLevel = 90.0
  # Dominant pole
  parameter fp1::Frequency = 5.0
  # Pole frequency
  parameter fp2::Frequency = 2.0e6
  # Pole frequency
  parameter fp3::Frequency = 20.0e6
  # Pole frequency
  parameter fp4::Frequency = 100.0e6
  # Zero frequency
  parameter fz::Frequency = 5.0e6
  # Slew rate for increase
  parameter sr_p::VoltageSlope = 0.5e6
  # Slew rate for decrease
  parameter sr_m::VoltageSlope = 0.5e6
  # Output resistance
  parameter Rout::Resistance = 75.0
  # Maximal output current (source current)
  parameter Imaxso::Current = 25.0e-3
  # Maximal output current (sink current)
  parameter Imaxsi::Current = 25.0e-3
  # Sampling Time | number of intervals: 2500, stop time: 0.003
  parameter Ts::Time = 0.0000012
  # Positive correction value for limiting by `p_supply`
  final parameter vcp_abs::Voltage = abs(vcp)
  # Positive correction value for limiting by `n_supply`
  final parameter vcm_abs::Voltage = abs(vcm)
  # Current of internal source I1
  final parameter I1::Current = Ib+Ios/2.0
  # Current of internal source I2
  final parameter I2::Current = Ib-Ios/2.0
  # Differential mode gain
  final parameter Avd0_val::Real = 10.0^(Avd0/20.0)
  # Common mode gain
  final parameter Avcm_val::Real = (Avd0_val/(10.0^(CMRR/20.0)))/2.0
  # Value of slew rate for increase
  final parameter sr_p_val::VoltageSlope = abs(sr_p)
  # Negative value of slew rate for increase
  final parameter sr_m_val::VoltageSlope = -abs(sr_m)
  # Orientation out outp
  final parameter Imaxso_val::Current = abs(Imaxso)
  # Orientation into outp
  final parameter Imaxsi_val::Current = abs(Imaxsi)
  variable v_pos::Voltage
  variable v_neg::Voltage
  variable v_vos::Voltage
  variable v_3::Voltage
  variable v_in::Voltage
  variable v_4::Voltage
  variable i_vos::Current
  variable i_3::Current
  variable i_r2::Current
  variable i_c3::Current
  variable i_4::Current
  variable q_fr1::Real
  variable q_fr2::Real
  variable q_fr3::Real
  variable q_sum::Voltage
  variable q_sum_help::Voltage
  variable q_fp1::Voltage
  variable v_source::Voltage
  # Auxiliary variable for slew rate
  variable x::Voltage
  variable v_out::Voltage
  variable i_out::Current
relations
  initial v_source = q_fp1
  initial x = 0
  # power supply
  v_pos = p_supply.v
  v_neg = n_supply.v
  # input stage
  p.i = i_vos
  n.i = i_4-i_r2-i_c3
  0 = i_3+i_r2+i_c3-i_vos
  p.v-n.v = v_vos+v_in
  v_4 = n.v
  v_3 = p.v-v_vos
  v_vos = Vos
  i_3 = I1+v_3/Rcm
  v_in = Rdm*i_r2
  i_c3 = Cin*der(v_in)
  i_4 = I2+v_4/Rcm
  # Frequency response
  der(q_fr1) = 2.0*π*fp2*(v_in-q_fr1)
  q_fr2+(1.0/(2.0*π*fp3))*der(q_fr2) = q_fr1+(1.0/(2.0*π*fz))*der(q_fr1)
  der(q_fr3) = 2.0*π*fp4*(q_fr2-q_fr3)
  # gain stage
  q_sum = Avd0_val*q_fr3+Avcm_val*(v_3+v_4)
  q_sum_help = limit_q_sum(q_sum, q_fp1, v_pos, v_neg, vcp_abs, vcm_abs)
  der(q_fp1) = 2.0*π*fp1*(q_sum_help-q_fp1)
  # slew rate stage
  der(x) = (q_fp1-v_source)/Ts
  der(v_source) = ifelse(der(x)>sr_p_val, sr_p_val, ifelse(der(x)<sr_m_val, sr_m_val, der(x)))
  # output stage
  v_out = outp.v
  i_out = outp.i
  i_out = limit_out_current(v_source, v_out, Rout, Imaxsi_val, Imaxso_val)
  p_supply.i = 0
  n_supply.i = 0
end
Flattened Source
# Detailed model of an operational amplifier
component OpAmpDetailed
  # Positive pin of the input port
  p = Pin() [{
    "JuliaSim": {
      "placement": {"icon": {"iconName": "pos", "x1": -50, "y1": 650, "x2": 50, "y2": 750}}
    }
  }]
  # Negative pin of the input port
  n = Pin() [{
    "JuliaSim": {
      "placement": {"icon": {"iconName": "neg", "x1": -50, "y1": 250, "x2": 50, "y2": 350}}
    }
  }]
  # Output pin
  outp = Pin() [{
    "JuliaSim": {
      "placement": {"icon": {"iconName": "pos", "x1": 950, "y1": 450, "x2": 1050, "y2": 550}}
    }
  }]
  # Positive output voltage limitation
  p_supply = Pin() [{
    "JuliaSim": {
      "placement": {"icon": {"iconName": "pos", "x1": 450, "y1": -50, "x2": 550, "y2": 50}}
    }
  }]
  # Negative output voltage limitation
  n_supply = Pin() [{
    "JuliaSim": {
      "placement": {"icon": {"iconName": "neg", "x1": 450, "y1": 950, "x2": 550, "y2": 1050}}
    }
  }]
  # Input resistance (differential input mode)
  parameter Rdm::Resistance = 2.0e6
  # Input resistance (common mode)
  parameter Rcm::Resistance = 2.0e9
  # Input capacitance
  parameter Cin::Capacitance = 1.4e-12
  # Input offset voltage
  parameter Vos::Voltage = 1.0e-3
  # Input bias current
  parameter Ib::Current = 80.0e-9
  # Input offset current
  parameter Ios::Current = 20.0e-9
  # Correction value for limiting by `p_supply`
  parameter vcp::Voltage = 0.0
  # Correction value for limiting by `n_supply`
  parameter vcm::Voltage = 0.0
  # Differential amplifier [dB]
  parameter Avd0::SoundPowerLevel = 106.0
  # Common-mode rejection [dB]
  parameter CMRR::SoundPowerLevel = 90.0
  # Dominant pole
  parameter fp1::Frequency = 5.0
  # Pole frequency
  parameter fp2::Frequency = 2.0e6
  # Pole frequency
  parameter fp3::Frequency = 20.0e6
  # Pole frequency
  parameter fp4::Frequency = 100.0e6
  # Zero frequency
  parameter fz::Frequency = 5.0e6
  # Slew rate for increase
  parameter sr_p::VoltageSlope = 0.5e6
  # Slew rate for decrease
  parameter sr_m::VoltageSlope = 0.5e6
  # Output resistance
  parameter Rout::Resistance = 75.0
  # Maximal output current (source current)
  parameter Imaxso::Current = 25.0e-3
  # Maximal output current (sink current)
  parameter Imaxsi::Current = 25.0e-3
  # Sampling Time | number of intervals: 2500, stop time: 0.003
  parameter Ts::Time = 0.0000012
  # Positive correction value for limiting by `p_supply`
  final parameter vcp_abs::Voltage = abs(vcp)
  # Positive correction value for limiting by `n_supply`
  final parameter vcm_abs::Voltage = abs(vcm)
  # Current of internal source I1
  final parameter I1::Current = Ib+Ios/2.0
  # Current of internal source I2
  final parameter I2::Current = Ib-Ios/2.0
  # Differential mode gain
  final parameter Avd0_val::Real = 10.0^(Avd0/20.0)
  # Common mode gain
  final parameter Avcm_val::Real = (Avd0_val/(10.0^(CMRR/20.0)))/2.0
  # Value of slew rate for increase
  final parameter sr_p_val::VoltageSlope = abs(sr_p)
  # Negative value of slew rate for increase
  final parameter sr_m_val::VoltageSlope = -abs(sr_m)
  # Orientation out outp
  final parameter Imaxso_val::Current = abs(Imaxso)
  # Orientation into outp
  final parameter Imaxsi_val::Current = abs(Imaxsi)
  variable v_pos::Voltage
  variable v_neg::Voltage
  variable v_vos::Voltage
  variable v_3::Voltage
  variable v_in::Voltage
  variable v_4::Voltage
  variable i_vos::Current
  variable i_3::Current
  variable i_r2::Current
  variable i_c3::Current
  variable i_4::Current
  variable q_fr1::Real
  variable q_fr2::Real
  variable q_fr3::Real
  variable q_sum::Voltage
  variable q_sum_help::Voltage
  variable q_fp1::Voltage
  variable v_source::Voltage
  # Auxiliary variable for slew rate
  variable x::Voltage
  variable v_out::Voltage
  variable i_out::Current
relations
  initial v_source = q_fp1
  initial x = 0
  # power supply
  v_pos = p_supply.v
  v_neg = n_supply.v
  # input stage
  p.i = i_vos
  n.i = i_4-i_r2-i_c3
  0 = i_3+i_r2+i_c3-i_vos
  p.v-n.v = v_vos+v_in
  v_4 = n.v
  v_3 = p.v-v_vos
  v_vos = Vos
  i_3 = I1+v_3/Rcm
  v_in = Rdm*i_r2
  i_c3 = Cin*der(v_in)
  i_4 = I2+v_4/Rcm
  # Frequency response
  der(q_fr1) = 2.0*π*fp2*(v_in-q_fr1)
  q_fr2+(1.0/(2.0*π*fp3))*der(q_fr2) = q_fr1+(1.0/(2.0*π*fz))*der(q_fr1)
  der(q_fr3) = 2.0*π*fp4*(q_fr2-q_fr3)
  # gain stage
  q_sum = Avd0_val*q_fr3+Avcm_val*(v_3+v_4)
  q_sum_help = limit_q_sum(q_sum, q_fp1, v_pos, v_neg, vcp_abs, vcm_abs)
  der(q_fp1) = 2.0*π*fp1*(q_sum_help-q_fp1)
  # slew rate stage
  der(x) = (q_fp1-v_source)/Ts
  der(v_source) = ifelse(der(x)>sr_p_val, sr_p_val, ifelse(der(x)

Test Cases