Library for analog electrical models

within Modelica.Electrical;
package Analog "Library for analog electrical models"

  extends Modelica.Icons.Package;
end Analog;


Ideal linear electrical capacitor. The linear capacitor connects the branch voltage v with the branch current i by i = C * dv/dt. The Capacitance C is allowed to be positive or zero.

within Modelica.Electrical.Analog.Basic;
model Capacitor "Ideal linear electrical capacitor"
  extends Interfaces.OnePort(v(start=0));
  parameter SI.Capacitance C(start=1) "Capacitance";

equation
  i = C*der(v);
end Capacitor;


Linear current-controlled current source. The linear current-controlled current source is a TwoPort. The right port current i2 is controlled by the left port current i1 via

within Modelica.Electrical.Analog.Basic;
model CCC "Linear current-controlled current source"
  extends Interfaces.TwoPort;
  parameter Real gain(start=1) "Current gain";

equation
  i2 = i1*gain;
  v1 = 0;
end CCC;


Linear current-controlled voltage source. The linear current-controlled voltage source is a TwoPort. The right port voltage v2 is controlled by the left port current i1 via

within Modelica.Electrical.Analog.Basic;
model CCV "Linear current-controlled voltage source"
  extends Interfaces.TwoPort;

  parameter SI.Resistance transResistance(start=1) "Transresistance";

equation
  v2 = i1*transResistance;
  v1 = 0;
end CCV;


Ideal linear electrical conductor. The linear conductor connects the branch voltage v with the branch current i by i = v*G. The Conductance G is allowed to be positive, zero, or negative.

within Modelica.Electrical.Analog.Basic;
model Conductor "Ideal linear electrical conductor"
  parameter SI.Conductance G(start=1)
    "Conductance at temperature T_ref";
  parameter SI.Temperature T_ref=300.15 "Reference temperature";
  parameter SI.LinearTemperatureCoefficient alpha=0
    "Temperature coefficient of conductance (G_actual = G_ref/(1 + alpha*(T_heatPort - T_ref))";
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=T_ref);
  SI.Conductance G_actual
    "Actual conductance = G_ref/(1 + alpha*(T_heatPort - T_ref))";

equation
  assert((1 + alpha*(T_heatPort - T_ref)) >= Modelica.Constants.eps,
    "Temperature outside scope of model!");
  G_actual = G/(1 + alpha*(T_heatPort - T_ref));
  i = G_actual*v;
  LossPower = v*i;
end Conductor;


Signal adaptor for an Electrical OnePort with voltage and derivative of voltage as outputs and current and derivative of current as inputs (especially useful for FMUs). Adaptor between an electrical oneport and a signal representation of the oneport.
This component is used to provide a pure signal interface around an Electrical model
and export this model in form of an input/output block,
especially as FMU (Functional Mock-up Unit).
Examples of the usage of this adaptor are provided in
Electrical.Analog.Examples.GenerationOfFMUs.
This adaptor has current and derivative of current as inputs and voltage and derivative of voltage as output signals.

within Modelica.Electrical.Analog.Basic;
model GeneralCurrentToVoltageAdaptor
  "Signal adaptor for an Electrical OnePort with voltage and derivative of voltage as outputs and current and derivative of current as inputs (especially useful for FMUs)"
  extends Modelica.Blocks.Interfaces.Adaptors.FlowToPotentialAdaptor(
    final Name_p="v",
    final Name_pder="dv",
    final Name_pder2="d2v",
    final Name_f="i",
    final Name_fder="di",
    final Name_fder2="d2i",
    final use_pder2=false,
    final use_fder2=false,
    final p(unit="V"),
    final pder(unit="V/s"),
    final pder2(unit="V/s2"),
    final f(unit="A"),
    final fder(unit="A/s"),
    final fder2(unit="A/s2"));
  SI.Voltage v "Voltage drop between the two pins (= p.v - n.v)";
  SI.Current i "Current flowing from pin p to pin n";
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_p
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_n
equation
  v = pin_p.v - pin_n.v;
  i = pin_p.i;
  pin_p.i + pin_n.i = 0;
  y = v "output = potential = voltage";
  u = i "input = flow = current";
end GeneralCurrentToVoltageAdaptor;


Signal adaptor for an Electrical OnePort with current and derivative of current as output and voltage and derivative of voltage as input (especially useful for FMUs). Adaptor between an electrical openport and a signal representation of the oneport.
This component is used to provide a pure signal interface around an Electrical model
and export this model in form of an input/output block,
especially as FMU (Functional Mock-up Unit).
Examples of the usage of this adaptor are provided in
Electrical.Analog.Examples.GenerationOfFMUs.
This adaptor has voltage and derivative of voltage as input signals and current and derivative of current as output signal.

within Modelica.Electrical.Analog.Basic;
model GeneralVoltageToCurrentAdaptor
  "Signal adaptor for an Electrical OnePort with current and derivative of current as output and voltage and derivative of voltage as input (especially useful for FMUs)"
  extends Modelica.Blocks.Interfaces.Adaptors.PotentialToFlowAdaptor(
    final Name_p="v",
    final Name_pder="dv",
    final Name_pder2="d2v",
    final Name_f="i",
    final Name_fder="di",
    final Name_fder2="d2i",
    final use_pder2=false,
    final use_fder2=false,
    final p(unit="V"),
    final pder(unit="V/s"),
    final pder2(unit="V/s2"),
    final f(unit="A"),
    final fder(unit="A/s"),
    final fder2(unit="A/s2"));
  SI.Voltage v "Voltage drop between the two pins (= p.v - n.v)";
  SI.Current i "Current flowing from pin p to pin n";
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_p
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_n
equation
  v = pin_p.v - pin_n.v;
  i = pin_p.i;
  pin_p.i + pin_n.i = 0;
  y = i "output = flow = current";
  u = v "input = potential = voltage";
end GeneralVoltageToCurrentAdaptor;


Ground node. Ground of an electrical circuit. The potential at the ground node is zero. Every electrical circuit has to contain at least one ground object.

within Modelica.Electrical.Analog.Basic;
model Ground "Ground node"

  Interfaces.Pin p
equation
  p.v = 0;
end Ground;


Gyrator. A gyrator is a two-port element defined by the following equations:

within Modelica.Electrical.Analog.Basic;
model Gyrator "Gyrator"
  extends Interfaces.TwoPort;
  parameter SI.Conductance G1(start=1) "Primary gyration conductance";
  parameter SI.Conductance G2(start=1) "Secondary gyration conductance";
equation
  i1 = G2*v2;
  i2 = -G1*v1;
end Gyrator;


Ideal linear electrical inductor. The linear inductor connects the branch voltage v with the branch current i by v = L * di/dt. The Inductance L is allowed to be positive, or zero.

within Modelica.Electrical.Analog.Basic;
model Inductor "Ideal linear electrical inductor"
  extends Interfaces.OnePort(i(start=0));
  parameter SI.Inductance L(start=1) "Inductance";

equation
  L*der(i) = v;
end Inductor;


Generic transformer with free number of inductors. The model M_Transformer is a model of a transformer with the possibility to choose the number of inductors. Inside the model, an inductance matrix is built based on the inductance of the inductors and the coupling inductances between the inductors given as a parameter vector from the user of the model.

within Modelica.Electrical.Analog.Basic;
model M_Transformer "Generic transformer with free number of inductors"

  parameter Integer N(final min=1) = 3 "Number of inductors";
protected
  parameter Integer dimL=div(N*(N + 1), 2);
public
  parameter SI.Inductance L[dimL]={1,0.1,0.2,2,0.3,3}
    "Inductances and coupling inductances";
  Modelica.Electrical.Analog.Interfaces.PositivePin p[N] "Positive pin"
  Modelica.Electrical.Analog.Interfaces.NegativePin n[N] "Negative pin"

  SI.Voltage v[N] "Voltage drop over inductors";
  SI.Current i[N](each start=0, each fixed=true)
    "Current through inductors";
  parameter SI.Inductance Lm[N, N](each final fixed=false)
    "Complete symmetric inductance matrix, calculated internally";

initial equation
  for s in 1:N loop
    Lm[s,s] = L[(s - 1)*N - div((s - 1)*s, 2) + s];
    for z in s + 1:N loop
      Lm[s,z] = L[(s - 1)*N - div((s - 1)*s, 2) + z];
      Lm[z,s] = L[(s - 1)*N - div((s - 1)*s, 2) + z];
    end for;
  end for;

equation
  for j in 1:N loop
    v[j] = p[j].v - n[j].v;
    0 = p[j].i + n[j].i;
    i[j] = p[j].i;
  end for;

  v = Lm*der(i);
end M_Transformer;


Simple nonideal model of an OpAmp with limitation. The OpAmp is a simple nonideal model with a smooth out.v = f(vin) characteristic, where "vin = in_p.v - in_n.v". The characteristic is limited by VMax.v and VMin.v. Its slope at vin=0 is the parameter Slope, which must be positive. (Therefore, the absolute value of Slope is taken into calculation.)

within Modelica.Electrical.Analog.Basic;
model OpAmp "Simple nonideal model of an OpAmp with limitation"
  parameter Real Slope(start=10000)
    "Slope of the out.v/vin characteristic at vin=0";
  Modelica.Electrical.Analog.Interfaces.PositivePin in_p
    "Positive pin of the input port"
  Modelica.Electrical.Analog.Interfaces.NegativePin in_n
    "Negative pin of the input port"
  Modelica.Electrical.Analog.Interfaces.PositivePin out "Output pin"
  Modelica.Electrical.Analog.Interfaces.PositivePin VMax
    "Positive output voltage limitation"
  Modelica.Electrical.Analog.Interfaces.NegativePin VMin
    "Negative output voltage limitation"
  SI.Voltage vin "Input voltage";
protected
  Real f "Auxiliary variable";
  Real absSlope;
equation
  in_p.i = 0;
  in_n.i = 0;
  VMax.i = 0;
  VMin.i = 0;
  vin = in_p.v - in_n.v;
  f = 2/(VMax.v - VMin.v);
  absSlope = if (Slope < 0) then -Slope else Slope;
  out.v = (VMax.v + VMin.v)/2 + absSlope*vin/(1 + absSlope*smooth(0, (if (f*
    vin < 0) then -f*vin else f*vin)));
end OpAmp;


Detailed model of an operational amplifier. Internal limitation function, designed for OpAmpDetailed, not for purpose of external usage.

within Modelica.Electrical.Analog.Basic;
model OpAmpDetailed "Detailed model of an operational amplifier"
  // literature: Conelly, J.A.; Choi, P.: Macromodelling with SPICE. Englewood Cliffs: Prentice-Hall, 1992
  import Modelica.Constants.pi;
  parameter SI.Resistance Rdm=2.0e6
    "Input resistance (differential input mode)";
  parameter SI.Resistance Rcm=2.0e9 "Input resistance (common mode)";
  parameter SI.Capacitance Cin=1.4e-12 "Input capacitance";
  parameter SI.Voltage Vos=1.0e-3 "Input offset voltage";
  parameter SI.Current Ib=80.0e-9 "Input bias current";
  parameter SI.Current Ios=20.0e-9 "Input offset current";
  parameter SI.Voltage vcp=0.0 "Correction value for limiting by p_supply";
  parameter SI.Voltage vcm=0.0 "Correction value for limiting by msupply";
  parameter Real Avd0=106.0 "Differential amplifier [dB]";
  parameter Real CMRR=90.0 "Common-mode rejection [dB]";
  parameter SI.Frequency fp1=5.0 "Dominant pole";
  parameter SI.Frequency fp2=2.0e6 "Pole frequency";
  parameter SI.Frequency fp3=20.0e6 "Pole frequency";
  parameter SI.Frequency fp4=100.0e6 "Pole frequency";
  parameter SI.Frequency fz=5.0e6 "Zero frequency";
  parameter SI.VoltageSlope sr_p=0.5e6 "Slew rate for increase";
  parameter SI.VoltageSlope sr_m=0.5e6 "Slew rate for decrease";
  parameter SI.Resistance Rout=75.0 "Output resistance";
  parameter SI.Current Imaxso=25.0e-3
    "Maximal output current (source current)";
  parameter SI.Current Imaxsi=25.0e-3 "Maximal output current (sink current)";

  // number of intervals: 2500, stop time: 0.003
  parameter SI.Time Ts=0.0000012 "Sampling time";

  // power supply
  final parameter SI.Voltage vcp_abs=abs(vcp)
    "Positive correction value for limiting by p_supply";
  final parameter SI.Voltage vcm_abs=abs(vcm)
    "Positive correction value for limiting by msupply";

  // input stage
  //  Ib = 0.5*(I1 + I2);
  //  Ios = I1 - I2;
  final parameter SI.Current I1=Ib + Ios/2.0 "Current of internal source I1";
  final parameter SI.Current I2=Ib - Ios/2.0 "Current of internal source I2";

  // gain stage (difference and common mode)
  final parameter Real Avd0_val=10.0^(Avd0/20.0) "Differential mode gain";
  final parameter Real Avcm_val=(Avd0_val/(10.0^(CMRR/20.0)))/2.0
    "Common mode gain";

  // slew rate stage
  final parameter SI.VoltageSlope sr_p_val=abs(sr_p)
    "Value of slew rate for increase";
  final parameter SI.VoltageSlope sr_m_val=-abs(sr_m)
    "Negative value of slew rate for increase";

  // output stage
  final parameter SI.Current Imaxso_val=abs(Imaxso) "Orientation out outp";
  final parameter SI.Current Imaxsi_val=abs(Imaxsi) "Orientation into outp";

  Modelica.Electrical.Analog.Interfaces.PositivePin p
    "Positive pin of the input port"
  Modelica.Electrical.Analog.Interfaces.NegativePin m
    "Negative pin of the input port"
  Modelica.Electrical.Analog.Interfaces.PositivePin outp "Output pin"
  Modelica.Electrical.Analog.Interfaces.PositivePin p_supply
    "Positive output voltage limitation"
  Modelica.Electrical.Analog.Interfaces.NegativePin m_supply
    "Negative output voltage limitation"

  // power supply
  SI.Voltage v_pos;
  SI.Voltage v_neg;

  // input stage
  SI.Voltage v_vos;
  SI.Voltage v_3;
  SI.Voltage v_in;
  SI.Voltage v_4;

  SI.Current i_vos;
  SI.Current i_3;
  SI.Current i_r2;
  SI.Current i_c3;
  SI.Current i_4;

  // frequency response
  Real q_fr1;
  Real q_fr2;
  Real q_fr3;

  // gain stage
  SI.Voltage q_sum;
  SI.Voltage q_sum_help;
  SI.Voltage q_fp1;

  // slew rate stage
  SI.Voltage v_source;

  SI.Voltage x "Auxiliary variable for slew rate";

  // output stage
  SI.Voltage v_out;

  SI.Current i_out;

  // functions
  function FCNiout_limit "Internal limitation function"
    extends Modelica.Icons.Function;
    input SI.Voltage v_source;
    input SI.Voltage v_out;
    input SI.Resistance Rout;
    input SI.Current Imaxsi_val;
    input SI.Current Imaxso_val;
    output SI.Current result;

  algorithm
    if v_out > v_source + Rout*Imaxsi_val then
      result := Imaxsi_val;
    elseif v_out < v_source - Rout*Imaxso_val then
      result := -Imaxso_val;
    else
      result := (v_out - v_source)/Rout;
    end if;
    return;
  end FCNiout_limit;

  function FCNq_sum_limit "Internal limitation function"
    extends Modelica.Icons.Function;
    input SI.Voltage q_sum;
    input SI.Voltage q_sum_ltf;
    input SI.Voltage v_pos;
    input SI.Voltage v_neg;
    input SI.Voltage vcp;
    input SI.Voltage vcm;
    output SI.Voltage result;

  algorithm
    if q_sum > v_pos - vcp and q_sum_ltf >= v_pos - vcp then
      result := v_pos - vcp;
    elseif q_sum < v_neg + vcm and q_sum_ltf <= v_neg + vcm then
      result := v_neg + vcm;
    else
      result := q_sum;
    end if;
    return;
  end FCNq_sum_limit;

initial equation
  v_source = q_fp1;
  x = 0;
equation
  assert(Rout > 0.0, "Rout must be > 0.0.");

  // power supply
  v_pos = p_supply.v;
  v_neg = m_supply.v;

  // input stage
  p.i = i_vos;
  m.i = i_4 - i_r2 - i_c3;
  0 = i_3 + i_r2 + i_c3 - i_vos;
  p.v - m.v = v_vos + v_in;
  v_4 = m.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
  // Laplace transformation
  der(q_fr1) = 2.0*pi*fp2*(v_in - q_fr1);
  q_fr2 + (1.0/(2.0*pi*fp3))*der(q_fr2) = q_fr1 + (1.0/(2.0*pi*fz))*der(q_fr1);
  der(q_fr3) = 2.0*pi*fp4*(q_fr2 - q_fr3);

  // gain stage
  // Laplace transformation
  q_sum = Avd0_val*q_fr3 + Avcm_val*(v_3 + v_4);
  q_sum_help = FCNq_sum_limit(
      q_sum,
      q_fp1,
      v_pos,
      v_neg,
      vcp_abs,
      vcm_abs);
  der(q_fp1) = 2.0*pi*fp1*(q_sum_help - q_fp1);

  // slew rate stage
  der(x) = (q_fp1 - v_source)/Ts;
  der(v_source) = smooth(0, noEvent(if der(x) > sr_p_val then sr_p_val else
    if der(x) < sr_m_val then sr_m_val else der(x)));

  // output stage
  v_out = outp.v;
  i_out = outp.i;
  i_out = FCNiout_limit(
      v_source,
      v_out,
      Rout,
      Imaxsi_val,
      Imaxso_val);

  p_supply.i = 0;
  m_supply.i = 0;
end OpAmpDetailed;


Basic electrical components

within Modelica.Electrical.Analog;
package Basic "Basic electrical components"

  extends Modelica.Icons.Package;
end Basic;


Adjustable resistor. This models a potentiometer where the sliding contact is placed between pin_n (r = 0) and pin_p (r = 1), dependent on either the parameter rConstant or the signal input r.

within Modelica.Electrical.Analog.Basic;
model Potentiometer "Adjustable resistor"
  parameter SI.Resistance R(start=1)
    "Resistance at temperature T_ref";
  parameter SI.Temperature T_ref=293.15 "Reference temperature";
  parameter SI.LinearTemperatureCoefficient alpha=0
    "Temperature coefficient of resistance (R_actual = R*(1 + alpha*(T_heatPort - T_ref))";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=T_ref);
  parameter Boolean useRinput=false "Use input for 0<r<1 (else constant)"
  parameter Real rConstant(
    final min=0,
    final max=1) = 0.5 "Contact between n (r=0) and p (r=1)"
  SI.Resistance Rp
    "Actual resistance between pin_p and contact";
  SI.Resistance Rn
    "Actual resistance between contact and pin_n";
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_p
  Modelica.Electrical.Analog.Interfaces.PositivePin contact
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_n
  Modelica.Blocks.Interfaces.RealInput r if useRinput
protected
  Modelica.Blocks.Sources.Constant rConst(final k=rConstant) if not useRinput
  Modelica.Blocks.Interfaces.RealInput rInt
equation
  pin_p.i + pin_n.i + contact.i = 0;
  Rp = R*(1 + alpha*(T_heatPort - T_ref))*(1 - min(1, max(0, rInt)));
  Rn = R*(1 + alpha*(T_heatPort - T_ref))*min(1, max(0, rInt));
  pin_p.v - contact.v = Rp*pin_p.i;
  pin_n.v - contact.v = Rn*pin_n.i;
  LossPower = (pin_p.v - contact.v)*pin_p.i + (pin_n.v - contact.v)*pin_n.i;
  connect(rInt, r)
  connect(rInt, rConst.y)
end Potentiometer;


Ideal linear electrical resistor. The linear resistor connects the branch voltage v with the branch current i by i*R = v. The Resistance R is allowed to be positive, zero, or negative.

within Modelica.Electrical.Analog.Basic;
model Resistor "Ideal linear electrical resistor"
  parameter SI.Resistance R(start=1)
    "Resistance at temperature T_ref";
  parameter SI.Temperature T_ref=300.15 "Reference temperature";
  parameter SI.LinearTemperatureCoefficient alpha=0
    "Temperature coefficient of resistance (R_actual = R*(1 + alpha*(T_heatPort - T_ref))";

  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=T_ref);
  SI.Resistance R_actual
    "Actual resistance = R*(1 + alpha*(T_heatPort - T_ref))";

equation
  assert((1 + alpha*(T_heatPort - T_ref)) >= Modelica.Constants.eps,
    "Temperature outside scope of model!");
  R_actual = R*(1 + alpha*(T_heatPort - T_ref));
  v = R_actual*i;
  LossPower = v*i;
end Resistor;


Electromotoric force (electric/mechanic transformer). EMF transforms electrical energy into rotational mechanical energy. It is used as basic building block of an electrical motor. The mechanical connector flange can be connected to elements of the Modelica.Mechanics.Rotational library. flange.tau is the cut-torque, flange.phi is the angle at the rotational connection.

within Modelica.Electrical.Analog.Basic;
model RotationalEMF "Electromotoric force (electric/mechanic transformer)"
  parameter Boolean useSupport=false
    "= true, if support flange enabled, otherwise implicitly grounded"
  parameter SI.ElectricalTorqueConstant k(start=1)
    "Transformation coefficient";
  SI.Voltage v "Voltage drop between the two pins";
  SI.Current i "Current flowing from positive to negative pin";
  SI.Angle phi
    "Angle of shaft flange with respect to support (= flange.phi - support.phi)";
  SI.AngularVelocity w "Angular velocity of flange relative to support";
  SI.Torque tau "Torque of flange";
  SI.Torque tauElectrical "Electrical torque";
  Interfaces.PositivePin p "Positive electrical pin"
  Interfaces.NegativePin n "Negative electrical pin"
  Modelica.Mechanics.Rotational.Interfaces.Flange_b flange "Flange"
  Mechanics.Rotational.Interfaces.Support support if useSupport
    "Support/housing of emf shaft"
protected
  Mechanics.Rotational.Components.Fixed fixed if not useSupport
  Mechanics.Rotational.Interfaces.InternalSupport internalSupport(tau=-tau) "Internal support"
equation
  v = p.v - n.v;
  0 = p.i + n.i;
  i = p.i;

  phi = flange.phi - internalSupport.phi;
  w = der(phi);
  k*w = v;
  tau = -k*i;
  tauElectrical = -tau;
  tau = flange.tau;

  connect(internalSupport.flange, support)
  connect(internalSupport.flange, fixed.flange)
end RotationalEMF;


Simple model of an inductor with saturation. This model approximates the behaviour of an inductor with the influence of saturation, i.e.,
the value of the inductance depends on the current flowing through the inductor (Fig. 1).
The inductance decreases as current increases. Note, that hysteresis is not taken into account.

within Modelica.Electrical.Analog.Basic;
model SaturatingInductor "Simple model of an inductor with saturation"
  extends Modelica.Electrical.Analog.Interfaces.OnePort(i(start=0));
  import Modelica.Constants.pi;
  import Modelica.Constants.eps;
  import Modelica.Constants.small;
  import Modelica.Math.atan;
  parameter SI.Current Inom(start=1) "Nominal current"
  parameter SI.Inductance Lnom(start=1)
    "Nominal inductance at Nominal current";
  parameter SI.Inductance Lzer(start=2*Lnom)
    "Inductance near current=0";
  parameter SI.Inductance Linf(start=Lnom/2)
    "Inductance at large currents";
  SI.Inductance Lact(start=Lzer) "Present inductance";
  SI.MagneticFlux Psi "Present flux";
protected
  parameter SI.Current Ipar(start=Inom/10, fixed=false);
initial equation
  (Lnom - Linf)/(Lzer - Linf)=Ipar/Inom*(pi/2 - atan(Ipar/Inom));
equation
  assert(Lzer > Lnom*(1 + eps), "Lzer (= " + String(Lzer) +
    ") has to be > Lnom (= " + String(Lnom) + ")");
  assert(Linf < Lnom*(1 - eps), "Linf (= " + String(Linf) +
    ") has to be < Lnom (= " + String(Lnom) + ")");
  Lact = Linf + (Lzer - Linf)*(if noEvent(abs(i)/Ipar<small) then 1 else atan(i/Ipar)/(i/Ipar));
  Psi = Linf*i + (Lzer - Linf)*Ipar*atan(i/Ipar);
  v = der(Psi);
end SaturatingInductor;


Transformer with two ports. The transformer is a two port. The left port voltage v1, left port current i1, right port voltage v2 and right port current i2 are connected by the following relation:

within Modelica.Electrical.Analog.Basic;
model Transformer "Transformer with two ports"
  extends Interfaces.TwoPort(i1(start=0),i2(start=0));
  parameter SI.Inductance L1(start=1) "Primary inductance";
  parameter SI.Inductance L2(start=1) "Secondary inductance";
  parameter SI.Inductance M(start=1) "Coupling inductance";
  Real dv "Difference between voltage drop over primary inductor and voltage drop over secondary inductor";
equation
  v1 = L1*der(i1) + M*der(i2);

  /* Original equation:
        v2 = M*der(i1) + L2*der(i2);
     If L1 = L2 = M, then this model has one state less. However,
     it might be difficult for a tool to detect this. For this reason
     the model is defined with a relative potential:
  */
  dv = (L1 - M)*der(i1) + (M - L2)*der(i2);
  v2 = v1 - dv;
end Transformer;


Electromotoric force (electric/mechanic transformer). EMF transforms electrical energy into translational mechanical energy. It is used as basic building block of an electrical linear motor. The mechanical connector flange can be connected to elements of the Modelica.Mechanics.Translational library. flange.f is the cut-force, flange.s is the distance at the translational connection.

within Modelica.Electrical.Analog.Basic;
model TranslationalEMF "Electromotoric force (electric/mechanic transformer)"
  parameter Boolean useSupport=false
    "= true, if support flange enabled, otherwise implicitly grounded"
  parameter SI.ElectricalForceConstant k(start=1)
    "Transformation coefficient";

  SI.Voltage v "Voltage drop between the two pins";
  SI.Current i "Current flowing from positive to negative pin";
  SI.Position s "Position of flange relative to support";
  SI.Velocity vel "Velocity of flange relative to support";
  SI.Force f "Force of flange";
  SI.Force fElectrical "Electrical force";

  Modelica.Electrical.Analog.Interfaces.PositivePin p "Positive electrical pin"
  Modelica.Electrical.Analog.Interfaces.NegativePin n "Negative electrical pin"
  Modelica.Mechanics.Translational.Interfaces.Flange_b flange "Flange"
  Modelica.Mechanics.Translational.Interfaces.Support support if useSupport
    "Support/housing"
protected
  Modelica.Mechanics.Translational.Components.Fixed fixed if not useSupport
  Modelica.Mechanics.Translational.Interfaces.InternalSupport internalSupport(f=-f) "Internal support"
equation
  v = p.v - n.v;
  0 = p.i + n.i;
  i = p.i;

  s = flange.s - internalSupport.s;
  vel = der(s);
  k*vel = v;
  f = -k*i;
  fElectrical = -f;
  f = flange.f;

  connect(internalSupport.flange, support)
  connect(internalSupport.flange, fixed.flange)
end TranslationalEMF;


Ideal linear electrical capacitor with variable capacitance. The linear capacitor connects the branch voltage v with the branch current i by

i = dQ/dt with Q = C * v.

The capacitance C is given as input signal.
It is required that C ≥ 0, otherwise an assertion is raised. To avoid a variable index system,
C = Cmin, if 0 ≤ C < Cmin, where Cmin is a parameter with default value Modelica.Constants.eps.

within Modelica.Electrical.Analog.Basic;
model VariableCapacitor
  "Ideal linear electrical capacitor with variable capacitance"
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  Modelica.Blocks.Interfaces.RealInput C(unit="F")
  parameter SI.Capacitance Cmin=Modelica.Constants.eps
    "Lower bound for variable capacitance";
  SI.ElectricCharge Q;
  parameter SI.Voltage IC=0 "Initial Value";
  parameter Boolean UIC=false "Decision if initial value IC shall be used";
initial equation
  if UIC then
    v = IC;
  end if;
equation
  assert(C >= 0, "Capacitance C (= " + String(C) + ") has to be >= 0!");
  // protect solver from index change
  Q = noEvent(max(C, Cmin))*v;
  i = der(Q);
end VariableCapacitor;


Ideal linear electrical conductor with variable conductance. The linear conductor connects the branch voltage v with the branch current i by

i = G*v

The Conductance G is given as input signal.

Attention!!!

It is recommended that the G signal should not cross the zero value. Otherwise depending on the surrounding circuit the probability of singularities is high.

within Modelica.Electrical.Analog.Basic;
model VariableConductor
  "Ideal linear electrical conductor with variable conductance"
  parameter SI.Temperature T_ref=300.15 "Reference temperature";
  parameter SI.LinearTemperatureCoefficient alpha=0
    "Temperature coefficient of conductance (G_actual = G/(1 + alpha*(T_heatPort - T_ref))";
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=T_ref);
  SI.Conductance G_actual
    "Actual conductance = G/(1 + alpha*(T_heatPort - T_ref))";
  Modelica.Blocks.Interfaces.RealInput G(unit="S")
equation
  assert((1 + alpha*(T_heatPort - T_ref)) >= Modelica.Constants.eps,
    "Temperature outside scope of model!");
  G_actual = G/(1 + alpha*(T_heatPort - T_ref));
  i = G_actual*v;
  LossPower = v*i;
end VariableConductor;


Ideal linear electrical inductor with variable inductance. The linear inductor connects the branch voltage v with the branch current i by

v = d Psi/dt with Psi = L * i .

The inductance L is as input signal.
It is required that L ≥ 0, otherwise an assertion is raised. To avoid a variable index system, L = Lmin, if 0 ≤ L < Lmin, where Lmin is a parameter with default value Modelica.Constants.eps.

within Modelica.Electrical.Analog.Basic;
model VariableInductor
  "Ideal linear electrical inductor with variable inductance"
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  Modelica.Blocks.Interfaces.RealInput L(unit="H")
  SI.MagneticFlux Psi;
  parameter SI.Inductance Lmin=Modelica.Constants.eps
    "Lower bound for variable inductance";
  parameter SI.Current IC=0 "Initial Value";
  parameter Boolean UIC=false "Decision if initial value IC shall be used";
initial equation
  if UIC then
    i = IC;
  end if;
equation
  assert(L >= 0, "Inductance L_ (= " + String(L) + ") has to be >= 0!");
  // protect solver from index change
  Psi = noEvent(max(L, Lmin))*i;
  v = der(Psi);
end VariableInductor;


Ideal linear electrical resistor with variable resistance. The linear resistor connects the branch voltage v with the branch current i by

i*R = v

The Resistance R is given as input signal.

Attention!!!
It is recommended that the R signal should not cross the zero value. Otherwise depending on the surrounding circuit the probability of singularities is high.

within Modelica.Electrical.Analog.Basic;
model VariableResistor
  "Ideal linear electrical resistor with variable resistance"
  parameter SI.Temperature T_ref=300.15 "Reference temperature";
  parameter SI.LinearTemperatureCoefficient alpha=0
    "Temperature coefficient of resistance (R_actual = R*(1 + alpha*(T_heatPort - T_ref))";
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=T_ref);
  SI.Resistance R_actual
    "Actual resistance = R*(1 + alpha*(T_heatPort - T_ref))";
  Modelica.Blocks.Interfaces.RealInput R(unit="Ohm")
equation
  assert((1 + alpha*(T_heatPort - T_ref)) >= Modelica.Constants.eps,
    "Temperature outside scope of model!");
  R_actual = R*(1 + alpha*(T_heatPort - T_ref));
  v = R_actual*i;
  LossPower = v*i;
end VariableResistor;


Linear voltage-controlled current source. The linear voltage-controlled current source is a TwoPort. The right port current i2 is controlled by the left port voltage v1 via

within Modelica.Electrical.Analog.Basic;
model VCC "Linear voltage-controlled current source"
  extends Interfaces.TwoPort;
  parameter SI.Conductance transConductance(start=1) "Transconductance";
equation
  i2 = v1*transConductance;
  i1 = 0;
end VCC;


Linear voltage-controlled voltage source. The linear voltage-controlled voltage source is a TwoPort. The right port voltage v2 is controlled by the left port voltage v1 via

within Modelica.Electrical.Analog.Basic;
model VCV "Linear voltage-controlled voltage source"
  extends Interfaces.TwoPort;
  parameter Real gain(start=1) "Voltage gain";

equation
  v2 = v1*gain;
  i1 = 0;
end VCV;


Conversion circuit. The simple converter circuit converts an analog sine signal into a N-bit (by default a 4 bit) logic signal, which is converted backward into an analog signal.

within Modelica.Electrical.Analog.Examples;
model AD_DA_conversion "Conversion circuit"
  extends Modelica.Icons.Example;
  parameter Integer N=7 "Digital signal width";
  Modelica.Electrical.Analog.Ideal.AD_Converter aD_Converter(N=N,
    Rin=1000000,
    VRefLow=0,
    VRefHigh=10)
  Modelica.Electrical.Digital.Sources.Pulse pulse(
    pulse=Modelica.Electrical.Digital.Interfaces.Logic.'1',
    quiet=Modelica.Electrical.Digital.Interfaces.Logic.'0',
    nperiod=-1,
    width=1,
    period=0.001,
    startTime=0)
  Modelica.Electrical.Analog.Ideal.DA_Converter dA_Converter(N=N, Vref=10)
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Sources.SineVoltage sineVoltage(
    V=5,
    f=10,
    offset=5)
  Modelica.Electrical.Analog.Basic.Resistor resistor(R=1)
equation
  connect(pulse.y, aD_Converter.trig)
  connect(sineVoltage.p, aD_Converter.p)
  connect(sineVoltage.n, aD_Converter.n)
  connect(ground.p, sineVoltage.n)
  connect(sineVoltage.p, resistor.p)
  connect(dA_Converter.trig, pulse.y)
  connect(aD_Converter.y, dA_Converter.x)
  connect(dA_Converter.p, resistor.n)
  connect(dA_Converter.n, ground.p)
end AD_DA_conversion;


Simple Amplifier circuit which uses OpAmpDetailed. With the test circuit AmplifierWithOpAmpDetailed a time domain analysis of the example arrangement with a sinusoidal input voltage (12 V amplitude, frequency 1 kHz) using the operational amplifier model OpAmpDetailed is carried out. The working voltages are 15 V and -15 V.

within Modelica.Electrical.Analog.Examples;
model AmplifierWithOpAmpDetailed
  "Simple Amplifier circuit which uses OpAmpDetailed"
  extends Modelica.Icons.Example;

  Modelica.Electrical.Analog.Basic.OpAmpDetailed opAmp
  Modelica.Electrical.Analog.Basic.Resistor resistor(R=10000)
  Modelica.Electrical.Analog.Basic.Resistor resistor1(R=20000)
  Modelica.Electrical.Analog.Basic.Resistor resistor2(R=10000)
  Modelica.Electrical.Analog.Sources.SineVoltage sineVoltage(V=12, f=1000)
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage(V=15)
  Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage1(V=-15)
initial equation
  resistor2.i = 0;
  opAmp.q_fp1 = 0;
  opAmp.q_fr1 = 0;
  opAmp.q_fr2 = 0;
  opAmp.q_fr3 = 0;

equation
  connect(resistor.n, opAmp.m)
  connect(resistor1.n, resistor2.p)
  connect(resistor.p, sineVoltage.p)
  connect(resistor1.p, opAmp.m)
  connect(sineVoltage.n, ground.p)
  connect(opAmp.p, ground.p)
  connect(resistor2.n, ground.p)
  connect(opAmp.p_supply, constantVoltage.p)
  connect(opAmp.m_supply, constantVoltage1.p)
  connect(constantVoltage.n, constantVoltage1.n)
  connect(constantVoltage1.n, ground.p)
  connect(opAmp.outp, resistor2.p)
end AmplifierWithOpAmpDetailed;


Cauer low pass filter with analog components. The example Cauer Filter is a low-pass-filter of the fifth order. It is realized using an analog network. The voltage source V is the input voltage (step), and the R2.p.v is the filter output voltage. The pulse response is calculated.

within Modelica.Electrical.Analog.Examples;
model CauerLowPassAnalog "Cauer low pass filter with analog components"
  extends Modelica.Icons.Example;

  parameter SI.Inductance l1=1.304 "Filter coefficient I1";
  parameter SI.Inductance l2=0.8586 "Filter coefficient I2";
  parameter SI.Capacitance c1=1.072 "Filter coefficient c1";
  parameter SI.Capacitance c2=1/(1.704992^2*l1)
    "Filter coefficient c2";
  parameter SI.Capacitance c3=1.682 "Filter coefficient c3";
  parameter SI.Capacitance c4=1/(1.179945^2*l2)
    "Filter coefficient c4";
  parameter SI.Capacitance c5=0.7262 "Filter coefficient c5";
  Modelica.Electrical.Analog.Basic.Ground G
  Modelica.Electrical.Analog.Basic.Capacitor C1(C=c1, v(start=0, fixed=true))

Modelica.Electrical.Analog.Basic.Capacitor C2(C=c2)
  Modelica.Electrical.Analog.Basic.Capacitor C3(C=c3,v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C4(C=c4)
  Modelica.Electrical.Analog.Basic.Capacitor C5(C=c5,v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Inductor L1(L=l1,i(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Inductor L2(L=l2,i(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Resistor R1(R=1)
  Modelica.Electrical.Analog.Basic.Resistor R2(R=1)
  Modelica.Electrical.Analog.Sources.StepVoltage V(startTime=1, offset=0,
    V=1)
equation
  connect(R1.n,C1.p)
  connect(C1.n,G.p)
  connect(L1.p,C2.p)
  connect(L1.p,C1.p)
  connect(L1.n,C2.n)
  connect(C2.n,C3.p)
  connect(C2.n,C4.p)
  connect(C2.n,L2.p)
  connect(L2.n,C4.n)
  connect(C4.n,C5.p)
  connect(C4.n,R2.p)
  connect(C1.n,C3.n)
  connect(C1.n,C5.n)
  connect(R2.n,C1.n)
  connect(R1.p,V.p)
  connect(V.n,G.p)
end CauerLowPassAnalog;


Cauer low pass filter with operational amplifiers. The example Cauer Filter is a low-pass-filter of the fifth order. It is realized using an analog network with operational amplifiers. The voltage source V is the input voltage (step), and the OP5.out.v is the filter output voltage. The pulse response is calculated.

within Modelica.Electrical.Analog.Examples;
model CauerLowPassOPV "Cauer low pass filter with operational amplifiers"
  extends Modelica.Icons.Example;

  parameter SI.Capacitance l1=1.304 "Filter coefficient i1";
  parameter SI.Capacitance l2=0.8586 "Filter coefficient i2";
  parameter SI.Capacitance c1=1.072 "Filter coefficient c1";
  parameter SI.Capacitance c2=1/(1.704992^2*l1)
    "Filter coefficient c2";
  parameter SI.Capacitance c3=1.682 "Filter coefficient c3";
  parameter SI.Capacitance c4=1/(1.179945^2*l2)
    "Filter coefficient c4";
  parameter SI.Capacitance c5=0.7262 "Filter coefficient c5";
  Modelica.Electrical.Analog.Basic.Capacitor C1(C=c1 + c2, v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C2(C=c2, v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C3(C=l1, v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C4(C=c4, v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C5(C=c2)
  Modelica.Electrical.Analog.Basic.Resistor R1(R=1)
  Modelica.Electrical.Analog.Basic.Resistor R2(R=1)
  Modelica.Electrical.Analog.Basic.Resistor R3(R=1)
  Modelica.Electrical.Analog.Ideal.IdealOpAmp3Pin Op1
  Modelica.Electrical.Analog.Basic.Ground G
  Modelica.Electrical.Analog.Basic.Resistor R4(R=-1)
  Modelica.Electrical.Analog.Basic.Resistor R5(R=-1)
  Modelica.Electrical.Analog.Ideal.IdealOpAmp3Pin Op2
  Modelica.Electrical.Analog.Ideal.IdealOpAmp3Pin Op3
  Modelica.Electrical.Analog.Basic.Ground G1
  Modelica.Electrical.Analog.Basic.Resistor R6(R=1)
  Modelica.Electrical.Analog.Basic.Resistor R7(R=1)
  Modelica.Electrical.Analog.Basic.Capacitor C6(C=c2 + c3 + c4)
  Modelica.Electrical.Analog.Basic.Resistor R8(R=-1)
  Modelica.Electrical.Analog.Basic.Resistor R9(R=-1)
  Modelica.Electrical.Analog.Basic.Resistor R10(R=1)
  Modelica.Electrical.Analog.Ideal.IdealOpAmp3Pin Op4
  Modelica.Electrical.Analog.Ideal.IdealOpAmp3Pin Op5
  Modelica.Electrical.Analog.Basic.Capacitor C7(C=l2, v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C8(C=c4)
  Modelica.Electrical.Analog.Basic.Capacitor C9(C=c4 + c5)
  Modelica.Electrical.Analog.Basic.Resistor R11(R=1)
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n1
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n2
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n3
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n4
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n5
protected
  Modelica.Electrical.Analog.Interfaces.PositivePin p1
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n6
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n7
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n8
protected
  Modelica.Electrical.Analog.Interfaces.PositivePin p2
protected
  Modelica.Electrical.Analog.Interfaces.PositivePin out1
protected
  Modelica.Electrical.Analog.Interfaces.PositivePin p3
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n9
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n10
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n11
public
  Modelica.Electrical.Analog.Basic.Ground G2
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n12
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n13
protected
  Modelica.Electrical.Analog.Interfaces.PositivePin p4
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n14
public
  Modelica.Electrical.Analog.Basic.Ground G3
  Modelica.Electrical.Analog.Basic.Ground G4
  Modelica.Electrical.Analog.Sources.StepVoltage V(startTime=1, V=1)
  Modelica.Electrical.Analog.Basic.Ground Ground1
equation
  connect(Op1.in_p, G.p)
  connect(G1.p, Op2.in_p)
  connect(R1.n, n1)
  connect(n1, Op1.in_n)
  connect(C2.n, n1)
  connect(R2.n, n2)
  connect(n1, n2)
  connect(n2, n3)
  connect(n3, C1.p)
  connect(n3, R3.p)
  connect(C1.n, n4)
  connect(R3.n, n4)
  connect(n4, Op1.out)
  connect(R4.p, Op1.out)
  connect(C5.p, Op1.out)
  connect(R4.n, n5)
  connect(n5, Op2.in_n)
  connect(C3.p, n5)
  connect(R5.n, n5)
  connect(R5.p, p1)
  connect(C2.p, p1)
  connect(C3.n, n6)
  connect(n6, Op2.out)
  connect(R2.p, n6)
  connect(Op2.out, R7.p)
  connect(R7.n, n7)
  connect(n7, Op3.in_n)
  connect(C5.n, n7)
  connect(R6.n, n8)
  connect(n7, n8)
  connect(C6.p, p2)
  connect(n8, p2)
  connect(C4.n, p2)
  connect(C6.n, Op3.out)
  connect(R9.p, Op3.out)
  connect(Op3.out, out1)
  connect(p1, out1)
  connect(out1, C8.p)
  connect(C4.p, p3)
  connect(p3, R8.p)
  connect(R8.n, n9)
  connect(n9, n10)
  connect(R9.n, n10)
  connect(n10, Op4.in_n)
  connect(n9, C7.p)
  connect(C7.n, n11)
  connect(R6.p, n11)
  connect(n11, Op4.out)
  connect(Op4.out, R10.p)
  connect(G2.p, Op3.in_p)
  connect(R11.n, n12)
  connect(p3, n12)
  connect(C9.n, n13)
  connect(n12, n13)
  connect(n13, Op5.out)
  connect(C9.p, p4)
  connect(R11.p, p4)
  connect(R10.n, n14)
  connect(p4, n14)
  connect(Op5.in_n, n14)
  connect(C8.n, n14)
  connect(Op4.in_p, G3.p)
  connect(Op5.in_p, G4.p)
  connect(V.p, Ground1.p)
  connect(V.n, R1.p)
end CauerLowPassOPV;


Cauer low-pass filter with operational amplifiers and switched capacitors. The example CauerLowPassSC is a low-pass-filter of the fifth order. It is realized using an switched-capacitor network with operational amplifiers. The voltage source V is the input voltage (step), and the OP5.out.v is the filter output voltage. The pulse response is calculated.

within Modelica.Electrical.Analog.Examples;
model CauerLowPassSC "Cauer low-pass filter with operational amplifiers and switched capacitors"
  extends Modelica.Icons.Example;

  parameter SI.Capacitance l1=1.304 "Filter coefficient i1";
  parameter SI.Capacitance l2=0.8586 "Filter coefficient i2";
  parameter SI.Capacitance c1=1.072 "Filter coefficient c1";
  parameter SI.Capacitance c2=1/(1.704992^2*l1)
    "Filter coefficient c2";
  parameter SI.Capacitance c3=1.682 "Filter coefficient c3";
  parameter SI.Capacitance c4=1/(1.179945^2*l2)
    "Filter coefficient c4";
  parameter SI.Capacitance c5=0.7262 "Filter coefficient c5";
  Modelica.Electrical.Analog.Basic.Capacitor C1(C=c1 + c2,v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C2(C=c2,v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C3(C=l1,v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C4(C=c4,v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C5(C=c2)
  Modelica.Electrical.Analog.Ideal.IdealOpAmp3Pin Op1
  Modelica.Electrical.Analog.Basic.Ground G
  Modelica.Electrical.Analog.Ideal.IdealOpAmp3Pin Op2
  Modelica.Electrical.Analog.Ideal.IdealOpAmp3Pin Op3
  Modelica.Electrical.Analog.Basic.Ground G1
  Modelica.Electrical.Analog.Basic.Capacitor C6(C=c2 + c3 + c4)
  Modelica.Electrical.Analog.Ideal.IdealOpAmp3Pin Op4
  Modelica.Electrical.Analog.Ideal.IdealOpAmp3Pin Op5
  Modelica.Electrical.Analog.Basic.Capacitor C7(C=l2,v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C8(C=c4)
  Modelica.Electrical.Analog.Basic.Capacitor C9(C=c4 + c5)
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n1
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n2
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n3
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n4
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n5
protected
  Modelica.Electrical.Analog.Interfaces.PositivePin p1
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n6
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n7
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n8
protected
  Modelica.Electrical.Analog.Interfaces.PositivePin p2
protected
  Modelica.Electrical.Analog.Interfaces.PositivePin out1
protected
  Modelica.Electrical.Analog.Interfaces.PositivePin p3
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n9
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n10
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n11
public
  Modelica.Electrical.Analog.Basic.Ground G2
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n12
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n13
protected
  Modelica.Electrical.Analog.Interfaces.PositivePin p4
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n14
public
  Modelica.Electrical.Analog.Basic.Ground G3
  Modelica.Electrical.Analog.Basic.Ground G4
  Modelica.Electrical.Analog.Sources.StepVoltage V(startTime=1, V=1)
  Modelica.Electrical.Analog.Basic.Ground Ground1
  Modelica.Electrical.Analog.Examples.Utilities.SwitchedCapacitor R4(clock=0.1, R=-1, Capacitor(v(start=0, fixed=true)))
  Modelica.Electrical.Analog.Examples.Utilities.SwitchedCapacitor R5(clock=0.1, R=-1, Capacitor(v(start=0, fixed=true)))
  Modelica.Electrical.Analog.Examples.Utilities.SwitchedCapacitor R8(clock=0.1, R=-1, Capacitor(v(start=0, fixed=true)))
  Modelica.Electrical.Analog.Examples.Utilities.SwitchedCapacitor R9(clock=0.1, R=-1, Capacitor(v(start=0, fixed=true)))
  Modelica.Electrical.Analog.Examples.Utilities.SwitchedCapacitor R1(clock=0.1,
    R=1,                                                                        Capacitor(v(start=0, fixed=true)))
  Modelica.Electrical.Analog.Examples.Utilities.SwitchedCapacitor R2(clock=0.1,
    R=1,                                                                        Capacitor(v(start=0, fixed=true)))
  Modelica.Electrical.Analog.Examples.Utilities.SwitchedCapacitor R3(clock=0.1,
    R=1,                                                                        Capacitor(v(start=0, fixed=true)))
  Modelica.Electrical.Analog.Examples.Utilities.SwitchedCapacitor Rp1(clock=0.1,
    R=1,                                                                         Capacitor(v(start=0, fixed=true)))
  Modelica.Electrical.Analog.Examples.Utilities.SwitchedCapacitor R7(clock=0.1,
    R=1,                                                                        Capacitor(v(start=0, fixed=true)))
  Modelica.Electrical.Analog.Examples.Utilities.SwitchedCapacitor R10(clock=0.1,
    R=1,                                                                         Capacitor(v(start=0, fixed=true)))
  Modelica.Electrical.Analog.Examples.Utilities.SwitchedCapacitor R11(clock=0.1,
    R=1,                                                                         Capacitor(v(start=0, fixed=true)))
equation
  connect(Op1.in_p,G. p)
  connect(G1.p,Op2. in_p)
  connect(n1,Op1. in_n)
  connect(C2.n,n1)
  connect(n1,n2)
  connect(n2,n3)
  connect(n3,C1. p)
  connect(C1.n,n4)
  connect(n4,Op1. out)
  connect(C5.p,Op1. out)
  connect(n5,Op2. in_n)
  connect(C3.p,n5)
  connect(C2.p,p1)
  connect(C3.n,n6)
  connect(n6,Op2. out)
  connect(n7,Op3. in_n)
  connect(C5.n,n7)
  connect(n7,n8)
  connect(C6.p,p2)
  connect(n8,p2)
  connect(C4.n,p2)
  connect(C6.n,Op3. out)
  connect(Op3.out,out1)
  connect(p1,out1)
  connect(out1,C8. p)
  connect(C4.p,p3)
  connect(n9,n10)
  connect(n10,Op4. in_n)
  connect(n9,C7. p)
  connect(C7.n,n11)
  connect(n11,Op4. out)
  connect(G2.p,Op3. in_p)
  connect(p3,n12)
  connect(C9.n,n13)
  connect(n12,n13)
  connect(n13,Op5. out)
  connect(C9.p,p4)
  connect(p4,n14)
  connect(Op5.in_n,n14)
  connect(C8.n,n14)
  connect(Op4.in_p,G3. p)
  connect(Op5.in_p,G4. p)
  connect(V.p, Ground1.p)
  connect(R4.n, n5)
  connect(Op1.out, R4.p)
  connect(R5.p, p1)
  connect(R5.n, n5)
  connect(p3, R8.p)
  connect(R8.n, n9)
  connect(Op3.out, R9.p)
  connect(R9.n, n10)
  connect(R1.p, V.n)
  connect(R1.n, n1)
  connect(R2.n, n2)
  connect(R2.p, n6)
  connect(R3.p, n3)
  connect(R3.n, n4)
  connect(Rp1.n, n8)
  connect(Rp1.p, n11)
  connect(Op2.out, R7.p)
  connect(R7.n, n7)
  connect(R10.p, Op4.out)
  connect(R10.n, n14)
  connect(R11.n, n12)
  connect(R11.p, p4)
end CauerLowPassSC;


Characteristic of ideal diodes. Three examples of ideal diodes are shown:

the totally ideal diode (Ideal) with all parameters to be zero,
the nearly ideal diode with Ron=0.1 and Goff=0.1
 and the nearly ideal but displaced diode with Vknee=5 and Ron=0.1 and Goff=0.1.
The resistance and conductance are chosen atypically high since the slopes should be seen in the graphics.

within Modelica.Electrical.Analog.Examples;
model CharacteristicIdealDiodes "Characteristic of ideal diodes"
  extends Modelica.Icons.Example;

  Modelica.Electrical.Analog.Ideal.IdealDiode Ideal(
    Ron=0,
    Goff=0,
    Vknee=0)
  Modelica.Electrical.Analog.Ideal.IdealDiode With_Ron_Goff(
    Ron=0.1,
    Goff=0.1,
    Vknee=0)
  Modelica.Electrical.Analog.Ideal.IdealDiode With_Ron_Goff_Vknee(
    Ron=0.2,
    Goff=0.2,
    Vknee=5)
  Modelica.Electrical.Analog.Sources.SineVoltage SineVoltage1(
    V=10,
    offset=-9,
    f=1)
  Modelica.Electrical.Analog.Basic.Ground Ground1

  Modelica.Electrical.Analog.Basic.Resistor R1(R=1e-3)
  Modelica.Electrical.Analog.Basic.Resistor R2(R=1e-3)
  Modelica.Electrical.Analog.Basic.Resistor R3(R=1e-3)
  Modelica.Electrical.Analog.Sources.SineVoltage SineVoltage2(
    V=10,
    offset=0,
    f=1)
  Modelica.Electrical.Analog.Sources.SineVoltage SineVoltage3(
    V=10,
    offset=0,
    f=1)

equation
  connect(Ground1.p, SineVoltage1.n)
  connect(Ideal.n, R1.p)
  connect(With_Ron_Goff.n, R2.p)
  connect(With_Ron_Goff_Vknee.n, R3.p)
  connect(R1.n, R2.n)
  connect(R2.n, R3.n)
  connect(R3.n, Ground1.p)
  connect(SineVoltage2.p, Ideal.p)
  connect(SineVoltage2.n, Ground1.p)
  connect(SineVoltage1.p, With_Ron_Goff.p)
  connect(With_Ron_Goff_Vknee.p, SineVoltage3.p)
  connect(SineVoltage3.n, Ground1.p)
end CharacteristicIdealDiodes;


Characteristic of ideal thyristors. This example compares the behavior of the ideal thyristor and the ideal GTO thyristor with Vknee=1 both. The thyristors IdealThyristor1 and IdealGTOThyristor1 are controlled by an unregular Boolean fire signal. The aim is to show several cases for the fire signal in combination with the state (s<0 or s>0)of the thyristors. Please simulate until 6 seconds and compare IdealThyristor1.v with IdealGTOThyristor1.v, the same with IdealThyristor1.s and IdealGTOThyristor1.s (attention: s is a protected variable in each thyristor). Also compare IdealThyristor1.off and IdealGTOThyristor1.off and have a look at the fire signal (e.g. IdealThyristor1.fire). It can be seen that the IdealGTOThyristor1 reacts on switching off the fire signal whereas the IdealThyristor1 does not show this behavior.

within Modelica.Electrical.Analog.Examples;
model CharacteristicThyristors "Characteristic of ideal thyristors"

  extends Modelica.Icons.Example;

  Modelica.Electrical.Analog.Ideal.IdealThyristor IdealThyristor1(
                             off(start=true, fixed= true), Vknee=1)
  Modelica.Electrical.Analog.Sources.SineVoltage SineVoltage1(V=10,
      offset=0,
    f=1)
  Modelica.Electrical.Analog.Basic.Ground Ground1
  Modelica.Electrical.Analog.Basic.Resistor R3(R=1e-3)

  Modelica.Electrical.Analog.Ideal.IdealGTOThyristor IdealGTOThyristor1(
                                off(fixed=true, start=true), Vknee=1)
  Modelica.Electrical.Analog.Basic.Resistor R1(R=1e-3)

  Blocks.Sources.BooleanTable booleanStep1(table={1.25,3.2,4.2,4.25,5.7,5.72})
  Modelica.Electrical.Analog.Ideal.IdealThyristor IdealThyristor2(
                             off(start=true, fixed= true), Vknee=1)
  Modelica.Electrical.Analog.Basic.Resistor R2(R=1e-3)
  Modelica.Electrical.Analog.Ideal.IdealGTOThyristor IdealGTOThyristor2(
                                off(fixed=true, start=true), Vknee=1)
  Modelica.Electrical.Analog.Basic.Resistor R4(R=1e-3)
  Blocks.Sources.BooleanPulse booleanPulse(
    width=20,
    period=1,
    startTime=0.15)
initial equation
 // IdealThyristor1.off = true;

equation
  connect(IdealThyristor1.n, R3.p)
  connect(Ground1.p, SineVoltage1.n)
  connect(SineVoltage1.p, IdealThyristor1.p)
  connect(IdealGTOThyristor1.n, R1.p)
  connect(R3.n, R1.n)
  connect(IdealGTOThyristor1.p, IdealThyristor1.p)
  connect(IdealGTOThyristor1.fire, IdealThyristor1.fire)
  connect(IdealThyristor1.fire, booleanStep1.y)
  connect(IdealThyristor2.n,R2. p)
  connect(IdealGTOThyristor2.n,R4. p)
  connect(R2.n,R4. n)
  connect(IdealGTOThyristor2.p,IdealThyristor2. p)
  connect(IdealGTOThyristor2.fire,IdealThyristor2. fire)
  connect(R4.n, Ground1.p)
  connect(R2.n, R1.n)
  connect(SineVoltage1.p, IdealThyristor2.p)
  connect(booleanPulse.y, IdealThyristor2.fire)
end CharacteristicThyristors;


Chua's circuit, ns, V, A. Chua's circuit is the most simple nonlinear circuit which shows chaotic behaviour. The circuit consists of linear basic elements (capacitors, resistor, conductor, inductor), and one nonlinear element, which is called Chua's diode. The chaotic behaviour is simulated.

within Modelica.Electrical.Analog.Examples;
model ChuaCircuit "Chua's circuit, ns, V, A"
  extends Modelica.Icons.Example;

  Modelica.Electrical.Analog.Basic.Inductor L(L=18, i(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Resistor Ro(R=12.5e-3)
  Modelica.Electrical.Analog.Basic.Conductor G(G=0.565)
  Modelica.Electrical.Analog.Basic.Capacitor C1(C=10, v(start=4, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C2(C=100, v(start=0, fixed=true))
  Modelica.Electrical.Analog.Examples.Utilities.NonlinearResistor Nr(
    Ga(min=-1) = -0.757576,
    Gb(min=-1) = -0.409091,
    Ve=1)
  Modelica.Electrical.Analog.Basic.Ground Gnd
equation
  connect(L.n, Ro.p)
  connect(C2.p, G.p)
  connect(L.p, G.p)
  connect(G.n, Nr.p)
  connect(C1.p, G.n)
  connect(Ro.n, Gnd.p)
  connect(C2.n, Gnd.p)
  connect(Gnd.p, C1.n)
  connect(Gnd.p, Nr.n)
end ChuaCircuit;


Transformer circuit to show the magnetization facilities. This example is to demonstrate the behaviour of transformer models. The Basic.Transformer, which consists of mutual coupled inductors, is compared with the ideal transformer model. If the ideal model is used with considerMagnetization=true leakage inductances are taken into account, otherwise not.
The example is constructed in such a way that the ideal transformer circuit with considerMagnetization=true shows the same behaviour as the basic transformer.

within Modelica.Electrical.Analog.Examples;
model CompareTransformers
  "Transformer circuit to show the magnetization facilities"
  import Modelica.Constants.pi;
  extends Modelica.Icons.Example;
  parameter SI.Voltage Vdc=0.1 "DC offset of voltage source";
  parameter SI.Voltage Vpeak=0.1 "Peak voltage of voltage source";
  parameter SI.Frequency f=10 "Frequency of voltage source";
  parameter SI.Angle phi0=pi/2 "Phase of voltage source";
  parameter Real n=2 "Turns ratio primary:secondary voltage";
  parameter SI.Resistance R1=0.01
    "Primary resistance w.r.t. primary side";
  parameter SI.Inductance L1sigma=0.05/(2*pi*f)
    "Primary leakage inductance w.r.t. primary side";
  parameter SI.Inductance Lm1= 10./(2*pi*f)
    "Magnetizing inductance w.r.t. primary side";
  parameter SI.Inductance L2sigma=0.05/(2*pi*f)/n^2
    "Secondary leakage inductance w.r.t. secondary side";
  parameter SI.Resistance R2=0.01/n^2
    "Secondary resistance w.r.t. secondary side";
  parameter SI.Resistance RL=1/n^2 "Load resistance";
  final parameter SI.Inductance L1=L1sigma + M*n
    "Primary no-load inductance";
  final parameter SI.Inductance L2=L2sigma + M/n
    "Secondary no-load inductance";
  final parameter SI.Inductance M=Lm1/n "Mutual inductance";
  output SI.Voltage v1B = resistor11.n.v
    "Primary voltage, basic transformer";
  output SI.Current i1B = resistor11.i
    "Primary current, basic transformer";
  output SI.Voltage v2B = resistor12.p.v
    "Secondary voltage, basic transformer";
  output SI.Current i2B = resistor12.i
    "Secondary current, basic transformer";
  output SI.Voltage v1I = resistor21.n.v
    "Primary voltage, basic transformer";
  output SI.Current i1I = resistor21.i
    "Primary current, basic transformer";
  output SI.Voltage v2I = resistor22.p.v
    "Secondary voltage, basic transformer";
  output SI.Current i2I = resistor22.i
    "Secondary current, basic transformer";
  Modelica.Electrical.Analog.Sources.SineVoltage sineVoltage1(
    V=Vpeak,
    phase=phi0,
    f=f,
    offset=Vdc)
  Modelica.Electrical.Analog.Basic.Ground ground11
  Modelica.Electrical.Analog.Basic.Resistor resistor11(R=R1)
  Modelica.Electrical.Analog.Basic.Resistor resistor12(R=R2)
  Modelica.Electrical.Analog.Basic.Resistor load1(R=RL)
  Modelica.Electrical.Analog.Basic.Ground ground12
  Modelica.Electrical.Analog.Sources.SineVoltage sineVoltage2(
    V=Vpeak,
    phase=phi0,
    f=f,
    offset=Vdc)
  Modelica.Electrical.Analog.Basic.Ground ground21
  Modelica.Electrical.Analog.Basic.Resistor resistor21(R=R1)
  Modelica.Electrical.Analog.Basic.Inductor inductor21(L=L1sigma)
  Modelica.Electrical.Analog.Basic.Inductor inductor22(L=L2sigma, i(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Resistor resistor22(R=R2)
  Modelica.Electrical.Analog.Basic.Resistor load2(R=RL)
  Modelica.Electrical.Analog.Basic.Ground ground22
  Modelica.Electrical.Analog.Basic.Transformer basicTransformer(
    L1=L1,
    L2=L2,
    M=M)
  Modelica.Electrical.Analog.Ideal.IdealTransformer idealTransformer(n=n,
      Lm1=Lm1,
    considerMagnetization=false)

initial equation
 basicTransformer.i1=0;
 basicTransformer.i2=0;
equation

  connect(sineVoltage1.n, ground11.p)
  connect(sineVoltage1.p, resistor11.p)
  connect(load1.n, ground12.p)
  connect(resistor12.n, load1.p)
  connect(sineVoltage2.n, ground21.p)
  connect(sineVoltage2.p, resistor21.p)
  connect(resistor21.n, inductor21.p)
  connect(inductor22.n, resistor22.p)
  connect(load2.n, ground22.p)
  connect(resistor22.n, load2.p)
  connect(ground11.p, basicTransformer.n1)
  connect(basicTransformer.n2, ground12.p)
  connect(basicTransformer.p1, resistor11.n)
  connect(basicTransformer.p2, resistor12.p)
  connect(ground21.p, idealTransformer.n1)
  connect(ground22.p, idealTransformer.n2)
  connect(idealTransformer.p1, inductor21.n)
  connect(idealTransformer.p2, inductor22.p)
end CompareTransformers;


Comparison of controlled switch models both with and without arc. This example is to compare the behaviour of switch models with and without an electric arc taking into consideration.

within Modelica.Electrical.Analog.Examples;
model ControlledSwitchWithArc
  "Comparison of controlled switch models both with and without arc"
  extends Modelica.Icons.Example;
  Modelica.Electrical.Analog.Basic.Ground ground1
  Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage1(V=50)
  Modelica.Electrical.Analog.Basic.Inductor inductor1(L=0.1, i(fixed=true,
        start=0))
  Modelica.Electrical.Analog.Basic.Resistor resistor1(R=1)
  Modelica.Electrical.Analog.Ideal.ControlledIdealClosingSwitch switch1
  Modelica.Electrical.Analog.Basic.Ground ground2
  Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage2(V=50)
  Modelica.Electrical.Analog.Basic.Inductor inductor2(L=0.1, i(fixed=true,
        start=0))
  Modelica.Electrical.Analog.Basic.Resistor resistor2(R=1)
  Modelica.Electrical.Analog.Ideal.ControlledCloserWithArc switch2(
    V0=30,
    dVdt=10000,
    Vmax=60,
    off(fixed=true))
  Modelica.Electrical.Analog.Sources.SineVoltage sineVoltage(V=1, f=1)
  Modelica.Electrical.Analog.Basic.Ground ground
equation
  connect(inductor1.n,resistor1. p)
  connect(resistor1.n,ground1. p)
  connect(constantVoltage1.n,ground1. p)
  connect(switch1.n,inductor1. p)
  connect(constantVoltage1.p,switch1. p)
  connect(inductor2.n,resistor2. p)
  connect(resistor2.n,ground2. p)
  connect(constantVoltage2.n,ground2. p)
  connect(switch2.n,inductor2. p)
  connect(constantVoltage2.p,switch2. p)
  connect(sineVoltage.p, switch1.control)
  connect(sineVoltage.p, switch2.control)
  connect(sineVoltage.n, ground.p)
end ControlledSwitchWithArc;


Demonstrate trajectory of lightning current. Compare 2 lightning trajectories: No.1 with double exponential function, No.2 with Heidler function.

within Modelica.Electrical.Analog.Examples;
model DemonstrateLightning
  "Demonstrate trajectory of lightning current"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Time T1=10e-6 "Rise time";
  parameter Modelica.Units.SI.Time T2=350e-6 "Decay time to half value";
  Sources.LightningImpulseVoltage lightning1(
    approximation=Modelica.Electrical.Analog.Types.ImpulseApproximation.DoubleExp,

    V=100e3,
    T1=T1,
    T2=T2,
    startTime=10e-6)
  Sources.LightningImpulseCurrent lightning2(
    approximation=Modelica.Electrical.Analog.Types.ImpulseApproximation.Heidler,

    I=100e3,
    T1=T1,
    T2=T2,
    startTime=10e-6)

  Basic.Ground ground1
  Basic.Ground ground2
  Basic.Resistor resistor1(R=1)
  Basic.Resistor resistor2(R=1)
  Sensors.CurrentSensor currentSensor1
  Sensors.CurrentSensor currentSensor2
 Modelica.Blocks.Continuous.Integrator integrator1
  Modelica.Blocks.Continuous.Der der1
  Modelica.Blocks.Continuous.Integrator integrator2
  Modelica.Blocks.Continuous.Der der2
equation
  connect(integrator1.u, der1.u)
  connect(integrator2.u, der2.u)
  connect(lightning2.p, ground2.p)
  connect(ground1.p,resistor1. n)
  connect(ground2.p,resistor2. n)
  connect(currentSensor1.n,resistor1. p)
  connect(currentSensor1.i, der1.u)
  connect(lightning2.n, currentSensor2.p)
  connect(currentSensor2.n,resistor2. p)
  connect(currentSensor2.i, der2.u)
  connect(lightning1.n, ground1.p)
  connect(lightning1.p, currentSensor1.p)
end DemonstrateLightning;


Demonstrate behaviour of DC Power Supply.

within Modelica.Electrical.Analog.Examples;
model DemoPowerSupply "Demonstrate behaviour of DC Power Supply"
  extends Modelica.Icons.Example;
  Modelica.Electrical.Analog.Sources.DCPowerSupply dcPowerSupply
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Basic.VariableConductor conductor
  Modelica.Blocks.Sources.Ramp ramp(height = 6, duration = 1, offset = -3)
  Modelica.Blocks.Math.Power power10(base=10)
equation
  connect(dcPowerSupply.n, ground.p)
  connect(dcPowerSupply.p, conductor.p)
  connect(ground.p, conductor.n)
  connect(power10.y, conductor.G)
  connect(ramp.y, power10.u)
end DemoPowerSupply;


Demonstrate how to avoid back current to the DC Power Supply. At the beginning, the DC power supply charges the buffer capacitor within its limits (current, power, voltage).
The DC power supply is protected from back current by a buffer capacitor and a diode.
This also reduces current ripple of the power supply.

within Modelica.Electrical.Analog.Examples;
model DemoPowerSupplyWithBuffer
  "Demonstrate how to avoid back current to the DC Power Supply"
  extends Modelica.Icons.Example;
  parameter SI.Current amplitude = 50 "Pulse current amplitude peak-to-peak";
  parameter SI.Current offset = -25 "Pulse current offset";
  parameter Real dutyCycle(final min = 0, final max = 1) = 0.5 "Pulse current duty cycle";
  parameter SI.Frequency f = 1e3 "Pulse current frequency";
  Modelica.Electrical.Analog.Sources.DCPowerSupply dcPowerSupply(
    Gcc=0.01,
    Rcv=0.01,
    iBack=0.1)
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Basic.Resistor cable(R = 1e-3)
  Modelica.Electrical.Analog.Ideal.IdealDiode diode
  Modelica.Electrical.Analog.Basic.Capacitor bufferCapacitor(v(fixed = true, start = 0), C = 100e-3)
  Modelica.Electrical.Analog.Sources.SignalCurrent loadCurrent
  Modelica.Blocks.Sources.Pulse pulse(amplitude = amplitude, width = dutyCycle * 100, period = 1 / f, startTime = 0.5)
  Modelica.Blocks.Sources.Step step(height = offset, startTime = 0.5)
  Modelica.Blocks.Math.Add      add
equation
  connect(dcPowerSupply.n, ground.p)
  connect(dcPowerSupply.p, cable.p)
  connect(cable.n, diode.p)
  connect(pulse.y, add.u1)
  connect(add.y, loadCurrent.i)
  connect(step.y, add.u2)
  connect(diode.n, bufferCapacitor.p)
  connect(bufferCapacitor.p, loadCurrent.p)
  connect(bufferCapacitor.n, loadCurrent.n)
  connect(ground.p, bufferCapacitor.n)
end DemoPowerSupplyWithBuffer;


Simple NPN transistor amplifier circuit. It is a simple NPN transistor amplifier circuit. The voltage difference between R1.p and R3.n is amplified. The output signal is the voltage between R2.n and R4.n. In this example the voltage at V1 is amplified because R3.n is grounded.

within Modelica.Electrical.Analog.Examples;
model DifferenceAmplifier
  "Simple NPN transistor amplifier circuit"
  extends Modelica.Icons.Example;

  Modelica.Electrical.Analog.Sources.ExpSineVoltage V1(
    V=0.2,
    f=0.2e9,
    damping=0.1e8)
  Modelica.Electrical.Analog.Sources.RampVoltage V2(V=15, duration=1e-9)
  Modelica.Electrical.Analog.Sources.RampCurrent I1(I=0.16, duration=1e-9)
  Modelica.Electrical.Analog.Basic.Resistor R1(R=0.0001)
  Modelica.Electrical.Analog.Basic.Resistor R2(R=100)
  Modelica.Electrical.Analog.Basic.Resistor R3(R=0.0001)
  Modelica.Electrical.Analog.Basic.Resistor R4(R=100)
  Modelica.Electrical.Analog.Basic.Capacitor C1(C=1e-10, v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C4(C=1e-10, v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C5(C=1e-10, v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C2(C=1e-10, v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Capacitor C3(C=1e-10, v(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Ground Gnd1
  Modelica.Electrical.Analog.Basic.Ground Gnd9
  Modelica.Electrical.Analog.Basic.Ground Gnd3
  Modelica.Electrical.Analog.Basic.Ground Gnd2
  Modelica.Electrical.Analog.Basic.Ground Gnd6
  Modelica.Electrical.Analog.Basic.Ground Gnd7
  Modelica.Electrical.Analog.Basic.Ground Gnd8
  Modelica.Electrical.Analog.Basic.Ground Gnd5
  Modelica.Electrical.Analog.Basic.Ground Gnd4
  Modelica.Electrical.Analog.Examples.Utilities.Transistor Transistor1(ct(v(start=0, fixed=true)))
  Modelica.Electrical.Analog.Examples.Utilities.Transistor Transistor2(ct(v(start=0, fixed=true)))
equation
  connect(V1.n, Gnd1.p)
  connect(C1.n, Gnd2.p)
  connect(I1.n, Gnd7.p)
  connect(C5.n, Gnd8.p)
  connect(C3.n, Gnd5.p)
  connect(R3.n, Gnd4.p)
  connect(C2.n, Gnd3.p)
  connect(C4.p, Gnd6.p)
  connect(I1.p, C5.p)
  connect(R1.p, V1.p)
  connect(R2.p, V2.p)
  connect(R4.p, V2.p)
  connect(V2.n, Gnd9.p)
  connect(R1.n, Transistor1.b)
  connect(Transistor1.b, C1.p)
  connect(Transistor1.c, C2.p)
  connect(R2.n, Transistor1.c)
  connect(Transistor1.e, I1.p)
  connect(Transistor2.b, R3.p)
  connect(Transistor2.b, C3.p)
  connect(C4.n, Transistor2.c)
  connect(R4.n, Transistor2.c)
  connect(C5.p, Transistor2.e)
end DifferenceAmplifier;


Example to demonstrate variants to generate FMUs (Functional Mock-up Units). This example demonstrates how to generate an input/output block (e.g. in form of an
FMU - Functional Mock-up Unit) from various Electrical components.
The goal is to export such an input/output block from Modelica and import
it in another modeling environment. The essential issue is that before
exporting it must be known in which way the component is utilized in the
target environment. Depending on the target usage, different connector variables
need to be in the interface with either input or output causality.
Note, this example model can be used to test the FMU export/import of a Modelica tool.
Just export the components marked in the icons as \"toFMU\" as FMUs and import
them back. The models should then still work and give the same results as a
pure Modelica model.

within Modelica.Electrical.Analog.Examples;
model GenerationOfFMUs
  "Example to demonstrate variants to generate FMUs (Functional Mock-up Units)"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine sine12(f=2, amplitude=1)
  Modelica.Electrical.Analog.Examples.Utilities.DirectCapacitor
    directCapacitor1(C=1e-3)
  Modelica.Electrical.Analog.Examples.Utilities.InverseCapacitor
    inverseCapacitor1(C=2e-3)
  Modelica.Electrical.Analog.Examples.Utilities.Resistor resistor2(R=10)
  Modelica.Electrical.Analog.Basic.Capacitor capacitor2a(v(start=0, fixed=true), C=1e-3)
  Modelica.Electrical.Analog.Sources.SignalCurrent current2
  Modelica.Electrical.Analog.Basic.GeneralCurrentToVoltageAdaptor currentToVoltage2a(
      use_pder=false, use_fder=false)
  Modelica.Electrical.Analog.Basic.Capacitor capacitor2b(v(fixed=true, start=0), C=2e-3)
  Modelica.Electrical.Analog.Basic.GeneralCurrentToVoltageAdaptor currentToVoltage2b(
      use_pder=false, use_fder=false)
  Modelica.Electrical.Analog.Basic.Ground ground2a
  Modelica.Electrical.Analog.Basic.Ground ground3b
  Modelica.Blocks.Sources.Sine sine34(f=2, amplitude=1)
  Modelica.Electrical.Analog.Examples.Utilities.DirectInductor directInductor3(
      L=1e-3)
  Modelica.Electrical.Analog.Examples.Utilities.InverseInductor
    inverseInductor3(L=2e-3)
  Modelica.Electrical.Analog.Sources.SignalVoltage voltage4
  Modelica.Electrical.Analog.Basic.Ground ground4a
  Modelica.Electrical.Analog.Basic.Inductor inductor4a(i(fixed=true, start=0), L=1e-3)
  Modelica.Electrical.Analog.Basic.GeneralVoltageToCurrentAdaptor voltageToCurrent4a(
      use_pder=false, use_fder=false)
  Modelica.Electrical.Analog.Examples.Utilities.Conductor conductor4(G=10)
  Modelica.Electrical.Analog.Basic.GeneralVoltageToCurrentAdaptor voltageToCurrent4b(
      use_pder=false, use_fder=false)
  Modelica.Electrical.Analog.Basic.Inductor inductor4b(i(fixed=true, start=0), L=2e-3)
  Modelica.Electrical.Analog.Basic.Ground ground4b
equation
  connect(sine12.y, directCapacitor1.iDrive)
  connect(directCapacitor1.v, inverseCapacitor1.v)
  connect(directCapacitor1.dv, inverseCapacitor1.dv)
  connect(directCapacitor1.i, inverseCapacitor1.i)
  connect(sine12.y, current2.i)
  connect(current2.n, capacitor2a.p)
  connect(capacitor2a.p, currentToVoltage2a.pin_p)
  connect(capacitor2a.n, currentToVoltage2a.pin_n)
  connect(currentToVoltage2a.p,resistor2. v1)
  connect(currentToVoltage2a.f,resistor2. i1)
  connect(resistor2.v2, currentToVoltage2b.p)
  connect(resistor2.i2, currentToVoltage2b.f)
  connect(currentToVoltage2b.pin_p, capacitor2b.p)
  connect(current2.p, ground2a.p)
  connect(ground2a.p, capacitor2a.n)
  connect(currentToVoltage2b.pin_n, ground3b.p)
  connect(ground3b.p, capacitor2b.n)
  connect(sine34.y, directInductor3.vDrive)
  connect(directInductor3.v, inverseInductor3.v)
  connect(directInductor3.di, inverseInductor3.di)
  connect(directInductor3.i, inverseInductor3.i)
  connect(inductor4a.n, voltageToCurrent4a.pin_p)
  connect(ground4a.p, voltageToCurrent4a.pin_n)
  connect(voltageToCurrent4b.pin_p, inductor4b.p)
  connect(voltageToCurrent4b.pin_n, ground4b.p)
  connect(ground4b.p, inductor4b.n)
  connect(sine34.y, voltage4.v)
  connect(voltageToCurrent4a.f, conductor4.i1)
  connect(voltageToCurrent4a.p, conductor4.v1)
  connect(conductor4.v2, voltageToCurrent4b.p)
  connect(conductor4.i2, voltageToCurrent4b.f)
  connect(voltage4.p, inductor4a.p)
  connect(ground4a.p, voltage4.n)
end GenerationOfFMUs;


Heating MOS Inverter. The heating MOS inverter shows a heat flow always if a transistor is leading.

within Modelica.Electrical.Analog.Examples;
model HeatingMOSInverter "Heating MOS Inverter"
  extends Modelica.Icons.Example;
  Modelica.Electrical.Analog.Basic.Ground G
  Modelica.Electrical.Analog.Sources.SineVoltage Sin(V=5, f=1)

  Modelica.Electrical.Analog.Basic.Capacitor Capacitor1(C=0.00001, v(start=0, fixed=true))
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor HeatCapacitor1(C=0.01)
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor TC1(G=0.01)
  Semiconductors.PMOS H_PMOS(useTemperatureDependency=true)
  Semiconductors.NMOS H_NMOS(useTemperatureDependency=true)
  Modelica.Electrical.Analog.Sources.RampVoltage V(V=5, duration=1e-2)
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor TC2(G=0.01)
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature FixedTemperature1(T=
        300)
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor TC3(G=0.01)

initial equation
  HeatCapacitor1.T= 293.15;

equation
  connect(Sin.n, G.p)
  connect(Capacitor1.n, G.p)

  connect(H_PMOS.S, H_NMOS.D)
  connect(H_NMOS.D, Capacitor1.p)
  connect(H_NMOS.B, H_NMOS.S)
  connect(H_NMOS.S, G.p)
  connect(H_PMOS.B, H_PMOS.D)
  connect(V.p, H_PMOS.D)
  connect(V.n, G.p)
  connect(TC1.port_b, HeatCapacitor1.port)
  connect(TC2.port_b, HeatCapacitor1.port)
  connect(TC1.port_a, H_PMOS.heatPort)
  connect(TC2.port_a, H_NMOS.heatPort)
  connect(TC3.port_b, FixedTemperature1.port)
  connect(TC3.port_a, HeatCapacitor1.port)
  connect(Sin.p, H_NMOS.G)
  connect(H_PMOS.G, Sin.p)
end HeatingMOSInverter;


Heating NPN NOR Gate. The heating "NPN NOR" gate shows a heat flow always if a transistor is leading.

within Modelica.Electrical.Analog.Examples;
model HeatingNPN_NORGate "Heating NPN NOR Gate"
  extends Modelica.Icons.Example;
  parameter SI.Capacitance CapVal=0 "Value for capacitances"
  parameter SI.Time tauVal=0 "Value for ideal forward and reverse transit time of semiconductors"

  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor HeatCapacitor1(C=0.1)
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor TC1(G=0.01)
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor TC2(G=0.01)

  Modelica.Electrical.Analog.Sources.RampVoltage V(V=6, duration=5)
  Modelica.Electrical.Analog.Sources.TrapezoidVoltage V1(
    V=6,
    startTime=55,
    rising=5,
    width=15,
    falling=5,
    period=50,
    nperiod=10)
  Modelica.Electrical.Analog.Sources.TrapezoidVoltage V2(
    V=6,
    startTime=65,
    rising=5,
    width=15,
    falling=5,
    period=50,
    nperiod=10)
  Modelica.Electrical.Analog.Basic.Resistor R1(R=1800)
  Modelica.Electrical.Analog.Basic.Resistor R2(R=1800)
  Modelica.Electrical.Analog.Basic.Resistor RI(R=40)
  Modelica.Electrical.Analog.Basic.Ground Gnd
  Modelica.Electrical.Analog.Basic.Ground Gnd1
  Modelica.Electrical.Analog.Basic.Ground Gnd2
  Modelica.Electrical.Analog.Basic.Ground Gnd3
  Modelica.Electrical.Analog.Basic.Ground Gnd4
  Modelica.Electrical.Analog.Basic.Capacitor C1(final C=CapVal)
  Modelica.Electrical.Analog.Basic.Capacitor C2(final C=CapVal)
  Modelica.Electrical.Analog.Basic.Capacitor C3(final C=CapVal)
  Modelica.Electrical.Analog.Basic.Ground Gnd5
  Modelica.Electrical.Analog.Basic.Ground Gnd6
  Modelica.Electrical.Analog.Basic.Ground Gnd7
  Semiconductors.NPN T1(
    Bf=100,
    Br=1,
    Is=1e-14,
    Vak=0,
    final Tauf=tauVal,
    final Taur=tauVal,
    final Ccs=CapVal,
    final Cje=CapVal,
    final Cjc=CapVal,
    Phie=1,
    Me=0.5,
    Phic=1,
    Mc=0.5,
    Gbc=1e-12,
    Gbe=1e-12,
    EMax=40,
    vt_t(start=0.01, fixed=false),
    useTemperatureDependency=true, ibe(start=0), vbc(start=0))
  Semiconductors.NPN T2(
    Bf=100,
    Br=1,
    Is=1e-14,
    Vak=0,
    final Tauf=tauVal,
    final Taur=tauVal,
    final Ccs=CapVal,
    final Cje=CapVal,
    final Cjc=CapVal,
    Phie=1,
    Me=0.5,
    Phic=1,
    Mc=0.5,
    Gbc=1e-12,
    Gbe=1e-12,
    EMax=40,
    vt_t(start=0.01, fixed=false),
    useTemperatureDependency=true, ibe(start=0), vbc(start=0))
initial equation
  HeatCapacitor1.T= 293.15;

equation
  connect(Gnd1.p, V1.n)
  connect(V1.p, R1.p)
  connect(RI.n, V.p)
  connect(Gnd.p, V.n)
  connect(V2.p, R2.p)
  connect(Gnd2.p, V2.n)
  connect(Gnd7.p, C1.n)
  connect(C2.p, RI.p)
  connect(Gnd6.p, C2.n)
  connect(C3.p, R2.n)
  connect(C1.p, R1.n)
  connect(Gnd5.p, C3.n)
  connect(T1.B, R1.n)
  connect(T1.E, Gnd3.p)
  connect(RI.p, T1.C)
  connect(T2.B, R2.n)
  connect(T2.E, Gnd4.p)
  connect(T2.C, RI.p)
  connect(TC1.port_b, HeatCapacitor1.port)
  connect(TC2.port_b, HeatCapacitor1.port)
  connect(TC2.port_a, T2.heatPort)
  connect(TC1.port_a, T1.heatPort)
end HeatingNPN_NORGate;


Heating PNP NOR Gate. The heating "PNP NOR" gate shows a heat flow always if a transistor is conducting.

within Modelica.Electrical.Analog.Examples;
model HeatingPNP_NORGate "Heating PNP NOR Gate"
  extends Modelica.Icons.Example;
  parameter SI.Capacitance CapVal=0 "Value for capacitances"
  parameter SI.Time tauVal=0 "Value for ideal forward and reverse transit time of semiconductors"

  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor HeatCapacitor1(C=0.1)
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor TC1(G=0.01)
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor TC2(G=0.01)

  Modelica.Electrical.Analog.Sources.RampVoltage V(V=6, duration=5)
  Modelica.Electrical.Analog.Sources.TrapezoidVoltage V1(
    startTime=55,
    rising=5,
    width=15,
    falling=5,
    period=50,
    nperiod=10,
    V=-6)
  Modelica.Electrical.Analog.Sources.TrapezoidVoltage V2(
    startTime=65,
    rising=5,
    width=15,
    falling=5,
    period=50,
    nperiod=10,
    V=-6)
  Modelica.Electrical.Analog.Basic.Resistor R1(R=1800)
  Modelica.Electrical.Analog.Basic.Resistor R2(R=1800)
  Modelica.Electrical.Analog.Basic.Resistor RI(R=40)
  Modelica.Electrical.Analog.Basic.Ground Gnd
  Modelica.Electrical.Analog.Basic.Ground Gnd2
  Modelica.Electrical.Analog.Basic.Ground Gnd3
  Modelica.Electrical.Analog.Basic.Ground Gnd4
  Modelica.Electrical.Analog.Basic.Capacitor C1(final C=CapVal)
  Modelica.Electrical.Analog.Basic.Capacitor C2(final C=CapVal)
  Modelica.Electrical.Analog.Basic.Capacitor C3(final C=CapVal)
  Modelica.Electrical.Analog.Basic.Ground Gnd5
  Modelica.Electrical.Analog.Basic.Ground Gnd6
  Modelica.Electrical.Analog.Basic.Ground Gnd7
  Modelica.Electrical.Analog.Semiconductors.PNP T1(
    Bf=100,
    Br=1,
    Is=1e-14,
    Vak=0,
    final Tauf=tauVal,
    final Taur=tauVal,
    final Ccs=CapVal,
    final Cje=CapVal,
    final Cjc=CapVal,
    Phie=1,
    Me=0.5,
    Phic=1,
    Mc=0.5,
    Gbc=1e-12,
    Gbe=1e-12,
    EMax=40,
    vt_t(start=0.01, fixed=false),
    useTemperatureDependency=true)
  Modelica.Electrical.Analog.Semiconductors.PNP T2(
    Bf=100,
    Br=1,
    Is=1e-14,
    Vak=0,
    final Tauf=tauVal,
    final Taur=tauVal,
    final Ccs=CapVal,
    final Cje=CapVal,
    final Cjc=CapVal,
    Phie=1,
    Me=0.5,
    Phic=1,
    Mc=0.5,
    Gbc=1e-12,
    Gbe=1e-12,
    EMax=40,
    vt_t(start=0.01, fixed=false),
    useTemperatureDependency=true)
  Modelica.Electrical.Analog.Basic.Ground Gnd1
initial equation
  HeatCapacitor1.T= 293.15;

equation
  connect(Gnd7.p, C1.n)
  connect(C3.p, R2.n)
  connect(C1.p, R1.n)
  connect(Gnd5.p, C3.n)
  connect(T1.B, R1.n)
  connect(T1.E, Gnd3.p)
  connect(RI.p, T1.C)
  connect(T2.B, R2.n)
  connect(T2.E, Gnd4.p)
  connect(T2.C, RI.p)
  connect(TC1.port_b, HeatCapacitor1.port)
  connect(TC2.port_b, HeatCapacitor1.port)
  connect(TC2.port_a, T2.heatPort)
  connect(TC1.port_a, T1.heatPort)
  connect(V.n, RI.n)
  connect(Gnd.p, V.p)
  connect(V1.p, R1.p)
  connect(V1.n, Gnd1.p)
  connect(V2.p, R2.p)
  connect(V2.n, Gnd2.p)
  connect(C2.p, RI.p)
  connect(C2.n, Gnd6.p)
end HeatingPNP_NORGate;


Heating rectifier. The heating rectifier shows a heat flow always if the electrical capacitor is loaded.

within Modelica.Electrical.Analog.Examples;
model HeatingRectifier "Heating rectifier"
  extends Modelica.Icons.Example;
  Modelica.Electrical.Analog.Semiconductors.Diode HeatingDiode1(
      useTemperatureDependency=true, useHeatPort=true)
  Modelica.Electrical.Analog.Basic.Ground G
  Modelica.Electrical.Analog.Sources.SineVoltage SineVoltage1(V=1, f=1)

  Modelica.Electrical.Analog.Basic.Capacitor Capacitor1(C=1, v(start=0, fixed=true))
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor HeatCapacitor1(C=1)
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor ThermalConductor1(G=10)
  Modelica.Electrical.Analog.Basic.Resistor R(R=1)
initial equation
  HeatCapacitor1.T = 293.15;

equation
  connect(SineVoltage1.p, HeatingDiode1.p)
  connect(SineVoltage1.n, G.p)
  connect(Capacitor1.n, G.p)
  connect(HeatingDiode1.n, Capacitor1.p)
  connect(HeatingDiode1.heatPort, ThermalConductor1.port_a)
  connect(ThermalConductor1.port_b, HeatCapacitor1.port)
  connect(R.p, Capacitor1.p)
  connect(R.n, Capacitor1.n)
end HeatingRectifier;


Ideal triac test circuit. The simple ideal TRIAC example shows how a triac is used within an alternating current circuit.

within Modelica.Electrical.Analog.Examples;
model IdealTriacCircuit "Ideal triac test circuit"
  extends Modelica.Icons.Example;

  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Basic.Resistor R(R=20)
  Modelica.Electrical.Analog.Sources.SineVoltage V(V=5, f=2)
  Modelica.Blocks.Sources.BooleanPulse booleanPulse(width=50,
    period=0.25,
    startTime=0.1)
 Modelica.Electrical.Analog.Ideal.IdealTriac idealTriac(capacitor(v(start=0, fixed=true)),idealThyristor(
                                                        off(               start=true, fixed=true)), idealThyristor1(off(start=true, fixed=true)))

equation
  connect(V.n, ground.p)
  connect(R.p, V.p)
  connect(R.n, idealTriac.n)
  connect(idealTriac.p, ground.p)
  connect(idealTriac.fire1, booleanPulse.y)
end IdealTriacCircuit;


Inverting amplifier. This is an inverting amplifier. Resistance R1 can be chosen, R2 is defined by the desired amplification k.

within Modelica.Electrical.Analog.Examples;
model InvertingAmp "Inverting amplifier"
  extends Modelica.Icons.Example;
  parameter SI.Voltage Vps=+15 "Positive supply";
  parameter SI.Voltage Vns=-15 "Negative supply";
  parameter SI.Voltage Vin=5 "Amplitude of input voltage";
  parameter SI.Frequency f=10 "Frequency of input voltage";
  parameter Real k=2 "Desired amplification";
  parameter SI.Resistance R1=1000 "Arbitrary resistance";
  parameter SI.Resistance R2=k*R1 "Calculated resistance to reach desired amplification k";
  Modelica.Electrical.Analog.Ideal.IdealOpAmpLimited opAmp(
    out(i(start=0, fixed=false)))
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Sources.TrapezoidVoltage vIn(
    V=2*Vin,
    rising=0.2/f,
    width=0.3/f,
    falling=0.2/f,
    period=1/f,
    nperiod=-1,
    offset=-Vin,
    startTime=-(vIn.rising + vIn.width/2))
  Modelica.Electrical.Analog.Sensors.VoltageSensor vOut
  Modelica.Electrical.Analog.Basic.Resistor r1(R=R1)
  Modelica.Electrical.Analog.Basic.Resistor r2(R=R2)
  Modelica.Electrical.Analog.Basic.Ground ground1
  Modelica.Electrical.Analog.Sources.ConstantVoltage vSourcePos(V=Vps)
  Modelica.Electrical.Analog.Sources.ConstantVoltage vSourceNeg(V=Vns)
equation
  connect(r1.n, r2.n)
  connect(r2.n, opAmp.in_n)
  connect(r2.p, opAmp.out)
  connect(ground.p, opAmp.in_p)
  connect(vIn.p, r1.p)
  connect(ground.p, vIn.n)
  connect(ground.p, vOut.n)
  connect(opAmp.out, vOut.p)
  connect(ground1.p, vSourcePos.n)
  connect(vSourcePos.p, opAmp.VMax)
  connect(vSourcePos.n, vSourceNeg.n)
  connect(vSourceNeg.p, opAmp.VMin)
end InvertingAmp;


CMOS NAND Gate (see Tietze/Schenk, page 157). The nand gate is a basic CMOS building block. It consists of four CMOS transistors. The output voltage Nand.y.v is low if and only if the two input voltages at Nand.x1.v and Nand.x2.v are both high. In this way the nand functionality is realized.

within Modelica.Electrical.Analog.Examples;
model NandGate "CMOS NAND Gate (see Tietze/Schenk, page 157)"
  extends Modelica.Icons.Example;

  Modelica.Electrical.Analog.Sources.TrapezoidVoltage VIN1(
    V=3.5,
    startTime=20e-9,
    rising=1e-9,
    width=19e-9,
    falling=1e-9,
    period=40e-9,
    nperiod=-1)
  Modelica.Electrical.Analog.Sources.TrapezoidVoltage VIN2(
    V=3.5,
    startTime=10e-9,
    rising=1e-9,
    width=19e-9,
    falling=1e-9,
    period=40e-9,
    nperiod=-1)
  Modelica.Electrical.Analog.Sources.RampVoltage VDD(V=5, duration=1e-9)
  Modelica.Electrical.Analog.Basic.Ground Gnd1
  Modelica.Electrical.Analog.Basic.Ground Gnd4
  Modelica.Electrical.Analog.Basic.Ground Gnd5
  Modelica.Electrical.Analog.Examples.Utilities.Nand Nand(C4(v(start=0, fixed=true)),C7(v(start=0, fixed=true)))
equation
  connect(VDD.n, Gnd1.p)
  connect(VIN1.n, Gnd4.p)
  connect(VIN2.n, Gnd5.p)
  connect(Nand.Vdd, VDD.p)
  connect(VIN1.p, Nand.x1)
  connect(VIN2.p, Nand.x2)
end NandGate;


Example for Zener diodes. This example is a simple circuit for overvoltage protection. If the voltage zDiode_1.n.v is too high, the Diode zDiode_2 breaks through and the voltage gets down.

within Modelica.Electrical.Analog.Examples;
model OvervoltageProtection "Example for Zener diodes"
  extends Modelica.Icons.Example;

 Modelica.Electrical.Analog.Sources.SineVoltage sineVoltage(
   offset=0,
   V=10,
   f=5)
 Modelica.Electrical.Analog.Basic.Resistor Rv(R=20)
 Modelica.Electrical.Analog.Basic.Resistor RL(R=2000)
 Modelica.Electrical.Analog.Basic.Ground ground
 Modelica.Electrical.Analog.Basic.Capacitor CL(C=1e-7, v(start=0, fixed=true))
  Semiconductors.ZDiode zDiode
  Semiconductors.ZDiode zDiode1(v(start=0))
equation
 connect(sineVoltage.p, Rv.p)
 connect(RL.p, CL.p)
 connect(RL.n, CL.n)
  connect(sineVoltage.n, zDiode.p)
  connect(zDiode.p, ground.p)
  connect(zDiode.p, RL.n)
  connect(zDiode1.p, Rv.n)
  connect(RL.p, Rv.n)
  connect(zDiode1.n, zDiode.n)
end OvervoltageProtection;


within Modelica.Electrical.Analog;
package Examples "Examples that demonstrate the usage of the Analog electrical components"
  extends Modelica.Icons.ExamplesPackage;
end Examples;


Parallel resonance circuit. This model demonstrates the transient behaviour of a parallel resonant circuit:
A sine or cosine current with variable frequency and constant amplitude is applied to a parallel connection of L, C and R.
The parameter values result in a resonance frequency of 100 Hz.

within Modelica.Electrical.Analog.Examples;
model ParallelResonance "Parallel resonance circuit"
  extends Modelica.Icons.Example;
  import Modelica.Constants.pi;
  Sources.SineCurrentVariableFrequencyAndAmplitude sineCurrent(
      useConstantAmplitude=true,                               phi(fixed=true))
  Basic.Ground ground1
  Basic.Resistor resistor1(R=0.5)
  Basic.Inductor inductor1(i(fixed=true), L=0.1/(2*pi))
  Basic.Capacitor capacitor1(v(fixed=true), C=0.001/(2*pi))
  Sensors.VoltageSensor voltageSensor1
  Blocks.Sources.Ramp ramp(
    height=200,
    duration=1,
    offset=0,
    startTime=0)
  Sources.CosineCurrentVariableFrequencyAndAmplitude cosineCurrent(
      useConstantAmplitude=true, phi(fixed=true))
  Basic.Ground ground2
  Basic.Resistor resistor2(R=0.5)
  Basic.Inductor inductor2(i(fixed=true), L=0.1/(2*pi))
  Basic.Capacitor capacitor2(v(fixed=true), C=0.001/(2*pi))
  Sensors.VoltageSensor voltageSensor2
equation
  connect(sineCurrent.p, ground1.p)
  connect(ramp.y, sineCurrent.f)
  connect(ground1.p, inductor1.n)
  connect(sineCurrent.n, resistor1.p)
  connect(resistor1.n, inductor1.p)
  connect(ground1.p, capacitor1.n)
  connect(sineCurrent.n, capacitor1.p)
  connect(sineCurrent.n, voltageSensor1.p)
  connect(ground1.p, voltageSensor1.n)
  connect(cosineCurrent.p, ground2.p)
  connect(ground2.p, inductor2.n)
  connect(cosineCurrent.n, resistor2.p)
  connect(resistor2.n, inductor2.p)
  connect(ground2.p, capacitor2.n)
  connect(cosineCurrent.n, capacitor2.p)
  connect(cosineCurrent.n, voltageSensor2.p)
  connect(ground2.p, voltageSensor2.n)
  connect(ramp.y, cosineCurrent.f)
end ParallelResonance;


B6 diode bridge. The rectifier example shows a B6 diode bridge fed by a three-phase sinusoidal voltage, loaded by a DC current.
DC capacitors start at ideal no-load voltage, thus making easier initial transient.

within Modelica.Electrical.Analog.Examples;
model Rectifier "B6 diode bridge"
  extends Modelica.Icons.Example;
  import Modelica.Electrical.Analog.Ideal;
  parameter SI.Voltage VAC=400 "RMS line-to-line";
  parameter SI.Frequency f=50 "Line frequency";
  parameter SI.Inductance LAC=60E-6 "Line inductor";
  parameter SI.Resistance Ron=1E-3 "Diode forward resistance";
  parameter SI.Conductance Goff=1E-3 "Diode backward conductance";
  parameter SI.Voltage Vknee=2 "Diode threshold voltage";
  parameter SI.Capacitance CDC=15E-3 "DC capacitance";
  parameter SI.Current IDC=500 "Load current";
  output SI.Voltage uDC;
  output SI.Current iAC[3];
  output SI.Voltage uAC[3];
  output SI.Power Losses;

  Modelica.Electrical.Analog.Sources.SineVoltage SineVoltage1(f=f,
       V=VAC*sqrt(2/3))
  Modelica.Electrical.Analog.Sources.SineVoltage SineVoltage2(
    f=f,
    phase=-2/3*Modelica.Constants.pi,
    V=VAC*sqrt(2/3))
  Modelica.Electrical.Analog.Sources.SineVoltage SineVoltage3(
    f=f,
    phase=-4/3*Modelica.Constants.pi,
    V=VAC*sqrt(2/3))
  Modelica.Electrical.Analog.Basic.Inductor Inductor1(L=LAC)
  Modelica.Electrical.Analog.Basic.Inductor Inductor2(L=LAC, i(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Inductor Inductor3(L=LAC, i(start=0, fixed=true))
  Ideal.IdealDiode IdealDiode1(
    Ron=Ron,
    Goff=Goff,
    Vknee=Vknee)
  Ideal.IdealDiode IdealDiode2(
    Ron=Ron,
    Goff=Goff,
    Vknee=Vknee)
  Ideal.IdealDiode IdealDiode3(
    Ron=Ron,
    Goff=Goff,
    Vknee=Vknee)
  Ideal.IdealDiode IdealDiode4(
    Ron=Ron,
    Goff=Goff,
    Vknee=Vknee)
  Ideal.IdealDiode IdealDiode5(
    Ron=Ron,
    Goff=Goff,
    Vknee=Vknee)
  Ideal.IdealDiode IdealDiode6(
    Ron=Ron,
    Goff=Goff,
    Vknee=Vknee)
  Modelica.Electrical.Analog.Basic.Capacitor Capacitor1(C=2*CDC)
  Modelica.Electrical.Analog.Basic.Capacitor Capacitor2(C=2*CDC)
  Modelica.Electrical.Analog.Basic.Ground Ground1
  Modelica.Electrical.Analog.Sources.SignalCurrent SignalCurrent1
  Modelica.Blocks.Sources.Constant Constant1(k=IDC)
initial equation
  Capacitor1.v = VAC*sqrt(2)/2;
  Capacitor2.v = VAC*sqrt(2)/2;
equation
  uDC = Capacitor1.v + Capacitor2.v;
  iAC = {Inductor1.i,Inductor2.i,Inductor3.i};
  uAC[1] = Inductor1.n.v - Inductor2.n.v;
  uAC[2] = Inductor2.n.v - Inductor3.n.v;
  uAC[3] = Inductor3.n.v - Inductor1.n.v;
  Losses = IdealDiode1.v*IdealDiode1.i + IdealDiode2.v*IdealDiode2.i +
    IdealDiode3.v*IdealDiode3.i + IdealDiode4.v*IdealDiode4.i +
    IdealDiode5.v*IdealDiode5.i + IdealDiode6.v*IdealDiode6.i;
  connect(SineVoltage1.n, SineVoltage2.n)
  connect(SineVoltage2.n, SineVoltage3.n)
  connect(SineVoltage1.p, Inductor1.p)
  connect(SineVoltage2.p, Inductor2.p)
  connect(SineVoltage3.p, Inductor3.p)
  connect(IdealDiode1.p, IdealDiode4.n)
  connect(IdealDiode2.p, IdealDiode5.n)
  connect(IdealDiode3.p, IdealDiode6.n)
  connect(IdealDiode1.n, IdealDiode2.n)
  connect(IdealDiode2.n, IdealDiode3.n)
  connect(IdealDiode4.p, IdealDiode5.p)
  connect(IdealDiode5.p, IdealDiode6.p)
  connect(Capacitor2.n, IdealDiode6.p)
  connect(IdealDiode3.n, Capacitor1.p)
  connect(Capacitor1.n, Capacitor2.p)
  connect(Capacitor2.p, Ground1.p)
  connect(Capacitor1.p, SignalCurrent1.p)
  connect(SignalCurrent1.n, Capacitor2.n)
  connect(Constant1.y, SignalCurrent1.i)
  connect(Inductor1.n, IdealDiode1.p)
  connect(Inductor2.n, IdealDiode2.p)
  connect(Inductor3.n, IdealDiode3.p)
end Rectifier;


Resistor with simple thermal network. This is a very simple circuit consisting of a voltage source and a resistor. The loss power in the resistor is transported to the environment via its heatPort.

within Modelica.Electrical.Analog.Examples;
model Resistor "Resistor with simple thermal network"
  extends Modelica.Icons.Example;
  Basic.Resistor resistor(
    R=100,
    alpha=1e-3,
    T_ref=293.15,
    i(start=0),
    useHeatPort=true)
  Modelica.Electrical.Analog.Basic.Ground G
  Modelica.Electrical.Analog.Sources.SineVoltage SineVoltage1(V=220, f=1)

  Modelica.Thermal.HeatTransfer.Components.ThermalConductor thermalConductor(G=
        50)
  Thermal.HeatTransfer.Celsius.FixedTemperature fixedTemperature(T=20)
equation
  connect(SineVoltage1.n, G.p)
  connect(resistor.heatPort, thermalConductor.port_a)

  connect(SineVoltage1.p, resistor.p)

  connect(G.p, resistor.n)
  connect(thermalConductor.port_b, fixedTemperature.port)
end Resistor;


Resonance circuits: example to demonstrate generation of FMUs (Functional Mock-up Units). This example demonstrates how to couple the components of a parallel resonance circuit (upper part) and a series resonance circuit (lower part)
not directly but using adaptors between physical connectors and input/output signals.
Taking into account which derivatives are required, these components can be exported as input/output blocks
(e.g. in form of an FMU - Functional Mock-up Unit).
Connecting these input/output blocks should give the same results as connecting the physical components directly.

within Modelica.Electrical.Analog.Examples;
model ResonanceCircuits
  "Resonance circuits: example to demonstrate generation of FMUs (Functional Mock-up Units)"
  import Modelica.Constants.pi;
  extends Modelica.Icons.Example;
  parameter SI.Capacitance C=0.01 "Capacitance";
  parameter SI.Inductance L=0.01 "Inductance";
  final parameter SI.Frequency fRes=1/(2*pi*sqrt(L*C)) "Resonance frequency";
  parameter Real res=1 "Source to resonance frequency ratio (f/fRes)";
  parameter SI.Frequency f=res*fRes "Source frequency";

  Modelica.Electrical.Analog.Sources.SineCurrent current1(I=1, f=f)
  Modelica.Electrical.Analog.Basic.Ground ground1
  Modelica.Electrical.Analog.Basic.Inductor inductor1(i(fixed=true, start=0), L=L)
  Modelica.Electrical.Analog.Basic.Conductor conductor1(G=1)
  Modelica.Electrical.Analog.Basic.Capacitor capacitor1(v(start=0, fixed=true), C=C)
  Modelica.Electrical.Analog.Sources.SineVoltage voltage2(V=1, f=f)
  Modelica.Electrical.Analog.Basic.Ground ground2
  Modelica.Electrical.Analog.Basic.Inductor inductor2(i(fixed=true, start=0), L=L)
  Modelica.Electrical.Analog.Basic.Resistor resistor2(R=1)
  Modelica.Electrical.Analog.Basic.Capacitor capacitor2(v(start=0, fixed=true), C=C)
  Modelica.Electrical.Analog.Basic.GeneralVoltageToCurrentAdaptor
    voltageToCurrentAdaptor1a(use_pder=false)
  Modelica.Electrical.Analog.Basic.GeneralCurrentToVoltageAdaptor
    currentToVoltageAdaptor1a(use_pder=false)
  Modelica.Electrical.Analog.Basic.Ground ground1a
  Modelica.Electrical.Analog.Basic.GeneralCurrentToVoltageAdaptor
    currentToVoltageAdaptor1b(use_pder=false)
  Modelica.Electrical.Analog.Basic.GeneralVoltageToCurrentAdaptor
    voltageToCurrentAdaptor1b(use_pder=false)

  Modelica.Electrical.Analog.Basic.Ground ground1b
  Modelica.Electrical.Analog.Basic.GeneralVoltageToCurrentAdaptor
    voltageToCurrentAdaptor1c(use_pder=false)
  Modelica.Electrical.Analog.Basic.GeneralCurrentToVoltageAdaptor
    currentToVoltageAdaptor1c(use_pder=false)
  Modelica.Electrical.Analog.Basic.Ground ground1c
  Modelica.Electrical.Analog.Basic.GeneralCurrentToVoltageAdaptor
    currentToVoltageAdaptor2a(use_fder=false)
  Modelica.Electrical.Analog.Basic.GeneralVoltageToCurrentAdaptor
    voltageToCurrentAdaptor2a(use_fder=false)
  Modelica.Electrical.Analog.Basic.Ground ground2a
  Modelica.Electrical.Analog.Basic.GeneralVoltageToCurrentAdaptor
    voltageToCurrentAdaptor2b(use_fder=false)
  Modelica.Electrical.Analog.Basic.GeneralCurrentToVoltageAdaptor
    currentToVoltageAdaptor2b(use_fder=false)
  Modelica.Electrical.Analog.Basic.Ground ground2b
  Modelica.Electrical.Analog.Basic.GeneralCurrentToVoltageAdaptor
    currentToVoltageAdaptor2c(use_fder=false)
  Modelica.Electrical.Analog.Basic.GeneralVoltageToCurrentAdaptor
    voltageToCurrentAdaptor2c(use_fder=false)
  Modelica.Electrical.Analog.Basic.Ground ground2c
equation
  connect(voltage2.n, ground2.p)
  connect(ground1.p, current1.p)
  connect(current1.n, voltageToCurrentAdaptor1a.pin_p)
  connect(current1.p, voltageToCurrentAdaptor1a.pin_n)
  connect(currentToVoltageAdaptor1a.p, voltageToCurrentAdaptor1a.p)
  connect(voltageToCurrentAdaptor1a.f, currentToVoltageAdaptor1a.f)
  connect(voltageToCurrentAdaptor1a.fder, currentToVoltageAdaptor1a.fder)
  connect(currentToVoltageAdaptor1a.pin_p, inductor1.p)
  connect(currentToVoltageAdaptor1a.pin_n, inductor1.n)
  connect(inductor1.p, currentToVoltageAdaptor1b.pin_p)
  connect(currentToVoltageAdaptor1b.pin_n, inductor1.n)
  connect(inductor1.n, ground1a.p)
  connect(currentToVoltageAdaptor1b.p, voltageToCurrentAdaptor1b.p)
  connect(currentToVoltageAdaptor1b.fder, voltageToCurrentAdaptor1b.fder)
  connect(currentToVoltageAdaptor1b.f, voltageToCurrentAdaptor1b.f)
  connect(voltageToCurrentAdaptor1b.pin_p, conductor1.p)
  connect(voltageToCurrentAdaptor1b.pin_n, conductor1.n)
  connect(conductor1.n, ground1b.p)
  connect(capacitor1.n, ground1c.p)
  connect(conductor1.p, voltageToCurrentAdaptor1c.pin_p)
  connect(conductor1.n, voltageToCurrentAdaptor1c.pin_n)
  connect(voltageToCurrentAdaptor1c.p, currentToVoltageAdaptor1c.p)
  connect(voltageToCurrentAdaptor1c.fder, currentToVoltageAdaptor1c.fder)
  connect(voltageToCurrentAdaptor1c.f, currentToVoltageAdaptor1c.f)
  connect(capacitor1.n, currentToVoltageAdaptor1c.pin_n)
  connect(currentToVoltageAdaptor1c.pin_p, capacitor1.p)
  connect(voltage2.p, currentToVoltageAdaptor2a.pin_p)
  connect(voltage2.n, currentToVoltageAdaptor2a.pin_n)
  connect(voltageToCurrentAdaptor2a.pin_p, inductor2.p)
  connect(currentToVoltageAdaptor2a.p, voltageToCurrentAdaptor2a.p)
  connect(currentToVoltageAdaptor2a.pder, voltageToCurrentAdaptor2a.pder)
  connect(currentToVoltageAdaptor2a.f, voltageToCurrentAdaptor2a.f)
  connect(voltageToCurrentAdaptor2b.p, currentToVoltageAdaptor2b.p)
  connect(voltageToCurrentAdaptor2b.pder, currentToVoltageAdaptor2b.pder)
  connect(inductor2.n, voltageToCurrentAdaptor2b.pin_p)
  connect(voltageToCurrentAdaptor2a.pin_n, ground2a.p)
  connect(ground2a.p, voltageToCurrentAdaptor2b.pin_n)
  connect(voltageToCurrentAdaptor2b.f, currentToVoltageAdaptor2b.f)
  connect(capacitor2.n, ground2c.p)
  connect(currentToVoltageAdaptor2b.pin_p, resistor2.p)
  connect(currentToVoltageAdaptor2c.pin_p, resistor2.n)
  connect(voltageToCurrentAdaptor2c.pin_p, capacitor2.p)
  connect(capacitor2.n, voltageToCurrentAdaptor2c.pin_n)
  connect(currentToVoltageAdaptor2c.pin_n, ground2b.p)
  connect(ground2b.p, currentToVoltageAdaptor2b.pin_n)
  connect(currentToVoltageAdaptor2c.p, voltageToCurrentAdaptor2c.p)
  connect(currentToVoltageAdaptor2c.pder, voltageToCurrentAdaptor2c.pder)
  connect(currentToVoltageAdaptor2c.f, voltageToCurrentAdaptor2c.f)
end ResonanceCircuits;


Series resonance circuit. This model demonstrates the transient behaviour of a series resonant circuit:
A sine or cosine voltage with variable frequency and constant amplitude is applied to a series connection of L, C and R.
The parameter values result in a resonance frequency of 100 Hz.

within Modelica.Electrical.Analog.Examples;
model SeriesResonance "Series resonance circuit"
  extends Modelica.Icons.Example;
  import Modelica.Constants.pi;
  Sources.SineVoltageVariableFrequencyAndAmplitude sineVoltage(
      useConstantAmplitude=true,                               phi(fixed=true))
  Basic.Ground ground1
  Basic.Resistor resistor1(R=0.5)
  Basic.Inductor inductor1(i(fixed=true), L=0.1/(2*pi))
  Basic.Capacitor capacitor1(v(fixed=true), C=0.001/(2*pi))
  Sensors.CurrentSensor currentSensor1
  Blocks.Sources.Ramp ramp(
    height=200,
    duration=1,
    offset=0,
    startTime=0)
  Sources.CosineVoltageVariableFrequencyAndAmplitude cosineVoltage(
      useConstantAmplitude=true, phi(fixed=true))
  Basic.Ground ground2
  Basic.Resistor resistor2(R=0.5)
  Basic.Inductor inductor2(i(fixed=true), L=0.1/(2*pi))
  Basic.Capacitor capacitor2(v(fixed=true), C=0.001/(2*pi))
  Sensors.CurrentSensor currentSensor2
equation
  connect(sineVoltage.p, inductor1.p)
  connect(inductor1.n, capacitor1.p)
  connect(capacitor1.n, resistor1.p)
  connect(sineVoltage.n, ground1.p)
  connect(currentSensor1.p, resistor1.n)
  connect(ramp.y, sineVoltage.f)
  connect(ground1.p, currentSensor1.n)
  connect(cosineVoltage.p, inductor2.p)
  connect(inductor2.n, capacitor2.p)
  connect(capacitor2.n, resistor2.p)
  connect(cosineVoltage.n, ground2.p)
  connect(currentSensor2.p, resistor2.n)
  connect(ground2.p, currentSensor2.n)
  connect(ramp.y, cosineVoltage.f)
end SeriesResonance;