Simple demo to show behaviour of SaturatingInductor component. This simple circuit uses the saturating inductor which has a changing inductance.

within Modelica.Electrical.Analog.Examples;
model ShowSaturatingInductor
  "Simple demo to show behaviour of SaturatingInductor component"
  extends Modelica.Icons.Example;
  parameter SI.Inductance Lzer=2 "Inductance near current=0";
  parameter SI.Inductance Lnom=1
    "Nominal inductance at Nominal current";
  parameter SI.Current Inom=1 "Nominal current";
  parameter SI.Inductance Linf=0.5 "Inductance at large currents";
  parameter SI.Voltage U=1.25 "Source voltage (peak)";
  parameter SI.Frequency f=1/(2*Modelica.Constants.pi)
    "Source frequency";
  parameter SI.Angle phase=Modelica.Constants.pi/2
    "Source voltage phase shift";
  //output SI.Voltage v "Voltage drop over saturating inductor";
  //output SI.Current i "Current across saturating inductor";
  Modelica.Electrical.Analog.Sources.SineVoltage SineVoltage1(
    V=U,
    phase=phase,
    f=f)
  Modelica.Electrical.Analog.Basic.Ground Ground1
  Modelica.Electrical.Analog.Basic.SaturatingInductor SaturatingInductance1(
    Lzer=Lzer,
    Lnom=Lnom,
    Inom=Inom,
    Linf=Linf,
    i(fixed=true))
  Basic.Inductor Inductance1(L=Lnom, i(fixed=true))
equation
  //v=SaturatingInductance1.v;
  //i=SaturatingInductance1.i;
  connect(SineVoltage1.n, Ground1.p)
  connect(SineVoltage1.n, SaturatingInductance1.n)
  connect(SaturatingInductance1.p, SineVoltage1.p)
  connect(Inductance1.p, SineVoltage1.p)
  connect(Inductance1.n, SineVoltage1.n)
end ShowSaturatingInductor;


Simple demo of a VariableResistor model. It is a simple test circuit for the VariableResistor. The VariableResistor should be compared with R2.

within Modelica.Electrical.Analog.Examples;
model ShowVariableResistor "Simple demo of a VariableResistor model"
   extends Modelica.Icons.Example;

  Modelica.Electrical.Analog.Basic.VariableResistor VariableResistor
  Modelica.Electrical.Analog.Basic.Ground Ground1
  Modelica.Electrical.Analog.Basic.Ground Ground2
  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.Basic.Resistor R4(R=1)
  Modelica.Electrical.Analog.Basic.Resistor R5(R=1)

  Modelica.Electrical.Analog.Sources.SineVoltage SineVoltage1(V=1, f=1)
  Modelica.Blocks.Sources.Ramp Ramp1(height=5, offset=2,
    duration=2)
equation
  connect(R1.n, R2.p)
  connect(R2.n, R3.p)
  connect(R4.n, VariableResistor.p)
  connect(VariableResistor.n, R5.p)
  connect(R3.n, Ground2.p)
  connect(Ground2.p, R5.n)
  connect(SineVoltage1.p, Ground1.p)
  connect(SineVoltage1.n, R1.p)
  connect(SineVoltage1.n, R4.p)
  connect(Ramp1.y, VariableResistor.R)
end ShowVariableResistor;


Simple triac test circuit. The simple TRIAC example shows how the SimpleTriac is used within an alternating current circuit.

within Modelica.Electrical.Analog.Examples;
model SimpleTriacCircuit "Simple triac test circuit"
  extends Modelica.Icons.Example;

  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Basic.Inductor L(L=2e-6, i(start=0, fixed=true),
    p(                                                          v(  start=0)))
  Modelica.Electrical.Analog.Basic.Resistor R(R=10)
  Modelica.Electrical.Analog.Sources.SineVoltage V(V=30, f=10000)
  Modelica.Electrical.Analog.Semiconductors.SimpleTriac simpleTriac(VDRM=400, VRRM=400,
    thyristor1(                                                                         vGK(           start=0)))
  Sources.TrapezoidCurrent                        trapezoidCurrent(
    I=0.005,
    rising=0.000001,
    width=0.000005,
    falling=0.000001,
    nperiod=-1,
    startTime=0.00002,
    period=0.00005)

initial equation
     simpleTriac.thyristor.vControl=0;
    simpleTriac.thyristor1.vControl=0;

equation
  connect(L.n, R.p)
  connect(R.n, V.p)
  connect(V.n, ground.p)
  connect(simpleTriac.p, ground.p)
  connect(simpleTriac.n, L.p)
  connect(trapezoidCurrent.n, simpleTriac.g)
  connect(trapezoidCurrent.p, ground.p)
end SimpleTriacCircuit;


Comparison of 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 SwitchWithArc "Comparison of switch models both with and without arc"

  extends Modelica.Icons.Example;
  Modelica.Blocks.Sources.BooleanPulse booleanPulse(period=1)
  Modelica.Electrical.Analog.Basic.Ground ground1
  Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage1(V=50)
  Modelica.Electrical.Analog.Basic.Inductor inductor1(L=0.1, i(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Resistor resistor1(R=1)
  Modelica.Electrical.Analog.Ideal.IdealClosingSwitch 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(start=0, fixed=true))
  Modelica.Electrical.Analog.Basic.Resistor resistor2(R=1)
  Modelica.Electrical.Analog.Ideal.CloserWithArc switch2(
    dVdt=10000,
    V0=30,
    Vmax=60,
    off(fixed=true))

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(booleanPulse.y, switch1.control)
  connect(booleanPulse.y, switch2.control)
end SwitchWithArc;


Thyristor demonstration example. This is a simple test circuit, to test the behavior of the thyristor model.

within Modelica.Electrical.Analog.Examples;
model ThyristorBehaviourTest "Thyristor demonstration example"
  extends Modelica.Icons.Example;

  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Sources.SineVoltage sineVoltage(          V=30, f=
        10000)
  Modelica.Electrical.Analog.Basic.Resistor resistor(R=10)
  Modelica.Electrical.Analog.Sources.PulseCurrent pulseCurrent(
    width=10,
    period=0.0001,
    startTime=0.00002,
    I=0.005)
  Modelica.Electrical.Analog.Semiconductors.Thyristor thyristor_v4_1(vControl(
        fixed=true),vAK(start=0), vGK(start=0))
  Modelica.Electrical.Analog.Basic.Inductor inductor(L=2e-6, i(start=0, fixed=true))
equation
  connect(sineVoltage.n, ground.p)
  connect(sineVoltage.p, thyristor_v4_1.Anode)
  connect(resistor.p, thyristor_v4_1.Cathode)
  connect(pulseCurrent.n, thyristor_v4_1.Gate)
  connect(resistor.p, pulseCurrent.p)
  connect(resistor.n, inductor.p)
  connect(inductor.n, ground.p)
end ThyristorBehaviourTest;


Compares oLine and tLine splitting lines into trunks. This example shows a way to look at the traveling wave moving along a power line.

within Modelica.Electrical.Analog.Examples.Lines;
model CompareLineTrunks "Compares oLine and tLine splitting lines into trunks"
  extends Modelica.Icons.Example;
  import Modelica.Units.SI;
  import Modelica.Constants.small;
  parameter SI.Resistance Rload=1000 "Load resistance";
  parameter Real r1(final min=small, final unit="Ohm/m")=1e-6 "Resistance per meter";
  parameter Real g1(final min=small, final unit="S/m")=1e-12 "Conductance per meter";
  parameter Real l1(final min=small, final unit="H/m")=1e-6 "Inductance per meter";
  parameter Real c1(final min=small, final unit="F/m")=1e-11 "Capacitance per meter";
  parameter SI.Length len=100e3 "Length of line";
  parameter Integer segsPerTrunk=7 "Segments per trunk";
  parameter SI.Velocity c=1/sqrt(l1*c1) "Speed of EM wave";
  parameter SI.Time td=len/c/4 "Transmission delay";
  parameter SI.Impedance z0=sqrt(l1/c1) "Characteristic impedance for very high frequency";
  Modelica.Blocks.Sources.Ramp ramp(startTime=400e-6, duration=50e-6)
  Modelica.Electrical.Analog.Sources.SignalVoltage srcLump
  Modelica.Electrical.Analog.Basic.Ground ground1
  Modelica.Electrical.Analog.Lines.OLine oLine1(
    N=segsPerTrunk,
    r=r1,
    l=l1,
    g=g1,
    c=c1,
    length=len/4)
  Modelica.Electrical.Analog.Lines.OLine oLine2(
    N=segsPerTrunk,
    r=r1,
    l=l1,
    g=g1,
    c=c1,
    length=len/4)
  Modelica.Electrical.Analog.Lines.OLine oLine3(
    N=segsPerTrunk,
    r=r1,
    l=l1,
    g=g1,
    c=c1,
    length=len/4)
  Modelica.Electrical.Analog.Lines.OLine oLine4(
    N=segsPerTrunk,
    r=r1,
    l=l1,
    g=g1,
    c=c1,
    length=len/4)
  Modelica.Electrical.Analog.Basic.Resistor R1(R=Rload)
  Modelica.Electrical.Analog.Sources.SignalVoltage srcDistr
  Basic.Ground ground2
  Modelica.Electrical.Analog.Lines.TLine tLine1(Z0=z0, TD=td,
    er(start=0),
    v2(start=0))
  Modelica.Electrical.Analog.Lines.TLine tLine2(Z0=z0, TD=td,
    er(start=0),
    v2(start=0))
  Modelica.Electrical.Analog.Lines.TLine tLine3(Z0=z0, TD=td,
    er(start=0),
    v2(start=0))
  Modelica.Electrical.Analog.Lines.TLine tLine4(Z0=z0, TD=td,
    er(start=0),
    v2(start=0))
  Modelica.Electrical.Analog.Basic.Resistor R2(R=Rload)
initial equation
  oLine1.v=zeros(segsPerTrunk);
  oLine1.i=zeros(segsPerTrunk + 1);
  oLine2.v=zeros(segsPerTrunk);
  oLine2.i=zeros(segsPerTrunk + 1);
  oLine3.v=zeros(segsPerTrunk);
  oLine3.i=zeros(segsPerTrunk + 1);
  oLine4.v=zeros(segsPerTrunk);
  oLine4.i=zeros(segsPerTrunk + 1);
equation
  connect(srcLump.v, ramp.y)
  connect(oLine1.p1, srcLump.p)
  connect(tLine1.p1, srcDistr.p)
  connect(srcDistr.n, tLine1.n1)
  connect(oLine1.p2, oLine2.p1)
  connect(oLine2.p2, oLine3.p1)
  connect(oLine3.p2, oLine4.p1)
  connect(oLine4.p2, R1.p)
  connect(srcDistr.v, ramp.y)
  connect(tLine2.n1, tLine1.n2)
  connect(tLine2.p1, tLine1.p2)
  connect(tLine3.n1, tLine2.n2)
  connect(tLine3.p1, tLine2.p2)
  connect(tLine4.n1, tLine3.n2)
  connect(tLine4.p1, tLine3.p2)
  connect(srcLump.n, ground1.p)
  connect(ground1.p, oLine1.p3)
  connect(ground1.p, oLine2.p3)
  connect(ground1.p, oLine3.p3)
  connect(ground1.p, oLine4.p3)
  connect(ground1.p, R1.n)
  connect(tLine4.p2, R2.p)
  connect(tLine4.n2, R2.n)
  connect(srcDistr.n, ground2.p)
  connect(ground2.p, tLine2.n2)
  connect(ground2.p, tLine3.n2)
  connect(ground2.p, tLine4.n2)
  connect(ground2.p, tLine1.n2)
end CompareLineTrunks;


Compare lossless lines with different load. This example compares three lossless lines with different loads.
Inductance per meter (l=250 nH/m) and capacitance per meter (c=100 pF/m) are estimated for an average coaxial cable with characteristic impedance z0=√(l/c)=50 Ω.
The speed of the electromagnetic wave is given by c0=1/√(l*c)=2*108 m/s. Using a cable with a length of len=1 m, we obtain a delay td=len/c0=5 ns.
The sources impress a single voltage pulse with height=10 V and length=td/2, starting at td/2.
Due to the inner resistances of the sources ri=z0 the pulse at the input of the line (v1) has a height of 5 V.
Simulate for 20 ns and compare for each of the lines: v1, v2 and i1, i2.

within Modelica.Electrical.Analog.Examples.Lines;
model CompareLosslessLines
  "Compare lossless lines with different load"
  extends Modelica.Icons.Example;
  import Modelica.Units.SI;
  import Modelica.Constants.small;
  parameter Real l(final min=small, final unit="H/m")=250e-9 "Inductance per meter";
  parameter Real c(final min=small, final unit="F/m")=100e-12 "Capacitance per meter";
  parameter SI.Length len=1 "Length of line";
  parameter SI.Velocity c0=1/sqrt(l*c) "Speed of EM wave";
  parameter SI.Time td=len/c0 "Transmission delay";
  parameter SI.Impedance z0=sqrt(l/c) "Characteristic impedance";
  Sources.SignalVoltage source1
  Basic.Resistor ri1(R=z0)
  Basic.Ground ground1
  Modelica.Electrical.Analog.Lines.TLine line1(Z0=z0, TD=td,
    er(start=0),
    v2(start=0))
  Ideal.Idle load1
  Sources.SignalVoltage source2
  Basic.Resistor ri2(R=z0)
  Basic.Ground ground2
  Modelica.Electrical.Analog.Lines.TLine line2(
    Z0=z0,
    TD=td,
    er(start=0),
    v2(start=0))
  Basic.Resistor load2(R=z0)
  Sources.SignalVoltage source3
  Basic.Ground ground3
  Modelica.Electrical.Analog.Lines.TLine line3(
    Z0=z0,
    TD=td,
    er(start=0),
    v2(start=0))
  Basic.Resistor ri3(R=z0)
  Ideal.Short load3
  Blocks.Sources.Pulse pulse(
    amplitude=10,
    width=50,
    period=td,
    nperiod=1,
    startTime=td/2)
equation
  connect(source1.n, ground1.p)
  connect(source1.n, line1.n1)
  connect(line1.p2, load1.p)
  connect(line1.n2, load1.n)
  connect(source2.n, ground2.p)
  connect(source2.n, line2.n1)
  connect(line2.p2, load2.p)
  connect(line2.n2, load2.n)
  connect(source3.n, ground3.p)
  connect(source3.n, line3.n1)
  connect(line3.p2, load3.p)
  connect(line3.n2, load3.n)
  connect(pulse.y, source2.v)
  connect(pulse.y, source1.v)
  connect(pulse.y, source3.v)
  connect(load1.n, ground1.p)
  connect(load2.n, ground2.p)
  connect(load3.n, ground3.p)
  connect(source1.p, ri1.p)
  connect(ri1.n, line1.p1)
  connect(source2.p, ri2.p)
  connect(ri2.n, line2.p1)
  connect(source3.p, ri3.p)
  connect(ri3.n, line3.p1)
end CompareLosslessLines;


Lightning on a lossless transmission line. This example shows what happens when a lightning hits a transmission line.
We consider a lossless single-phase equivalent circuit with two parts of the transmission line, each 50 km long.
The RMS voltage is 380 kV / √3, the RMS load current is roughly 1090 A.
Realistic parameters of the 380 kV transmission line are used.
Note that after the source starts, the traveling wave arrives at the load 350 µs later.
After 20 ms, a lightning (10/350 µs) with an amplitude of 10 kA hits the transmission line just in the middle.
Note that the traveling wave hits source and load approximately 200 µs after the lightning hits the transmission line.
Plot voltage and current at the load. Without overvoltage protection, the load would be destroyed.
One could compare the results with that obtained by using a transmission line model taking losses into account.

within Modelica.Electrical.Analog.Examples.Lines;
model LightningLosslessTransmissionLine
  "Lightning on a lossless transmission line"
  extends Modelica.Icons.Example;
  import Modelica.Units.SI;
  import Modelica.Constants.small;
  parameter SI.Resistance Rload=200 "Load resistance";
  parameter Real r(final min=small, final unit="Ohm/m")=25e-6 "Resistance per meter";
  parameter Real g(final min=small, final unit="S/m")=15e-12 "Conductance per meter";
  parameter Real l(final min=small, final unit="H/m")=1e-6 "Inductance per meter";
  parameter Real c(final min=small, final unit="F/m")=15e-12 "Capacitance per meter";
  parameter SI.Length len=100e3 "Length of line";
  parameter SI.Velocity c0=1/sqrt(l*c) "Speed of EM wave";
  parameter SI.Time td=len/c0 "Transmission delay";
  parameter SI.Impedance z0=sqrt(l/c) "Characteristic impedance for very high frequency";
  Modelica.Electrical.Analog.Lines.TLine line1(Z0=z0,
    TD=td/2,
    er(start=0),
    v2(start=0))
  Modelica.Electrical.Analog.Lines.TLine line2(Z0=z0,
    TD=td/2,
    er(start=0),
    v2(start=0))
  Sources.SineVoltage source(V=380e3*sqrt(2/3), f=50)
  Basic.Resistor load(R=Rload)
  Basic.Ground ground
  Sources.LightningImpulseCurrent lightningImpulseCurrent(
    approximation=Modelica.Electrical.Analog.Types.ImpulseApproximation.Heidler,
    I=10e3,
    startTime=0.02)
equation
  connect(line1.p1, source.p)
  connect(line2.p2, load.p)
  connect(source.n, ground.p)
  connect(ground.p, load.n)
  connect(source.n, line1.n1)
  connect(line2.n2, load.n)
  connect(line1.n2, lightningImpulseCurrent.p)
  connect(lightningImpulseCurrent.p, line2.n1)
  connect(line1.p2, lightningImpulseCurrent.n)
  connect(lightningImpulseCurrent.n, line2.p1)
  connect(ground.p, lightningImpulseCurrent.p)
end LightningLosslessTransmissionLine;


Lightning on a segmented transmission line. This example shows what happens when a lightning hits a transmission line.
We consider a segmented single-phase equivalent circuit taking losses into account with two parts of the transmission line, each 50 km long.
The RMS voltage is 380 kV / √3, the RMS load current is roughly 1090 A.
Realistic parameters of the 380 kV transmission line are used.
Note that after the source starts, the traveling wave arrives at the load 350 µs later.
After 20 ms, a lightning (10/350 µs) with an amplitude of 10 kA hits the transmission line just in the middle.
Note that the traveling wave hits source and load approximately 200 µs after the lightning hits the transmission line.
Plot voltage and current at the load. Without overvoltage protection, the load would be destroyed.
Note that using a sparse solver saves some simulation time.
Using a lossless transmission line model simulates even much quicker.

within Modelica.Electrical.Analog.Examples.Lines;
model LightningSegmentedTransmissionLine
  "Lightning on a segmented transmission line"
  extends Modelica.Icons.Example;
  import Modelica.Units.SI;
  import Modelica.Constants.small;
  parameter SI.Resistance Rload=200 "Load resistance";
  parameter Real r(final min=small, final unit="Ohm/m")=25e-6 "Resistance per meter";
  parameter Real g(final min=small, final unit="S/m")=15e-12 "Conductance per meter";
  parameter Real l(final min=small, final unit="H/m")=1e-6 "Inductance per meter";
  parameter Real c(final min=small, final unit="F/m")=15e-12 "Capacitance per meter";
  parameter SI.Length len=100e3 "Length of line";
  parameter Integer N=100 "Number of segments";
  Modelica.Electrical.Analog.Lines.OLine line1(
    r=r,
    l=l,
    g=g,
    c=c,
    length=len/2,
    N=N)
  Modelica.Electrical.Analog.Lines.OLine line2(
    r=r,
    l=l,
    g=g,
    c=c,
    length=len/2,
    N=N)
  Sources.SineVoltage source(V=380e3*sqrt(2/3), f=50)
  Basic.Resistor load(R=Rload)
  Basic.Ground ground
  Sources.LightningImpulseCurrent lightningImpulseCurrent(
    approximation=Modelica.Electrical.Analog.Types.ImpulseApproximation.Heidler,
    I=10e3,
    startTime=0.02)
initial equation
  line1.v=zeros(N);
  line1.i=zeros(N + 1);
  line2.v=zeros(N);
  line2.i[2:N + 1]=zeros(N);
equation
  connect(line1.p1, source.p)
  connect(line2.p2, load.p)
  connect(source.n, ground.p)
  connect(ground.p, load.n)
  connect(line1.p2, lightningImpulseCurrent.n)
  connect(lightningImpulseCurrent.n, line2.p1)
  connect(ground.p, lightningImpulseCurrent.p)
  connect(ground.p, line1.p3)
  connect(ground.p, line2.p3)
end LightningSegmentedTransmissionLine;


Examples of line models

within Modelica.Electrical.Analog.Examples;
package Lines "Examples of line models"
  extends Modelica.Icons.ExamplesPackage;
end Lines;


Compares oLine and tLine behaviour. This example shows a comparison of a multi-segment OLine model with the distributed-parameter line model TLine.

within Modelica.Electrical.Analog.Examples.Lines;
model SmoothStep "Compares oLine and tLine behaviour"
  extends Modelica.Icons.Example;
  import Modelica.Units.SI;
  import Modelica.Constants.small;
  parameter SI.Resistance Rload=1000 "Load resistance";
  parameter Real r1(final min=small, final unit="Ohm/m")=1e-6 "Resistance per meter";
  parameter Real g1(final min=small, final unit="S/m")=1e-12 "Conductance per meter";
  parameter Real l1(final min=small, final unit="H/m")=1e-6 "Inductance per meter";
  parameter Real c1(final min=small, final unit="F/m")=1e-11 "Capacitance per meter";
  parameter SI.Length len=100e3 "Length of line";
  parameter Integer N1=1 "Number of lumped segments of oline1";
  parameter Integer N5=5 "Number of lumped segments of oline5";
  parameter Integer N50=50 "Number of lumped segments of oline50";
  parameter SI.Velocity c=1/sqrt(l1*c1) "Speed of EM wave";
  parameter SI.Time  td=len/c "Transmission delay";
  parameter SI.Impedance z0=sqrt(l1/c1) "Characteristic impedance for very high frequency";
  Modelica.Blocks.Sources.Step step(startTime=200e-6)
  Modelica.Blocks.Continuous.FirstOrder firstOrder(T=1e-9, initType=Modelica.Blocks.Types.Init.InitialOutput)
  Modelica.Electrical.Analog.Sources.SignalVoltage sourceV
  Modelica.Electrical.Analog.Basic.Ground groundS
  Modelica.Electrical.Analog.Lines.OLine oLine1(
    N=N1,
    r=r1,
    l=l1,
    g=g1,
    c=c1,
    length=len)
  Modelica.Electrical.Analog.Basic.Resistor R1(R=Rload)
  Modelica.Electrical.Analog.Lines.OLine oLine5(
    r=r1,
    l=l1,
    g=g1,
    c=c1,
    length=len,
    N=N5)
  Modelica.Electrical.Analog.Basic.Resistor R5(R=Rload)
  Modelica.Electrical.Analog.Lines.OLine oLine50(
    r=r1,
    l=l1,
    g=g1,
    c=c1,
    length=len,
    N=N50)
  Modelica.Electrical.Analog.Basic.Resistor R50(R=Rload)
  Modelica.Electrical.Analog.Basic.Ground groundO
  Modelica.Electrical.Analog.Lines.TLine tLine(
    Z0=z0,
    TD=td,
    er(start=0),
    v2(start=0))

  Modelica.Electrical.Analog.Basic.Resistor Rdistr(R=Rload)
  Modelica.Electrical.Analog.Basic.Ground groundT
initial equation
  oLine1.v=zeros(N1);
  oLine1.i=zeros(N1 + 1);
  oLine5.v=zeros(N5);
  oLine5.i=zeros(N5 + 1);
  oLine50.v=zeros(N50);
  oLine50.i=zeros(N50 + 1);
equation
  connect(groundS.p, sourceV.n)
  connect(R5.p, oLine5.p2)
  connect(R5.n, oLine5.p3)
  connect(Rdistr.p, tLine.p2)
  connect(R1.p, oLine1.p2)
  connect(R1.n, oLine1.p3)
  connect(groundT.p, tLine.n2)
  connect(R50.p, oLine50.p2)
  connect(R50.n, oLine50.p3)
  connect(oLine1.p1, sourceV.p)
  connect(oLine5.p1, sourceV.p)
  connect(oLine50.p1, sourceV.p)
  connect(tLine.p1, sourceV.p)
  connect(tLine.n1, groundS.p)
  connect(sourceV.v, firstOrder.y)
  connect(firstOrder.u, step.y)
  connect(Rdistr.n, groundT.p)
  connect(R1.n,groundO. p)
  connect(groundO.p, R50.n)
  connect(groundO.p, R5.n)
end SmoothStep;


Inverting adder. This is an inverting adder.

within Modelica.Electrical.Analog.Examples.OpAmps;
model Adder "Inverting adder"
  extends Modelica.Icons.Example;
  parameter SI.Voltage Vin=5 "Amplitude of input voltage";
  parameter SI.Frequency f=10 "Frequency of input voltage";
  Modelica.Electrical.Analog.Basic.Ground ground
  Sources.SineVoltage vIn1(V=Vin, f=f)
  Sources.ConstantVoltage vIn2(V=Vin)
  Modelica.Electrical.Analog.Sensors.VoltageSensor vOut
  OpAmpCircuits.Add add(p1_2(i(start=0)))
equation
  connect(add.n1, ground.p)
  connect(vIn1.p, add.p1)
  connect(vIn2.p, add.p1_2)
  connect(ground.p, vIn2.n)
  connect(ground.p, vIn1.n)
  connect(add.p2, vOut.n)
  connect(add.n2, vOut.p)
end Adder;


Comparator. This is a comparator. Resistance R1 can be chosen, resistance R2 is defined by the desired reference voltage Vref (between Vn and Vp). The output switches between Vn for input voltage < Vref and Vp for input voltage > Vref.

within Modelica.Electrical.Analog.Examples.OpAmps;
model Comparator "Comparator"
  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 SI.Voltage Vref=0 "Reference voltage";
  parameter Real k=(Vref - Vns)/(Vps - Vns) "Calculated potentiometer ratio to reach Vref";
  parameter SI.Resistance R=1000 "Resistance of potentiometer";
  Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp(Vps=Vps, Vns=
        Vns)
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Sources.TrapezoidVoltage vIn(
    rising=0.2/f,
    width=0.3/f,
    falling=0.2/f,
    period=1/f,
    nperiod=-1,
    startTime=-(vIn.rising + vIn.width/2),
    V=2*Vin,
    offset=-Vin)
  Modelica.Electrical.Analog.Sensors.VoltageSensor vOut
  Modelica.Electrical.Analog.Basic.Potentiometer potentiometer(R=R, rConstant=
       k)
  Modelica.Electrical.Analog.Sources.SupplyVoltage supplyVoltage(Vps=Vps, Vns=
       Vns)
equation
  connect(vIn.p, opAmp.in_p)
  connect(opAmp.out, vOut.p)
  connect(ground.p, vOut.n)
  connect(ground.p, vIn.n)
  connect(potentiometer.contact, opAmp.in_n)
  connect(potentiometer.pin_p, supplyVoltage.pin_p)
  connect(potentiometer.pin_n, supplyVoltage.pin_n)
  connect(ground.p, supplyVoltage.ground)
end Comparator;


Control circuit. This is an analog control circuit with operational amplifiers.

within Modelica.Electrical.Analog.Examples.OpAmps;
model ControlCircuit "Control circuit"
  extends Modelica.Icons.Example;
  parameter SI.Time T1=0.01 "Small time constant";
  parameter SI.Time T2=0.01 "Large time constant";
  parameter SI.Time Ti=T2 "Integral time constant";
  parameter Real kp=T2/(2*T1) "Proportional gain";
  Modelica.Electrical.Analog.Basic.Ground ground
  Sources.StepVoltage stepA(V=10, startTime=0.1)
  OpAmpCircuits.Feedback feedbackA(p1(i(start=0)))
  OpAmpCircuits.PI PIA(
    v2(fixed=true),
    k=kp,
    T=Ti,
    opAmp(v_in(start=0)))
  OpAmpCircuits.FirstOrder firstOrder1A(
    v2(fixed=true),
    T=T1,
    opAmp(v_in(start=0)))
  OpAmpCircuits.Add addA(i1_2(start=0), r(i(start=0)))
  Sources.StepVoltage step1A(V=1, startTime=0.5)
  OpAmpCircuits.FirstOrder firstOrder2A(
    v2(fixed=true),
    T=T2,
    opAmp(v_in(start=0)))
  Blocks.Sources.Step stepB(height=10, startTime=0.1)
  Blocks.Math.Feedback feedbackB
  Blocks.Continuous.PI PIB(
    k=kp,
    T=Ti,
    initType=Modelica.Blocks.Types.Init.InitialOutput)
  Blocks.Continuous.FirstOrder firstOrder1B(T=T1, initType=Modelica.Blocks.Types.Init.InitialOutput)
  Blocks.Math.Add addB
  Blocks.Sources.Step step1B(height=1, startTime=0.5)
  Blocks.Continuous.FirstOrder firstOrder2B(T=T2, initType=Modelica.Blocks.Types.Init.InitialOutput)
equation
  connect(stepA.n, ground.p)
  connect(feedbackA.p2, PIA.p1)
  connect(feedbackA.n2, PIA.n1)
  connect(PIA.p2, firstOrder1A.p1)
  connect(PIA.n2, firstOrder1A.n1)
  connect(stepB.y,feedbackB. u1)
  connect(feedbackB.y,PIB. u)
  connect(PIB.y,firstOrder1B. u)
  connect(firstOrder1B.y, addB.u1)
  connect(addB.y, firstOrder2B.u)
  connect(step1B.y, addB.u2)
  connect(firstOrder2B.y, feedbackB.u2)
  connect(stepA.p, feedbackA.p1_2)
  connect(firstOrder2A.p2, feedbackA.p1)
  connect(ground.p, feedbackA.n1)
  connect(ground.p, step1A.n)
  connect(firstOrder1A.n2, addA.n1)
  connect(firstOrder1A.p2, addA.p1)
  connect(step1A.p, addA.p1_2)
  connect(addA.p2, firstOrder2A.p1)
  connect(addA.n2, firstOrder2A.n1)
end ControlCircuit;


Differential amplifier. This model demonstrates a differential amplifier to attenuate the input voltage to a level that can be handled by the measurement instrument.

within Modelica.Electrical.Analog.Examples.OpAmps;
model DifferentialAmplifier "Differential amplifier"
  extends Modelica.Icons.Example;
  parameter
    Modelica.Electrical.Analog.Examples.OpAmps.OpAmpCircuits.DifferentialAmplifierData
    data "Parameters for source, OpAmp and measurement"
  Modelica.Electrical.Analog.Sources.SineVoltage sourceVoltage1(
    V=sqrt(2/3)*data.VSource,
    phase=1.0471975511966,
    f=data.fSource)
  Modelica.Electrical.Analog.Sources.SineVoltage sourceVoltage2(
    V=sqrt(2/3)*data.VSource,
    phase=-1.0471975511966,
    f=data.fSource)
  Modelica.Electrical.Analog.Basic.Resistor resistanceLoad(R=data.RLoad)
  Modelica.Electrical.Analog.Sensors.VoltageSensor voltageSensorSource
  Modelica.Blocks.Math.Gain gain(k=-1/data.k)
  Modelica.Electrical.Analog.Basic.Resistor resistorGround(R=data.RGround,
    i(start=0, fixed=false))
  Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp(
    V0=data.V0,
    useSupply=true,
    Vps=+data.VSupply,
    Vns=-data.VSupply)
  Modelica.Electrical.Analog.Basic.Resistor resistor1(R=data.R1,
    i(start=0, fixed=false))
  Modelica.Electrical.Analog.Basic.Resistor resistor2(R=data.R2,
    i(start=0, fixed=false))
  Modelica.Electrical.Analog.Basic.Resistor resistor3(R=data.R3)
  Modelica.Electrical.Analog.Basic.Resistor resistor4(R=data.R4)
  Modelica.Electrical.Analog.Sources.ConstantVoltage positiveSupply(V=+data.VSupply)
  Modelica.Electrical.Analog.Sources.ConstantVoltage negativeSupply(V=-data.VSupply)
  Modelica.Electrical.Analog.Basic.Resistor resistanceInstrument(R=data.RInstrument)
  Modelica.Electrical.Analog.Sensors.VoltageSensor voltageSensor
  Modelica.Blocks.Math.RootMeanSquare rootMeanSquare(f=data.fSource)
  Modelica.Electrical.Analog.Basic.Ground ground
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin groundSource
    "Negative electrical pin"
  Modelica.Electrical.Analog.Interfaces.NegativePin groundOpAmp
    "Negative electrical pin"
equation
  connect(voltageSensor.v, rootMeanSquare.u)
  connect(resistor4.n, groundOpAmp)
  connect(groundOpAmp, resistorGround.n)
  connect(groundOpAmp, resistanceInstrument.n)
  connect(groundOpAmp, voltageSensor.n)
  connect(groundOpAmp, positiveSupply.n)
  connect(groundOpAmp, negativeSupply.n)
  connect(negativeSupply.p, opAmp.s_n)
  connect(opAmp.s_p, positiveSupply.p)
  connect(sourceVoltage1.n, groundSource)
  connect(groundSource,sourceVoltage2. n)
  connect(groundSource, resistorGround.p)
  connect(groundSource, ground.p)
  connect(sourceVoltage1.p, resistor1.p)
  connect(sourceVoltage2.p, resistor2.p)
  connect(voltageSensorSource.v, gain.u)
  connect(sourceVoltage2.p, voltageSensorSource.n)
  connect(sourceVoltage1.p, voltageSensorSource.p)
  connect(sourceVoltage1.p, resistanceLoad.p)
  connect(sourceVoltage2.p, resistanceLoad.n)
  connect(resistor3.n, resistanceInstrument.p)
  connect(resistor3.n, voltageSensor.p)
  connect(resistor3.n, opAmp.out)
  connect(resistor1.n, resistor3.p)
  connect(resistor2.n, resistor4.p)
  connect(resistor2.n, opAmp.in_p)
  connect(resistor1.n, opAmp.in_n)
end DifferentialAmplifier;


Differentiating amplifier. This is a (inverting) differentiating amplifier. Resistance R can be chosen, capacitance C is defined by the desired time constant resp. frequency.

within Modelica.Electrical.Analog.Examples.OpAmps;
model Differentiator "Differentiating amplifier"
  extends Modelica.Icons.Example;
  parameter SI.Voltage Vin=5 "Amplitude of input voltage";
  parameter SI.Frequency f=10 "Frequency of input voltage";
  Modelica.Electrical.Analog.Basic.Ground ground
  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
  OpAmpCircuits.Der der_(
    k=2,
    f=f,
    v(fixed=true))
equation
  connect(vIn.p, der_.p1)
  connect(vIn.n, der_.n1)
  connect(der_.n1, ground.p)
  connect(der_.p2, vOut.p)
  connect(der_.n2, vOut.n)
end Differentiator;


High-pass filter. This is a (inverting) high pass filter. Resistance R1 can be chosen, resistance R2 is defined by the desired amplification k, capacitance C is defined by the desired cut-off frequency.

within Modelica.Electrical.Analog.Examples.OpAmps;
model HighPass "High-pass filter"
  extends Modelica.Icons.Example;
  import Modelica.Constants.pi;
  parameter SI.Voltage Vin=5 "Amplitude of input voltage";
  parameter SI.Frequency f=10 "Frequency of input voltage";
  parameter SI.Frequency fG=f/10 "Limiting frequency";
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Sensors.VoltageSensor vOut
  OpAmpCircuits.Derivative derivative(T=1/(2*pi*fG),
    v(fixed=true))
  Sources.TrapezoidVoltage vIn(
    V=Vin,
    rising=0.2/f,
    width=0.3/f,
    falling=0.2/f,
    period=1/f,
    nperiod=-1,
    offset=0,
    startTime=-(vIn.rising + vIn.width/2))
equation
  connect(derivative.n1, ground.p)
  connect(derivative.p2, vOut.p)
  connect(derivative.n2, vOut.n)
  connect(vIn.p, derivative.p1)
  connect(vIn.n, derivative.n1)
end HighPass;


Integrating amplifier. This is an (inverting) integrating amplifier. Resistance R can be chosen, capacitance C is defined by the desired time constant resp. frequency.

within Modelica.Electrical.Analog.Examples.OpAmps;
model Integrator "Integrating amplifier"
  extends Modelica.Icons.Example;
  parameter SI.Voltage Vin=5 "Amplitude of input voltage";
  parameter SI.Frequency f=10 "Frequency of input voltage";
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Sensors.VoltageSensor vOut
  OpAmpCircuits.Integrator integrator(
    k=2,
    f=f,
    v(fixed=true))
  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))
equation
  connect(integrator.n1, ground.p)
  connect(integrator.p2, vOut.p)
  connect(integrator.n2, vOut.n)
  connect(vIn.p, integrator.p1)
  connect(vIn.n, integrator.n1)
end Integrator;


Inverting amplifier. This is an inverting amplifier.

within Modelica.Electrical.Analog.Examples.OpAmps;
model InvertingAmplifier "Inverting amplifier"
  extends Modelica.Icons.Example;
  parameter SI.Voltage Vin=5 "Amplitude of input voltage";
  parameter SI.Frequency f=10 "Frequency of input voltage";
  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
  OpAmpCircuits.Gain gain(k=2)
equation
  connect(vIn.p, gain.p1)
  connect(gain.n1, ground.p)
  connect(gain.n1, vIn.n)
  connect(gain.p2, vOut.n)
  connect(gain.n2, vOut.p)
end InvertingAmplifier;


Inverting Schmitt trigger with hysteresis. This is a (inverting) Schmitt trigger. Resistance R1 can be chosen, resistance R2 is defined by the desired hysteresis. The output gets Vn for input voltage > 0 + vHys and Vp for input voltage < vHys*Vns/Vps.

within Modelica.Electrical.Analog.Examples.OpAmps;
model InvertingSchmittTrigger "Inverting Schmitt trigger with hysteresis"
  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 SI.Voltage vHys=1 "(Positive) hysteresis voltage";
  parameter Real k=vHys/Vps "Auxiliary calculated parameter to be used in R2 calculation";
  parameter SI.Resistance R1=1000 "Arbitrary resistance";
  parameter SI.Resistance R2=(1 - k)/k*R1 "Calculated resistance to reach hysteresis voltage";
  Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp(
    Vps=Vps,
    Vns=Vns,
    out(i(start=0)))
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Sources.TrapezoidVoltage vIn(
    rising=0.2/f,
    width=0.3/f,
    falling=0.2/f,
    period=1/f,
    nperiod=-1,
    startTime=-(vIn.rising + vIn.width/2),
    V=2*Vin,
    offset=-Vin)
  Modelica.Electrical.Analog.Sensors.VoltageSensor vOut
  Modelica.Electrical.Analog.Basic.Resistor r1(R=R1)
  Modelica.Electrical.Analog.Basic.Resistor r2(R=R2)
equation
  connect(r2.n, r1.p)
  connect(ground.p, r1.n)
  connect(opAmp.out, r2.p)
  connect(r2.n, opAmp.in_p)
  connect(vIn.p, opAmp.in_n)
  connect(ground.p, vIn.n)
  connect(ground.p, vOut.n)
  connect(opAmp.out, vOut.p)
end InvertingSchmittTrigger;


LC oscillator. This is an LC oscillator according to:

within Modelica.Electrical.Analog.Examples.OpAmps;
model LCOscillator "LC oscillator"
  extends Modelica.Icons.Example;
  import Modelica.Constants.pi;
  parameter SI.Voltage VAmp=10 "Amplitude of output";
  parameter SI.Frequency f=1000 "Desired frequency";
  parameter Real A=1.001 "Amplification constant: A > 1 amplification, A = 1 pure sinusoidal oscillation, A < 0 damping";
  parameter SI.Inductance L=0.001 "Arbitrary inductance > 0";
  parameter SI.Capacitance C=1/((2*pi*f)^2*L) "Calculated capacitance to reach frequency f";
  parameter SI.Resistance R=10000.0 "Damping resistance";
  parameter SI.Resistance R1=10000.0 "Arbitrary high resistance";
  parameter SI.Resistance R2=(A - 1)*R1 "Calculated resistance to reach amplification A";
  parameter Real gamma=(1 - A)/(2*R*C) "Calculated characteristical parameter";
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp
  Modelica.Electrical.Analog.Basic.Resistor r(R=R)
  Modelica.Electrical.Analog.Basic.Resistor r2(R=R2, i(start=0))
  Modelica.Electrical.Analog.Basic.Resistor r1(R=R1)
  Modelica.Electrical.Analog.Basic.Capacitor c(C=C, v(start=VAmp, fixed=true))
  Modelica.Electrical.Analog.Basic.Inductor l(L=L, i(fixed=true, start=0))
  Modelica.Electrical.Analog.Sensors.VoltageSensor vOut
equation
  connect(opAmp.out, r.p)
  connect(opAmp.out, r2.p)
  connect(r2.n, r1.p)
  connect(r2.n, opAmp.in_n)
  connect(r1.n, ground.p)
  connect(r.n, opAmp.in_p)
  connect(l.n, ground.p)
  connect(r.n, l.p)
  connect(c.p, l.p)
  connect(c.n, l.n)
  connect(ground.p, vOut.n)
  connect(r.n, vOut.p)
end LCOscillator;


Low-pass filter. This is a (inverting) low pass filter. Resistance R1 can be chosen, resistance R2 is defined by the desired amplification k, capacitance C is defined by the desired cut-off frequency.

within Modelica.Electrical.Analog.Examples.OpAmps;
model LowPass "Low-pass filter"
  extends Modelica.Icons.Example;
  import Modelica.Constants.pi;
  parameter SI.Voltage Vin=5 "Amplitude of input voltage";
  parameter SI.Frequency f=10 "Frequency of input voltage";
  parameter SI.Frequency fG=f/10 "Limiting frequency";
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Sensors.VoltageSensor vOut
  OpAmpCircuits.FirstOrder firstOrder(
    T=1/(2*pi*fG), v(fixed=true))
  Sources.TrapezoidVoltage vIn(
    V=Vin,
    rising=0.2/f,
    width=0.3/f,
    falling=0.2/f,
    period=1/f,
    nperiod=-1,
    offset=0,
    startTime=-(vIn.rising + vIn.width/2))
equation
  connect(firstOrder.n1, ground.p)
  connect(firstOrder.p2, vOut.p)
  connect(firstOrder.n2, vOut.n)
  connect(vIn.p, firstOrder.p1)
  connect(vIn.n, firstOrder.n1)
end LowPass;


Multivibrator with Schmitt trigger. This is a Multivibrator with Schmitt trigger according to:

within Modelica.Electrical.Analog.Examples.OpAmps;
model Multivibrator "Multivibrator with Schmitt trigger"
  extends Modelica.Icons.Example;
  parameter SI.Voltage Vps=+15 "Positive supply";
  parameter SI.Voltage Vns=-15 "Negative supply";
  parameter SI.Frequency f=10 "Desired frequency";
  parameter SI.Resistance R1=1000 "Resistance 1 for adjusting the Schmitt trigger voltage level";
  parameter SI.Resistance R2=1000 "Resistance 2 for adjusting the Schmitt trigger voltage level";
  parameter SI.Resistance R=1000 "Arbitrary resistance";
  parameter SI.Capacitance C=1/f/(2*R*log(1 + 2*R1/R2)) "Calculated capacitance to reach the desired frequency f";
  Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp(
    Vps=Vps,
    Vns=Vns,
    homotopyType = Modelica.Blocks.Types.LimiterHomotopy.LowerLimit,
    strict = true)
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Sensors.VoltageSensor vOut
  Modelica.Electrical.Analog.Basic.Resistor r1(R=R1, i(start=0))
  Modelica.Electrical.Analog.Basic.Resistor r2(R=R2)
  Modelica.Electrical.Analog.Basic.Resistor r(R=R)
  Modelica.Electrical.Analog.Basic.Capacitor c(C=C, v(start=1, fixed=true))
equation
  connect(ground.p, r1.n)
  connect(ground.p, vOut.n)
  connect(opAmp.out, vOut.p)
  connect(ground.p, c.n)
  connect(opAmp.out, r.p)
  connect(r.n, opAmp.in_n)
  connect(opAmp.out, r2.p)
  connect(r2.n, opAmp.in_p)
  connect(opAmp.in_p, r1.p)
  connect(r.n, c.p)
end Multivibrator;


Non-inverting amplifier. This is a non inverting amplifier.

within Modelica.Electrical.Analog.Examples.OpAmps;
model NonInvertingAmplifier "Non-inverting amplifier"
  extends Modelica.Icons.Example;
  parameter SI.Voltage Vin=5 "Amplitude of input voltage";
  parameter SI.Frequency f=10 "Frequency of input voltage";
  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
  OpAmpCircuits.Buffer buffer(k=2)
equation
  connect(vIn.n, buffer.n1)
  connect(vIn.p, buffer.p1)
  connect(buffer.p2, vOut.p)
  connect(buffer.n2, vOut.n)
  connect(buffer.n1, ground.p)
end NonInvertingAmplifier;


Examples with operational amplifiers

within Modelica.Electrical.Analog.Examples;
package OpAmps "Examples with operational amplifiers"
  extends Modelica.Icons.ExamplesPackage;
end OpAmps;


Schmitt trigger with hysteresis. This is a (non-inverting) Schmitt trigger. Resistance R1 can be chosen, resistance R2 is defined by the desired hysteresis. The output gets Vp for input voltage > vHys and Vn for input voltage < vHys*Vns/Vps.

within Modelica.Electrical.Analog.Examples.OpAmps;
model SchmittTrigger "Schmitt trigger with hysteresis"
  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 SI.Voltage vHys=1 "(Positive) hysteresis voltage";
  parameter Real k=vHys/Vps "Auxiliary calculated parameter to be used in R2 calculation";
  parameter SI.Resistance R1=1000 "Arbitrary resistance";
  parameter SI.Resistance R2=R1/k "Calculated resistance to reach hysteresis voltage";
  Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp(
    Vps=Vps,
    Vns=Vns,
    out(i(start=0)))
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Sources.TrapezoidVoltage vIn(
    rising=0.2/f,
    width=0.3/f,
    falling=0.2/f,
    period=1/f,
    nperiod=-1,
    startTime=-(vIn.rising + vIn.width/2),
    V=2*Vin,
    offset=-Vin)
  Modelica.Electrical.Analog.Sensors.VoltageSensor vOut
  Modelica.Electrical.Analog.Basic.Resistor r1(R=R1)
  Modelica.Electrical.Analog.Basic.Resistor r2(R=R2)
equation
  connect(ground.p, vIn.n)
  connect(ground.p, vOut.n)
  connect(opAmp.out, vOut.p)
  connect(opAmp.in_n, ground.p)
  connect(opAmp.out, r2.n)
  connect(r2.p, opAmp.in_p)
  connect(r2.p, r1.n)
  connect(r1.p, vIn.p)
end SchmittTrigger;


Rectangle-Triangle generator. This signal generator consists of a Schmitt trigger and an integrator. The output of the Schmitt trigger part opamp (opAmp1) is a rectangular signal with the amplitude VAmp and the frequency f.
The output of the integrator part opamp (opAmp2) is a triangular signal of also the amplitude Vamp and the frequency f.

within Modelica.Electrical.Analog.Examples.OpAmps;
model SignalGenerator "Rectangle-Triangle generator"
  extends Modelica.Icons.Example;
  import Modelica.Constants.pi;
  parameter SI.Voltage Vps=+15 "Positive supply";
  parameter SI.Voltage Vns=-Vps "Negative supply";
  parameter SI.Voltage VAmp=10 "Desired amplitude of output";
  parameter SI.Resistance R1=1000 "Arbitrary resistance for Schmitt trigger part";
  parameter SI.Resistance R2=R1*Vps/VAmp "Calculated resistance for Schmitt trigger to reach VAmp";
  parameter SI.Frequency f=10 "Desired frequency";
  parameter SI.Resistance R=1000 "Arbitrary resistance of integrator part";
  parameter SI.Capacitance C=Vps/VAmp/(4*f*R) "Calculated capacitance of integrator part to reach f";
  Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp1(
    Vps=Vps,
    Vns=Vns,
    strict=false,
    homotopyType=Modelica.Blocks.Types.LimiterHomotopy.LowerLimit)
  Modelica.Electrical.Analog.Basic.Resistor r2(R=R2, i(start=Vps/R2))
  Modelica.Electrical.Analog.Basic.Resistor r1(R=R1)
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp2(
    Vps=Vps,
    Vns=Vns,
    v_in(start=0),
    strict=false)
  Modelica.Electrical.Analog.Basic.Capacitor c(C=C, v(fixed=true, start=0))
  Modelica.Electrical.Analog.Basic.Resistor r(R=R)
  Modelica.Electrical.Analog.Sensors.VoltageSensor vOutRectangle
  Modelica.Electrical.Analog.Sensors.VoltageSensor vOutTriangle
equation
  connect(opAmp1.out, r2.n)
  connect(opAmp1.in_p, r2.p)
  connect(opAmp1.in_n, ground.p)
  connect(opAmp1.out, r.p)
  connect(r.n, c.n)
  connect(c.p, opAmp2.out)
  connect(ground.p, opAmp2.in_p)
  connect(c.n, opAmp2.in_n)
  connect(r2.p, r1.p)
  connect(opAmp2.out, r1.n)
  connect(opAmp1.out, vOutRectangle.p)
  connect(ground.p, vOutRectangle.n)
  connect(opAmp2.out, vOutTriangle.p)
  connect(ground.p, vOutTriangle.n)
end SignalGenerator;


Inverting subtracter. This is an inverting subtracter.

within Modelica.Electrical.Analog.Examples.OpAmps;
model Subtracter "Inverting subtracter"
  extends Modelica.Icons.Example;
  parameter SI.Voltage Vin=5 "Amplitude of input voltage";
  parameter SI.Frequency f=10 "Frequency of input voltage";
  Modelica.Electrical.Analog.Basic.Ground ground
  Sources.SineVoltage vIn1(V=Vin, f=f)
  Sources.ConstantVoltage vIn2(V=Vin)
  Modelica.Electrical.Analog.Sensors.VoltageSensor vOut
  OpAmpCircuits.Feedback feedback(p1_2(i(start=0)))
equation
  connect(feedback.n1, ground.p)
  connect(vIn1.p, feedback.p1)
  connect(vIn2.p, feedback.p1_2)
  connect(ground.p, vIn2.n)
  connect(ground.p, vIn1.n)
  connect(feedback.p2, vOut.n)
  connect(feedback.n2, vOut.p)
end Subtracter;


Reproduce input voltage. This is a voltage follower. It reproduces the input voltage at the output without loading the input voltage source with a stiff output.

within Modelica.Electrical.Analog.Examples.OpAmps;
model VoltageFollower "Reproduce input voltage"
  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 SI.Resistance Ri=1
    "Inner resistance of input voltage source";
  parameter SI.Resistance Rl=1 "Load resistance";
  Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp(
    Vps=Vps,
    Vns=Vns,
    v_in(start=0))
  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 ri(R=Ri)
  Modelica.Electrical.Analog.Basic.Resistor rl(R=Rl)
equation
  connect(ground.p, vIn.n)
  connect(opAmp.out, vOut.p)
  connect(ground.p, vOut.n)
  connect(opAmp.out, opAmp.in_n)
  connect(vIn.p, ri.p)
  connect(ri.n, opAmp.in_p)
  connect(opAmp.out, rl.p)
  connect(ground.p, rl.n)
end VoltageFollower;


Adding operational amplifier circuit. Inverting adder, based on the IdealizedOpAmpLimited model.

within Modelica.Electrical.Analog.Examples.OpAmps.OpAmpCircuits;
model Add "Adding operational amplifier circuit"
  extends PartialOpAmp;
  SI.Voltage v1_2=p1_2.v - n1.v "Voltage drop of port 1_2 (= p1_2.v - n1.v)";
  SI.Current i1_2=p1_2.i "Current flowing from pos. to neg. pin of port 1_2";
  parameter Real k1(final min=0)=1 "Weight of input 1";
  parameter Real k2(final min=0)=1 "Weight of input 2";
  parameter SI.Resistance R=1000 "Resistance at output of OpAmp";
  parameter SI.Resistance R1=R/k1 "Calculated resistance to reach desired weight 1";
  parameter SI.Resistance R2=R/k2 "Calculated resistance to reach desired weight 2";
  Basic.Resistor  r1(final R=R1)
  Basic.Resistor  r2(final R=R2)
  Interfaces.PositivePin p1_2 "Positive electrical pin 1.2"
  Basic.Resistor r(final R=R)
equation
  connect(n1, n2)
  connect(p1, r1.p)
  connect(p1_2, r2.p)
  connect(n1, opAmp.in_p)
  connect(r2.n, opAmp.in_n)
  connect(opAmp.in_n, r1.n)
  connect(opAmp.in_n, r.n)
  connect(opAmp.out, r.p)
  connect(opAmp.out, p2)
end Add;


Non inverting operational amplifier circuit. Non-inverting amplifier = buffer, based on the IdealizedOpAmpLimited model.

within Modelica.Electrical.Analog.Examples.OpAmps.OpAmpCircuits;
model Buffer "Non inverting operational amplifier circuit"
  extends PartialOpAmp;
  parameter Real k(final min=0)=1 "Desired amplification";
  parameter SI.Resistance R1=1000 "Resistance at negative pin(s)";
  parameter SI.Resistance R2=(k - 1)*R1 "Calculated resistance to reach desired amplification k";
  Basic.Resistor                            r1(final R=R1)
  Basic.Resistor                            r2(final R=R2)
equation
  connect(opAmp.out, p2)
  connect(n1, n2)
  connect(n1, r1.n)
  connect(opAmp.out, r2.p)
  connect(r2.n, r1.p)
  connect(r2.n, opAmp.in_n)
  connect(opAmp.in_p, p1)
end Buffer;


Differentiating operational amplifier circuit. Inverting differentiator = der, based on the IdealizedOpAmpLimited model.

within Modelica.Electrical.Analog.Examples.OpAmps.OpAmpCircuits;
model Der "Differentiating operational amplifier circuit"
  extends PartialOpAmp;
  import Modelica.Constants.pi;
  parameter Real k(final min=0)=1 "Desired amplification at frequency f";
  parameter SI.Frequency f "Frequency";
  parameter SI.Resistance R=1000 "Resistance at output of OpAmp";
  parameter SI.Capacitance C=k/(2*pi*f*R) "Calculated capacitance to reach desired amplification k";
  SI.Voltage v(start=0)=c.v "Capacitor voltage = state";
  Basic.Capacitor                            c(final C=C)
  Basic.Resistor                            r(final R=R)
equation
  connect(n1, n2)
  connect(opAmp.out, p2)
  connect(c.n, opAmp.in_n)
  connect(opAmp.in_n, r.n)
  connect(opAmp.out, r.p)
  connect(c.p, p1)
  connect(n1, opAmp.in_p)
end Der;


Lowpass filter operational amplifier circuit. Inverting highpass filter = derivative, based on the IdealizedOpAmpLimited model.

within Modelica.Electrical.Analog.Examples.OpAmps.OpAmpCircuits;
model Derivative "Lowpass filter operational amplifier circuit"
  extends PartialOpAmp;
  import Modelica.Constants.pi;
  parameter Real k(final min=0)=1 "Desired amplification";
  parameter SI.Resistance R1=1000 "Resistance at negative input of OpAmp";
  parameter SI.Resistance R2=k*R1 "Calculated resistance to reach k";
  parameter SI.Time T "Time constant";
  parameter SI.Capacitance C=T/R1 "Calculated capacitance to reach T";
  SI.Voltage v(start=0)=c.v "Capacitor voltage = state";
  Basic.Resistor                            r1(R=R1)
  Basic.Resistor                            r2(R=R2)
  Basic.Capacitor                            c(C=C)
equation
  connect(n1, n2)
  connect(opAmp.out, p2)
  connect(n1, opAmp.in_p)
  connect(r1.n, opAmp.in_n)
  connect(opAmp.in_n, r2.n)
  connect(opAmp.out, r2.p)
  connect(c.n, r1.p)
  connect(c.p, p1)
end Derivative;


Subtracting operational amplifier circuit. Inverting subtracter = feedback, based on the IdealizedOpAmpLimited model.

within Modelica.Electrical.Analog.Examples.OpAmps.OpAmpCircuits;
model Feedback "Subtracting operational amplifier circuit"
  extends PartialOpAmp;
  SI.Voltage v1_2=p1_2.v - n1.v "Voltage drop of port 1_2 (= p1_2.v - n1.v)";
  SI.Current i1_2=p1_2.i "Current flowing from pos. to neg. pin of port 1_2";
  parameter Real k(final min=0)=1 "Desired amplification";
  parameter SI.Resistance R1=1000 "Resistance at inputs of OpAmp";
  parameter SI.Resistance R3=R1/k "Calculated resistance to reach desired amplification k";
  Basic.Resistor                            r1(final R=R1)
  Basic.Resistor                            r2(final R=R1)
  Interfaces.PositivePin p1_2 "Positive electrical pin 1.2"
  Basic.Resistor                            r3(final R=R3)
  Basic.Resistor                            r4(final R=R3)
equation
  connect(n1, n2)
  connect(p1, r1.p)
  connect(r1.n, opAmp.in_n)
  connect(r1.n, r3.n)
  connect(opAmp.out, r3.p)
  connect(opAmp.out, p2)
  connect(p1_2, r2.p)
  connect(r2.n, opAmp.in_p)
  connect(opAmp.in_p, r4.p)
  connect(n1, r4.n)
end Feedback;


Lowpass filter operational amplifier circuit. Inverting lowpass filter = first order, based on the IdealizedOpAmpLimited model.

within Modelica.Electrical.Analog.Examples.OpAmps.OpAmpCircuits;
model FirstOrder "Lowpass filter operational amplifier circuit"
  extends PartialOpAmp(v2(start=0));
  import Modelica.Constants.pi;
  parameter Real k(final min=0)=1 "Desired amplification";
  parameter SI.Resistance R1=1000 "Resistance at negative input of OpAmp";
  parameter SI.Resistance R2=k*R1 "Calculated resistance to reach k";
  parameter SI.Time T "Time constant";
  parameter SI.Capacitance C=T/R2 "Calculated capacitance to reach T";
  SI.Voltage v(start=0)=c.v "Capacitor voltage = state";
  Basic.Resistor                            r1(R=R1)
  Basic.Resistor                            r2(R=R2)
  Basic.Capacitor                            c(C=C)
equation
  connect(n1, n2)
  connect(opAmp.out, p2)
  connect(n1, opAmp.in_p)
  connect(r1.p, p1)
  connect(r1.n, opAmp.in_n)
  connect(opAmp.in_n, r2.n)
  connect(opAmp.in_n, c.n)
  connect(opAmp.out, r2.p)
  connect(opAmp.out, c.p)
end FirstOrder;


Inverting operational amplifier circuit. Inverting amplifier = gain, based on the IdealizedOpAmpLimited model.

within Modelica.Electrical.Analog.Examples.OpAmps.OpAmpCircuits;
model Gain "Inverting operational amplifier circuit"
  extends PartialOpAmp;
  parameter Real k(final min=0)=1 "Desired amplification";
  parameter SI.Resistance R1=1000 "Resistance at negative input of OpAmp";
  parameter SI.Resistance R2=k*R1 "Calculated resistance to reach desired amplification k";
  Basic.Resistor                            r1(final R=R1)
  Basic.Resistor                            r2(final R=R2)
equation
  connect(opAmp.out, r2.p)
  connect(opAmp.out, p2)
  connect(r1.n, opAmp.in_n)
  connect(r1.n, r2.n)
  connect(r1.p, p1)
  connect(n1, opAmp.in_p)
  connect(n1, n2)
end Gain;


Integrating operational amplifier circuit. Inverting integrator, based on the IdealizedOpAmpLimited model.

within Modelica.Electrical.Analog.Examples.OpAmps.OpAmpCircuits;
model Integrator "Integrating operational amplifier circuit"
  extends PartialOpAmp(v2(start=0));
  import Modelica.Constants.pi;
  parameter Real k(final min=0)=1 "Desired amplification at frequency f";
  parameter SI.Frequency f "Frequency";
  parameter SI.Resistance R=1000 "Resistance at negative input of OpAmp";
  parameter SI.Capacitance C=1/k/(2*pi*f*R) "Calculated capacitance to reach desired amplification k";
  SI.Voltage v(start=0)=c.v "Capacitor voltage = state";
  Basic.Capacitor  c(final C=C)
  Basic.Resistor r(final R=R)
equation
  connect(n1, n2)
  connect(opAmp.out, p2)
  connect(n1, opAmp.in_p)
  connect(r.p, p1)
  connect(r.n, opAmp.in_n)
  connect(opAmp.in_n, c.n)
  connect(opAmp.out, c.p)
end Integrator;


within Modelica.Electrical.Analog.Examples.OpAmps;
package OpAmpCircuits "Different circuits with operational amplifiers"
  extends Modelica.Icons.VariantsPackage;
end OpAmpCircuits;


Partial circuit of operational amplifiers. Partial model for operational amplifier circuits, based on the IdealizedOpAmpLimited model.
Different functionality is achieved by different circuits.

within Modelica.Electrical.Analog.Examples.OpAmps.OpAmpCircuits;
partial model PartialOpAmp
  "Partial circuit of operational amplifiers"
  extends Modelica.Electrical.Analog.Interfaces.FourPin;
  parameter SI.Voltage Vps=+15 "Positive supply";
  parameter SI.Voltage Vns=-15 "Negative supply";
  parameter Real V0=15000.0 "No-load amplification";
  Ideal.IdealizedOpAmpLimited opAmp(
    V0=V0,
    final useSupply=false,
    final Vps=Vps,
    final Vns=Vns,
    out(i(start=0, fixed=false)))
end PartialOpAmp;


PI controller operational amplifier circuit. Inverting proportional-integral controller = PI, based on the IdealizedOpAmpLimited model.

within Modelica.Electrical.Analog.Examples.OpAmps.OpAmpCircuits;
model PI "PI controller operational amplifier circuit"
  extends PartialOpAmp(v2(start=0));
  import Modelica.Constants.pi;
  parameter Real k(final min=0)=1 "Desired amplification";
  parameter SI.Resistance R1=1000 "Resistance at negative input of OpAmp";
  parameter SI.Resistance R2=k*R1 "Calculated resistance to reach k";
  parameter SI.Time T "Time constant";
  parameter SI.Capacitance C=T/k/R1 "Calculated capacitance to reach T";
  Basic.Resistor                            r1(R=R1)
  Basic.Resistor                            r2(R=R2)
  Basic.Capacitor                            c(C=C)
equation
  connect(n1, n2)
  connect(opAmp.out, p2)
  connect(n1, opAmp.in_p)
  connect(r1.n, opAmp.in_n)
  connect(opAmp.in_n, r2.n)
  connect(p1, r1.p)
  connect(r2.p, c.n)
  connect(opAmp.out, c.p)
end PI;


Input/output block of a conductance model.

within Modelica.Electrical.Analog.Examples.Utilities;
model Conductor "Input/output block of a conductance model"
  extends Modelica.Blocks.Icons.Block;
  parameter SI.Conductance G=1 "Conductance";
  Modelica.Electrical.Analog.Basic.GeneralCurrentToVoltageAdaptor currentToVoltage1(
      use_pder=false, use_fder=false)
  Modelica.Blocks.Interfaces.RealInput i1(unit="A")
    "Current of left oneport of resistance element"
  Modelica.Blocks.Interfaces.RealOutput v1(unit="V")
    "Voltage generated by the resistance element"
  Modelica.Electrical.Analog.Basic.Conductor conductor(G=G)
  Modelica.Blocks.Interfaces.RealInput i2(unit="A")
    "Current of right oneport of conduction element"
  Modelica.Blocks.Interfaces.RealOutput v2(unit="V")
    "Voltage generated by the resistance element"
  Modelica.Electrical.Analog.Basic.GeneralCurrentToVoltageAdaptor currentToVoltage2(
      use_fder=false, use_pder=false)
  Modelica.Electrical.Analog.Basic.Ground ground
equation

  connect(currentToVoltage1.p, v1)
  connect(currentToVoltage1.f, i1)
  connect(currentToVoltage2.f, i2)
  connect(v2, currentToVoltage2.p)
  connect(currentToVoltage1.pin_p, conductor.p)
  connect(conductor.p, currentToVoltage2.pin_p)
  connect(currentToVoltage1.pin_n, conductor.n)
  connect(conductor.n, currentToVoltage2.pin_n)
  connect(conductor.n, ground.p)
end Conductor;


Input/output block of a direct capacitor model.

within Modelica.Electrical.Analog.Examples.Utilities;
model DirectCapacitor "Input/output block of a direct capacitor model"
  extends Modelica.Blocks.Icons.Block;
  parameter SI.Capacitance C(min=0)=1 "Capacitance";
  Modelica.Electrical.Analog.Basic.Capacitor capacitor(C=C, v(fixed=
          true, start=0))
  Modelica.Electrical.Analog.Sources.SignalCurrent currentSource
  Modelica.Blocks.Interfaces.RealInput iDrive(unit="A")
  Modelica.Electrical.Analog.Basic.GeneralCurrentToVoltageAdaptor currentToVoltage(
      use_pder=true, use_fder=false)
  Modelica.Blocks.Interfaces.RealOutput v(unit="V")
    "Capacitor changes voltage due to current"
  Modelica.Blocks.Interfaces.RealOutput dv(unit="V/s")
    "Capacitor changes voltage due to current"
  Modelica.Blocks.Interfaces.RealInput i(unit="A") "Current to the capacitor"
  Modelica.Electrical.Analog.Basic.Ground ground
equation
  connect(currentToVoltage.f, i)
  connect(currentToVoltage.p, v)
  connect(currentToVoltage.pder, dv)
  connect(iDrive, currentSource.i)
  connect(capacitor.p, currentToVoltage.pin_p)
  connect(capacitor.n, currentToVoltage.pin_n)
  connect(currentSource.p, ground.p)
  connect(ground.p, capacitor.n)
  connect(currentSource.n, capacitor.p)
end DirectCapacitor;


Input/output block of a direct inductor model.

within Modelica.Electrical.Analog.Examples.Utilities;
model DirectInductor "Input/output block of a direct inductor model"
  extends Modelica.Blocks.Icons.Block;
  parameter SI.Inductance L(min=0)=1 "Inductance";
  Modelica.Electrical.Analog.Basic.Inductor inductor(i(fixed=true, start=0), L=
        L)
  Modelica.Electrical.Analog.Sources.SignalVoltage voltageSource
  Modelica.Blocks.Interfaces.RealInput vDrive(unit="V")
  Modelica.Electrical.Analog.Basic.GeneralVoltageToCurrentAdaptor currentToVoltage(
      use_pder=false, use_fder=true)
  Modelica.Blocks.Interfaces.RealOutput i(unit="A")
    "Inductor changes current due to voltage"
  Modelica.Blocks.Interfaces.RealOutput di(unit="A/s")
    "Inductor changes current due to voltage"
  Modelica.Blocks.Interfaces.RealInput v(unit="V") "Voltage to the inductor"
  Modelica.Electrical.Analog.Basic.Ground ground
equation
  connect(vDrive,voltageSource. v)
  connect(voltageSource.n, ground.p)
  connect(voltageSource.p, inductor.p)
  connect(inductor.n, currentToVoltage.pin_p)
  connect(ground.p, currentToVoltage.pin_n)
  connect(currentToVoltage.p, v)
  connect(currentToVoltage.f, i)
  connect(currentToVoltage.fder, di)
end DirectInductor;


Input/output block of an inverse capacitor model.

within Modelica.Electrical.Analog.Examples.Utilities;
model InverseCapacitor "Input/output block of an inverse capacitor model"
  extends Modelica.Blocks.Icons.Block;
  parameter SI.Capacitance C(min=0)=1 "Capacitance";
  Modelica.Electrical.Analog.Basic.Capacitor capacitor(C=C, v(fixed=
          true, start=0))
  Modelica.Electrical.Analog.Basic.GeneralVoltageToCurrentAdaptor voltageToCurrent(
      use_fder=false)
  Modelica.Blocks.Interfaces.RealInput v(unit="V")
    "Voltage to drive the Capacitor"
  Modelica.Blocks.Interfaces.RealInput dv(unit="V/s")
    "Voltage to drive the Capacitor"
  Modelica.Blocks.Interfaces.RealOutput i(unit="A")
    "Current needed to drive the oneport according to v, dv"
  Modelica.Electrical.Analog.Basic.Ground ground
equation

  connect(voltageToCurrent.f, i)
  connect(voltageToCurrent.p, v)
  connect(voltageToCurrent.pder, dv)
  connect(voltageToCurrent.pin_p, capacitor.p)
  connect(ground.p, capacitor.n)
  connect(voltageToCurrent.pin_n, ground.p)
end InverseCapacitor;


Input/output block of an inverse inductor model.

within Modelica.Electrical.Analog.Examples.Utilities;
model InverseInductor "Input/output block of an inverse inductor model"
  extends Modelica.Blocks.Icons.Block;
  parameter SI.Inductance L(min=0)=1 "Inductance";
  Modelica.Electrical.Analog.Basic.Inductor inductor(i(fixed=true, start=0), L=
        L)
  Modelica.Electrical.Analog.Basic.GeneralCurrentToVoltageAdaptor currentToVoltage(
      use_pder=false, use_fder=true)
  Modelica.Blocks.Interfaces.RealInput i(unit="A")
    "Current to drive the Inductor"
  Modelica.Blocks.Interfaces.RealInput di(unit="A/s")
    "Current to drive the Inductor"
  Modelica.Blocks.Interfaces.RealOutput v(unit="V")
    "Voltage needed to drive the oneport according to i, di"
  Modelica.Electrical.Analog.Basic.Ground ground
equation

  connect(currentToVoltage.pin_p, inductor.p)
  connect(ground.p, inductor.n)
  connect(currentToVoltage.pin_n, ground.p)
  connect(i, currentToVoltage.f)
  connect(di, currentToVoltage.fder)
  connect(currentToVoltage.p, v)
end InverseInductor;


CMOS NAND Gate (see Tietze/Schenk, page 157). The nand gate is a basic CMOS building block. It consists of four CMOS transistors.

within Modelica.Electrical.Analog.Examples.Utilities;
model Nand "CMOS NAND Gate (see Tietze/Schenk, page 157)"

  Semiconductors.PMOS TP1(
    W=6.5e-6,
    L=3.1e-6,
    Beta=1.05e-5,
    Vt=-1,
    K2=0.41,
    K5=0.8385,
    dW=-2.5e-6,
    dL=-2.1e-6)
  Semiconductors.PMOS TP2(
    W=6.5e-6,
    L=3.1e-6,
    Beta=1.05e-5,
    Vt=-1,
    K2=0.41,
    K5=0.8385,
    dW=-2.5e-6,
    dL=-2.1e-6)
  Semiconductors.NMOS TN1(
    W=6.5e-6,
    L=3.1e-6,
    Beta=4.1e-5,
    Vt=0.8,
    K2=1.144,
    K5=0.7311,
    dW=-2.5e-6,
    dL=-1.5e-6)
  Semiconductors.NMOS TN2(
    W=6.5e-6,
    L=3.1e-6,
    Beta=4.1e-5,
    Vt=0.8,
    K2=1.144,
    K5=0.7311,
    dW=-2.5e-6,
    dL=-1.5e-6)
  Basic.Capacitor C4(C=0.4e-13)
  Basic.Capacitor C7(C=0.4e-13)
  Basic.Ground Gnd
  Basic.Ground Gnd2
  Basic.Ground Gnd3
  Basic.Ground Gnd6
  Basic.Ground Gnd7
  Basic.Ground Gnd8
  Interfaces.Pin x1
  Interfaces.Pin x2
  Interfaces.Pin Vdd
  Interfaces.Pin y
equation
  connect(TN1.S, TN2.D)
  connect(TN2.B, Gnd.p)
  connect(TN2.D, C7.p)
  connect(TN2.S, Gnd.p)
  connect(TP1.S, TN1.D)
  connect(TP1.G, TN1.G)
  connect(C4.n, Gnd2.p)
  connect(C7.n, Gnd3.p)
  connect(TP2.B, Gnd6.p)
  connect(TN1.B, Gnd7.p)
  connect(TP1.B, Gnd8.p)
  connect(TP2.G, x1)
  connect(TP2.G, TN2.G)
  connect(TN1.G, x2)
  connect(TP2.S, TN1.D)
  connect(TN1.D, C4.p)
  connect(Vdd, TP1.D)
  connect(TP2.D, Vdd)
  connect(C4.p, y)
end Nand;


Chua's resistor. This is the only nonlinear component for Chua's circuit. It is a piecewise linear resistor with both an inner and an outer range, which includes the inner one. The slopes of both ranges are given by parameters. The resistance characteristic is continuous. For Chua's circuit both slopes have to be chosen to be negative.

within Modelica.Electrical.Analog.Examples.Utilities;
model NonlinearResistor "Chua's resistor"
  extends Interfaces.OnePort;

  parameter SI.Conductance Ga "Conductance in inner voltage range";
  parameter SI.Conductance Gb "Conductance in outer voltage range";
  parameter SI.Voltage Ve "Inner voltage range limit";
equation
  i = if (v < -Ve) then Gb*(v + Ve) - Ga*Ve else if (v > Ve) then Gb*(v - Ve)
     + Ga*Ve else Ga*v;
end NonlinearResistor;


within Modelica.Electrical.Analog.Examples;
package Utilities "Utility components used by package Examples"
  extends Modelica.Icons.UtilitiesPackage;
end Utilities;


Ideal switch with resistance. This component is a special kind of a commuting switch which possesses an additional constant resistance. This resistance was necessary in an example. It is not designed for common use.

within Modelica.Electrical.Analog.Examples.Utilities;
model RealSwitch "Ideal switch with resistance"

  Ideal.ControlledIdealTwoWaySwitch S(level=2.5)
  Basic.Resistor R(R=0.01)
  Interfaces.Pin p
  Interfaces.Pin n1
  Interfaces.Pin n2
  Interfaces.Pin control
equation
  connect(p, R.p)
  connect(R.n, S.p)
  connect(n1, S.n1)
  connect(n2, S.n2)
  connect(control, S.control)
end RealSwitch;


Input/output block of a resistance model.

within Modelica.Electrical.Analog.Examples.Utilities;
model Resistor "Input/output block of a resistance model"
  extends Modelica.Blocks.Icons.Block;
  parameter SI.Resistance R=1 "Resistance";
  Modelica.Electrical.Analog.Basic.GeneralVoltageToCurrentAdaptor voltageToCurrent1(
      use_pder=false, use_fder=false)
  Modelica.Blocks.Interfaces.RealInput v1(unit="V")
    "Voltage of left oneport of conduction element"
  Modelica.Blocks.Interfaces.RealOutput i1(unit="A")
    "Current generated by the conduction element"
  Modelica.Electrical.Analog.Basic.Resistor  resistor(R=R)
  Modelica.Blocks.Interfaces.RealInput v2(unit="V")
    "Voltage of right oneport of conduction element"
  Modelica.Blocks.Interfaces.RealOutput i2(unit="A")
    "Current generated by the conduction element"
  Modelica.Electrical.Analog.Basic.GeneralVoltageToCurrentAdaptor voltageToCurrent2(
      use_fder=false, use_pder=false)
  Modelica.Electrical.Analog.Basic.Ground ground
equation

  connect(i1, voltageToCurrent1.f)
  connect(voltageToCurrent2.f, i2)
  connect(voltageToCurrent1.p, v1)
  connect(voltageToCurrent2.p, v2)
  connect(voltageToCurrent1.pin_p, resistor.p)
  connect(resistor.n, voltageToCurrent2.pin_p)
  connect(voltageToCurrent1.pin_n, ground.p)
  connect(ground.p, voltageToCurrent2.pin_n)
end Resistor;


Switched capacitor which can represent a positive or negative resistance. This model is a switched capacitor model without thermal behavior which can represent positive and negative resistances.

within Modelica.Electrical.Analog.Examples.Utilities;
model SwitchedCapacitor "Switched capacitor which can represent a positive or negative resistance"

  parameter SI.Time clock(start=1) "Clock";
  parameter SI.Resistance R(start=1) "Resistance";
  Modelica.Blocks.Sources.BooleanPulse BooleanPulse(period=clock)
  Modelica.Electrical.Analog.Basic.Capacitor Capacitor(C=clock/max(Modelica.Constants.eps*oneOhm,abs(R)))
  Modelica.Electrical.Analog.Ideal.IdealTwoWaySwitch IdealCommutingSwitch1
  Modelica.Electrical.Analog.Ideal.IdealTwoWaySwitch IdealCommutingSwitch2
  Modelica.Electrical.Analog.Basic.Ground Ground1
  Modelica.Electrical.Analog.Basic.Ground Ground2
  Modelica.Electrical.Analog.Interfaces.PositivePin p
  Modelica.Electrical.Analog.Interfaces.NegativePin n
  Modelica.Blocks.Logical.LessEqualThreshold lessEqualThreshold
  Modelica.Blocks.Sources.RealExpression Resistance(y=R)
  Modelica.Blocks.Logical.Not not1
  Modelica.Blocks.Logical.LogicalSwitch logicalSwitch
protected
  constant SI.Resistance oneOhm=1 "Helping constant to satisfy unit check";
equation
  connect(IdealCommutingSwitch1.p, Capacitor.p)
  connect(Capacitor.n, IdealCommutingSwitch2.p)
  connect(IdealCommutingSwitch2.control, BooleanPulse.y)
  connect(Ground1.p, IdealCommutingSwitch1.n2)
  connect(Ground2.p, IdealCommutingSwitch2.n2)
  connect(IdealCommutingSwitch1.n1, p)
  connect(IdealCommutingSwitch2.n1, n)
  connect(Resistance.y, lessEqualThreshold.u)
  connect(logicalSwitch.y, IdealCommutingSwitch1.control)
  connect(logicalSwitch.u3, BooleanPulse.y)
  connect(logicalSwitch.u1, not1.y)
  connect(not1.u, BooleanPulse.y)
  connect(lessEqualThreshold.y, logicalSwitch.u2)
end SwitchedCapacitor;


Transistor with resistance an capacitance. Since the simple bipolar transistor model does not have base or collector resistances both are added in this component. Additionally, a capacity is added to the base pin. See the schematic for more details.  In such a way the transistor model can be enhanced to become more common.

within Modelica.Electrical.Analog.Examples.Utilities;
model Transistor "Transistor with resistance an capacitance"

  Basic.Resistor rtb(R=0.05)
  Basic.Resistor rtc(R=0.1)
  Basic.Capacitor ct(C=1e-10)
  Semiconductors.NPN Tr(
    Bf=50,
    Br=0.1,
    Is=1e-16,
    Vak=0.02,
    Tauf=0.12e-9,
    Taur=5e-9,
    Ccs=1e-12,
    Cje=0.4e-12,
    Cjc=0.5e-12,
    Phie=0.8,
    Me=0.4,
    Phic=0.8,
    Mc=0.333,
    Gbc=1e-15,
    Gbe=1e-15,
    Vt=0.02585,
    UIC=true)
  Basic.Ground Ground1
  Interfaces.Pin c
  Interfaces.Pin b
  Interfaces.Pin e
equation
  connect(rtb.n, Tr.B)
  connect(rtb.n, ct.p)
  connect(ct.n, Ground1.p)
  connect(Tr.C, rtc.p)
  connect(rtc.n, c)
  connect(b, rtb.p)
  connect(Tr.E, e)
end Transistor;


Icon for current sources. Just the common icon for current sources.

within Modelica.Electrical.Analog.Icons;
partial model CurrentSource "Icon for current sources"
end CurrentSource;


Icons for analog electrical models

within Modelica.Electrical.Analog;
package Icons "Icons for analog electrical models"
  extends Modelica.Icons.IconsPackage;

end Icons;


Icon for voltage sources. Just the common icon for voltage sources.

within Modelica.Electrical.Analog.Icons;
partial model VoltageSource "Icon for voltage sources"
end VoltageSource;


Simple n-bit analog to digital converter. Simple analog to digital converter with a variable resolution of n bits.
It converts the input voltage ppin.v-npin.v to an n-vector of type Logic
(9-valued logic according to IEEE 1164 STD_ULOGIC). The input resistance between positive and negative pin is determined by Rin.
Further effects (like input capacities) have to be modeled outside the converter, since this should be a general model.

within Modelica.Electrical.Analog.Ideal;
model AD_Converter "Simple n-bit analog to digital converter"
  import L = Modelica.Electrical.Digital.Interfaces.Logic;
  Modelica.Electrical.Analog.Interfaces.PositivePin p
    "Positive electrical pin (input)"
  Modelica.Electrical.Analog.Interfaces.NegativePin n
    "Negative electrical pin (input)"
  Modelica.Electrical.Digital.Interfaces.DigitalOutput y[N] "Digital output"
  Modelica.Electrical.Digital.Interfaces.DigitalInput trig "Trigger input"
  parameter Integer N(final min=1, start=8)
    "Resolution in bits - output signal width";
  parameter SI.Voltage VRefHigh(start=10) "High reference voltage";
  parameter SI.Voltage VRefLow(final max=VRefHigh, start=0)
    "Low reference voltage";
  parameter SI.Resistance Rin(start=10^6) "Input resistance";
  Integer z(start=0, fixed=true);
  Real u;

initial algorithm
  for i in 1:N loop
    y[i] := L.'X';
  end for;

algorithm
  when (trig == L.'1' or trig == L.'H') then
    z := if u > VRefLow then integer((u - VRefLow)/(VRefHigh - VRefLow)*(2^N
       - 1) + 0.5) else 0;
    for i in 1:N loop
      y[i] := if mod(z, 2) > 0 then L.'1' else L.'0';
      z := div(z, 2);
    end for;
  end when;
equation
  p.v - n.v = u;
  p.i*Rin = u;
  p.i + n.i = 0;
end AD_Converter;


Ideal closing switch with simple arc model. This model is an extension to the IdealClosingSwitch.

within Modelica.Electrical.Analog.Ideal;
model CloserWithArc "Ideal closing switch with simple arc model"
  extends Modelica.Electrical.Analog.Interfaces.IdealSwitchWithArc;
  Modelica.Blocks.Interfaces.BooleanInput control
    "true => p--n connected, false => switch open"
equation
  off = not control;
end CloserWithArc;


Controlled ideal electrical closer with simple arc model. This model is an extension to the ControlledIdealClosingSwitch.

within Modelica.Electrical.Analog.Ideal;
model ControlledCloserWithArc
  "Controlled ideal electrical closer with simple arc model"
  parameter SI.Voltage level=0.5 "Switch level";
  extends Modelica.Electrical.Analog.Interfaces.IdealSwitchWithArc;
  Modelica.Electrical.Analog.Interfaces.Pin control
    "Control pin: control.v > level switch closed, otherwise switch open"
equation
  off = control.v < level;
  control.i = 0;
end ControlledCloserWithArc;


Controlled ideal electrical closer. The switching behaviour of the controlled ideal closing switch is controlled by the control pin: off = control.v < level

For further details, see partial model IdealSwitch.

within Modelica.Electrical.Analog.Ideal;
model ControlledIdealClosingSwitch "Controlled ideal electrical closer"
  parameter SI.Voltage level=0.5 "Switch level";
  extends Modelica.Electrical.Analog.Interfaces.IdealSwitch;
  Modelica.Electrical.Analog.Interfaces.Pin control
    "Control pin: control.v > level switch closed, otherwise switch open"
equation
  off = control.v < level;
  control.i = 0;
end ControlledIdealClosingSwitch;


Controlled ideal intermediate switch. The intermediate switch has four switching contact pins p1, p2, n1, and n2. The switching behaviour is controlled by the control pin. If its voltage exceeds the value of the parameter level, the pin p1 is connected to pin n2, and the pin p2 is connected to the pin n1. Otherwise, the pin p1 is connected to the pin n1, and the pin p2 is connected to the pin n2.

within Modelica.Electrical.Analog.Ideal;
model ControlledIdealIntermediateSwitch
  "Controlled ideal intermediate switch"
  parameter SI.Voltage level=0.5 "Switch level";
  parameter SI.Resistance Ron(final min=0) = 1e-5 "Closed switch resistance";
  parameter SI.Conductance Goff(final min=0) = 1e-5
    "Opened switch conductance";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(final T=
        293.15);
  Interfaces.PositivePin p1
  Interfaces.PositivePin p2
  Interfaces.NegativePin n1
  Interfaces.NegativePin n2
  Interfaces.Pin control "Control pin: if control.v > level p1--n2, p2--n1 connected,
         otherwise p1--n1, p2--n2  connected"
protected
  Real s1(final unit="1");
  Real s2(final unit="1");
  Real s3(final unit="1");
  Real s4(final unit="1") "Auxiliary variables";
  constant SI.Voltage unitVoltage=1
  constant SI.Current unitCurrent=1
equation
  control.i = 0;

  p1.v - n1.v = s1*(if (control.v > level) then unitVoltage else Ron*unitCurrent);
  p2.v - n2.v = s2*(if (control.v > level) then unitVoltage else Ron*unitCurrent);
  p1.v - n2.v = s3*(if (control.v > level) then Ron*unitCurrent else unitVoltage);
  p2.v - n1.v = s4*(if (control.v > level) then Ron*unitCurrent else unitVoltage);

  p1.i = if control.v > level then s1*unitVoltage*Goff + s3*unitCurrent else
    s1*unitCurrent + s3*unitVoltage*Goff;
  p2.i = if control.v > level then s2*unitVoltage*Goff + s4*unitCurrent else
    s2*unitCurrent + s4*unitVoltage*Goff;
  -n1.i = if control.v > level then s1*unitVoltage*Goff + s4*unitCurrent else
    s1*unitCurrent + s4*unitVoltage*Goff;
  -n2.i = if control.v > level then s2*unitVoltage*Goff + s3*unitCurrent else
    s2*unitCurrent + s3*unitVoltage*Goff;

  LossPower = p1.i*p1.v + p2.i*p2.v + n1.i*n1.v + n2.i*n2.v;
end ControlledIdealIntermediateSwitch;


Controlled ideal electrical opener. The switching behaviour of the controlled  ideal opening switch is controlled by the control pin: off = control.v > level

For further details, see partial model IdealSwitch.

within Modelica.Electrical.Analog.Ideal;
model ControlledIdealOpeningSwitch "Controlled ideal electrical opener"
  parameter SI.Voltage level=0.5 "Switch level";
  extends Modelica.Electrical.Analog.Interfaces.IdealSwitch;
  Modelica.Electrical.Analog.Interfaces.Pin control
    "Control pin: control.v > level switch open, otherwise p--n connected"
equation
  off = control.v > level;
  control.i = 0;
end ControlledIdealOpeningSwitch;


Controlled ideal two-way switch. The two-way switch has a positive pin p and two negative pins n1 and n2.
The switching behaviour is controlled
by the control pin. If its voltage exceeds the value of the parameter level,
the pin p is connected with the negative pin n2. Otherwise, the pin p is
connected the negative pin n1.

within Modelica.Electrical.Analog.Ideal;
model ControlledIdealTwoWaySwitch "Controlled ideal two-way switch"
  parameter SI.Voltage level=0.5 "Switch level";
  parameter SI.Resistance Ron(final min=0) = 1e-5 "Closed switch resistance";
  parameter SI.Conductance Goff(final min=0) = 1e-5
    "Opened switch conductance";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(final T=
        293.15);
  Interfaces.PositivePin p
  Interfaces.NegativePin n2
  Interfaces.NegativePin n1
  Interfaces.Pin control
    "Control pin: if control.v > level p--n2 connected, otherwise p--n1 connected"
protected
  Real s1(final unit="1");
  Real s2(final unit="1") "Auxiliary variables";
  constant SI.Voltage unitVoltage=1
  constant SI.Current unitCurrent=1
equation
  control.i = 0;
  0 = p.i + n2.i + n1.i;

  p.v - n1.v = s1*(if (control.v > level) then unitVoltage else Ron*unitCurrent);
  n1.i = -s1*(if (control.v > level) then Goff*unitVoltage else unitCurrent);
  p.v - n2.v = s2*(if (control.v > level) then Ron*unitCurrent else unitVoltage);
  n2.i = -s2*(if (control.v > level) then unitCurrent else Goff*unitVoltage);
  LossPower = p.i*p.v + n1.i*n1.v + n2.i*n2.v;
end ControlledIdealTwoWaySwitch;


Controlled ideal electrical opener with simple arc model. This model is an extension to the ControlledIdealOpeningSwitch.

within Modelica.Electrical.Analog.Ideal;
model ControlledOpenerWithArc
  "Controlled ideal electrical opener with simple arc model"
  parameter SI.Voltage level=0.5 "Switch level";
  extends Modelica.Electrical.Analog.Interfaces.IdealSwitchWithArc;
  Modelica.Electrical.Analog.Interfaces.Pin control
    "Control pin: control.v > level switch open, otherwise p--n connected"
equation
  off = control.v > level;
  control.i = 0;
end ControlledOpenerWithArc;


Simple digital to analog converter. Simple digital to analog converter with a variable input signal width of N bits. The input signal is an N-vector of type Logic (9-valued logic according to IEEE 1164 STD_ULOGIC). The output voltage of value y is generated by an ideal voltage source. The output can only change if the trigger signal trig of type Logic changes to '1' (forced or weak). In this case, the output voltage is calculated in the following way:

within Modelica.Electrical.Analog.Ideal;
model DA_Converter "Simple digital to analog converter"
  import L = Modelica.Electrical.Digital.Interfaces.Logic;
  Modelica.Electrical.Digital.Interfaces.DigitalInput trig "Trigger input"
  Modelica.Electrical.Digital.Interfaces.DigitalInput x[N] "Digital input"
  Modelica.Electrical.Analog.Interfaces.PositivePin p
    "Positive electrical pin (output)"
  Modelica.Electrical.Analog.Interfaces.NegativePin n
    "Negative electrical pin (output)"

  SI.Voltage vout(start=0, fixed=true);
  Real y(start=0, fixed=true);
  parameter Integer N(final min=1, start=8) "Resolution - input signal width";
  parameter SI.Voltage Vref(start=10) "Reference voltage";

algorithm
  when trig == L.'1' or trig == L.'H' then
    y := 0;
    for i in 1:N loop
      y := if (x[i] == L.'1' or x[i] == L.'H') then y + 2^(i - 1) else y;
    end for;
    vout := y*Vref/(2^N - 1);
  end when;

equation
  p.v - n.v = vout;
  p.i + n.i = 0;
end DA_Converter;


Ideal electrical closer. The switching behaviour of the ideal closing switch is controlled by the input signal control: off = not control.

For further details, see partial model IdealSwitch.

within Modelica.Electrical.Analog.Ideal;
model IdealClosingSwitch "Ideal electrical closer"
  extends Modelica.Electrical.Analog.Interfaces.IdealSwitch;
  Modelica.Blocks.Interfaces.BooleanInput control
    "true => p--n connected, false => switch open"
equation
  off = not control;
end IdealClosingSwitch;


Ideal diode. This is an ideal diode, for details see partial model IdealSemiconductor

The diode is conducting if voltage > Vknee.

The diode is locking if current < Vknee*Goff.

within Modelica.Electrical.Analog.Ideal;
model IdealDiode "Ideal diode"
  extends Modelica.Electrical.Analog.Interfaces.IdealSemiconductor;
equation
  off = s < 0;
end IdealDiode;


Ideal GTO thyristor. This is an ideal GTO thyristor or switching transistor, for details see partial model IdealSemiconductor

The GTO thyristor is conducting if voltage > Vknee AND fire = true.

Otherwise, the GTO thyristor is locking.

within Modelica.Electrical.Analog.Ideal;
model IdealGTOThyristor "Ideal GTO thyristor"
  extends Modelica.Electrical.Analog.Interfaces.IdealSemiconductor;
  Modelica.Blocks.Interfaces.BooleanInput fire
equation
  off = s < 0 or not fire;
end IdealGTOThyristor;


Ideal intermediate switch. The intermediate switch has four switching contact pins p1, p2, n1, and n2. The switching behaviour is controlled by the input signal control. If control is true, the pin p1 is connected to the pin n2, and the pin p2 is connected to the pin n1. Otherwise,if control is false, the pin p1 is connected to n1, and the pin p2 is connected to n2.

within Modelica.Electrical.Analog.Ideal;
model IdealIntermediateSwitch "Ideal intermediate switch"
  parameter SI.Resistance Ron(final min=0) = 1e-5 "Closed switch resistance";
  parameter SI.Conductance Goff(final min=0) = 1e-5
    "Opened switch conductance";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(final T=
        293.15);
  Interfaces.PositivePin p1
  Interfaces.PositivePin p2
  Interfaces.NegativePin n1
  Interfaces.NegativePin n2
  Modelica.Blocks.Interfaces.BooleanInput control
    "true => p1--n2, p2--n1 connected, otherwise p1--n1, p2--n2  connected"
protected
  Real s1(final unit="1");
  Real s2(final unit="1");
  Real s3(final unit="1");
  Real s4(final unit="1") "Auxiliary variables";
  constant SI.Voltage unitVoltage=1
  constant SI.Current unitCurrent=1
equation
  p1.v - n1.v = s1*(if control then unitVoltage else Ron*unitCurrent);
  p2.v - n2.v = s2*(if control then unitVoltage else Ron*unitCurrent);
  p1.v - n2.v = s3*(if control then Ron*unitCurrent else unitVoltage);
  p2.v - n1.v = s4*(if control then Ron*unitCurrent else unitVoltage);

  p1.i = if control then s1*unitVoltage*Goff + s3*unitCurrent else
    s1*unitCurrent + s3*unitVoltage*Goff;
  p2.i = if control then s2*unitVoltage*Goff + s4*unitCurrent else
    s2*unitCurrent + s4*unitVoltage*Goff;
  -n1.i = if control then s1*unitVoltage*Goff + s4*unitCurrent else
    s1*unitCurrent + s4*unitVoltage*Goff;
  -n2.i = if control then s2*unitVoltage*Goff + s3*unitCurrent else
    s2*unitCurrent + s3*unitVoltage*Goff;

  LossPower = p1.i*p1.v + p2.i*p2.v + n1.i*n1.v + n2.i*n2.v;
end IdealIntermediateSwitch;


Idealized operational amplifier with limitation. Idealized operational amplifier with saturation:

within Modelica.Electrical.Analog.Ideal;
model IdealizedOpAmpLimited "Idealized operational amplifier with limitation"
  parameter Real V0=15000.0 "No-load amplification";
  parameter Boolean useSupply=false
    "Use supply pins (otherwise constant supply)"
  parameter SI.Voltage Vps=+15 "Positive supply voltage"
  parameter SI.Voltage Vns=-15 "Negative supply voltage"
  parameter Boolean strict=true "= true, if strict limits with noEvent(..)"
  parameter Modelica.Blocks.Types.LimiterHomotopy homotopyType = Modelica.Blocks.Types.LimiterHomotopy.NoHomotopy "Simplified model for homotopy-based initialization"
  SI.Voltage vps "Positive supply voltage";
  SI.Voltage vns "Negative supply voltage";
  SI.Voltage v_in=in_p.v - in_n.v "Input voltage difference";
  SI.Voltage v_out=out.v "Output voltage to ground";
  SI.Power p_in=in_p.v*in_p.i + in_n.v*in_n.i "Input power";
  SI.Power p_out=out.v*out.i "Output power";
  SI.Power p_s=-(p_in + p_out) "Supply power";
  SI.Current i_s=p_s/(vps - vns) "Supply current";
  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
    "Pin of the output port"
  //optional supply pins
  Modelica.Electrical.Analog.Interfaces.PositivePin s_p(final i=+i_s, final v=
       vps) if useSupply "Optional positive supply pin"
  Modelica.Electrical.Analog.Interfaces.NegativePin s_n(final i=-i_s, final v=
       vns) if useSupply "Optional negative supply pin"
protected
  SI.Voltage simplifiedExpr "Simplified expression for homotopy-based initialization";
equation
  if not useSupply then
    vps = Vps;
    vns = Vns;
  end if;
  in_p.i = 0;
  in_n.i = 0;
  simplifiedExpr = (if homotopyType == Modelica.Blocks.Types.LimiterHomotopy.Linear then V0*v_in
                    else if homotopyType == Modelica.Blocks.Types.LimiterHomotopy.UpperLimit then vps
                    else if homotopyType == Modelica.Blocks.Types.LimiterHomotopy.LowerLimit then vns
                    else 0);
  if strict then
    if homotopyType == Modelica.Blocks.Types.LimiterHomotopy.NoHomotopy then
      v_out = smooth(0, noEvent(if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in));
    else
      v_out = homotopy(actual = smooth(0, noEvent(if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in)),
                       simplified=simplifiedExpr);
    end if;
  else
    if homotopyType == Modelica.Blocks.Types.LimiterHomotopy.NoHomotopy then
      v_out = smooth(0, if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in);
    else
      v_out = homotopy(actual = smooth(0, if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in),
                       simplified=simplifiedExpr);
    end if;
  end if;
end IdealizedOpAmpLimited;


Ideal operational amplifier (norator-nullator pair). The ideal OpAmp is a two-port. The left port is fixed to v1=0 and i1=0
(nullator). At the right port both any voltage v2 and any current i2
are possible (norator).

within Modelica.Electrical.Analog.Ideal;
model IdealOpAmp "Ideal operational amplifier (norator-nullator pair)"
  SI.Voltage v1 "Voltage drop over the left port";
  SI.Voltage v2 "Voltage drop over the right port";
  SI.Current i1 "Current flowing from pos. to neg. pin of the left port";
  SI.Current i2 "Current flowing from pos. to neg. pin of the right port";
  Interfaces.PositivePin p1 "Positive pin of the left port"
  Interfaces.NegativePin n1 "Negative pin of the left port"
  Interfaces.PositivePin p2 "Positive pin of the right port"
  Interfaces.NegativePin n2 "Negative pin of the right port"
equation
  v1 = p1.v - n1.v;
  v2 = p2.v - n2.v;
  0 = p1.i + n1.i;
  0 = p2.i + n2.i;
  i1 = p1.i;
  i2 = p2.i;
  v1 = 0;
  i1 = 0;
end IdealOpAmp;


Ideal operational amplifier (norator-nullator pair), but 3 pins. The ideal OpAmp with three pins is of exactly the same behaviour as the ideal
OpAmp with four pins. Only the negative output pin is left out.
Both the input voltage and current are fixed to zero (nullator).
At the output pin both any voltage v2 and any current i2
are possible.

within Modelica.Electrical.Analog.Ideal;
model IdealOpAmp3Pin
  "Ideal operational amplifier (norator-nullator pair), but 3 pins"
  Interfaces.PositivePin in_p "Positive pin of the input port"
  Interfaces.NegativePin in_n "Negative pin of the input port"
  Interfaces.PositivePin out "Output pin"
equation
  in_p.v = in_n.v;
  in_p.i = 0;
  in_n.i = 0;
end IdealOpAmp3Pin;


Ideal operational amplifier with limitation. The ideal OpAmp with limitation behaves like an ideal OpAmp without limitation,
if the output voltage is within the limits VMin and VMax. In this case
the input voltage vin = in_p.v - in_n.v is zero.
If the input voltage vin less than 0, the output voltage is out.v = VMin.
If the input voltage is vin larger than 0, the output voltage is out.v = VMax.

within Modelica.Electrical.Analog.Ideal;
model IdealOpAmpLimited "Ideal operational amplifier with limitation"
  Interfaces.PositivePin in_p "Positive pin of the input port"
  Interfaces.NegativePin in_n "Negative pin of the input port"
  Interfaces.PositivePin out "Output pin"
  Interfaces.PositivePin VMax "Positive output voltage limitation"
  Interfaces.NegativePin VMin "Negative output voltage limitation"
  SI.Voltage vin "Input voltage";
protected
  Real s(start=0, final unit="1") "Auxiliary variable";
  constant SI.Voltage unitVoltage=1

equation
  in_p.i = 0;
  in_n.i = 0;
  VMax.i = 0;
  VMin.i = 0;
  vin = in_p.v - in_n.v;
  in_p.v - in_n.v = unitVoltage*smooth(0, (if s < -1 then s + 1 else if s > 1
     then s - 1 else 0));
  out.v = smooth(0, if s < -1 then VMin.v else if s > 1 then VMax.v else (
    VMax.v - VMin.v)*s/2 + (VMax.v + VMin.v)/2);
end IdealOpAmpLimited;


Ideal electrical opener. The switching behaviour of the ideal opening switch is controlled by the input signal control: off = control.

For further details, see partial model IdealSwitch.

within Modelica.Electrical.Analog.Ideal;
model IdealOpeningSwitch "Ideal electrical opener"
  extends Modelica.Electrical.Analog.Interfaces.IdealSwitch;
  Modelica.Blocks.Interfaces.BooleanInput control
    "true => switch open, false => p--n connected"
equation
  off = control;
end IdealOpeningSwitch;


Ideal thyristor. This is an ideal thyristor, for details see partial model IdealSemiconductor

The thyristor is conducting if voltage > Vknee AND fire = true.

If fire gets false, the current has to fall below Vknee*Goff, then the thyristor gets locking.

within Modelica.Electrical.Analog.Ideal;
model IdealThyristor "Ideal thyristor"
  extends Modelica.Electrical.Analog.Interfaces.IdealSemiconductor;
  Modelica.Blocks.Interfaces.BooleanInput fire
equation
  off = s < 0 or pre(off) and not fire;
end IdealThyristor;


Ideal transformer core with or without magnetization. The ideal transformer is a two-port circuit element;
in case of Boolean parameter considerMagnetization = false it is characterized by the following equations:

within Modelica.Electrical.Analog.Ideal;
model IdealTransformer "Ideal transformer core with or without magnetization"
  extends Modelica.Electrical.Analog.Interfaces.TwoPort;
  parameter Real n(start=1) "Turns ratio primary:secondary voltage";
  parameter Boolean considerMagnetization=false
    "Choice of considering magnetization"
  parameter SI.Inductance Lm1(start=1)
    "Magnetization inductance w.r.t. primary side"
protected
  SI.Current im1 "Magnetization current w.r.t. primary side";
  SI.MagneticFlux psim1 "Magnetic flux w.r.t. primary side";
equation
  im1 = i1 + i2/n;
  if considerMagnetization then
    psim1 = Lm1*im1;
    v1 = der(psim1);
  else
    psim1 = 0;
    im1 = 0;
  end if;
  v1 = n*v2;
end IdealTransformer;


Ideal triac, based on ideal thyristors. This is an ideal triac model based on an ideal thyristor model.

within Modelica.Electrical.Analog.Ideal;
model IdealTriac "Ideal triac, based on ideal thyristors"

  parameter SI.Resistance Ron(final min=0) = 1e-5 "Closed triac resistance";
  parameter SI.Conductance Goff(final min=0) = 1e-5
    "Opened triac conductance";
  parameter SI.Voltage Vknee(
    final min=0,
    start=0) = 0.8 "Threshold voltage for positive and negative phase";

  parameter SI.Resistance Rdis=100 "Resistance of disturbance elimination";
  parameter SI.Capacitance Cdis=0.005 "Capacity of disturbance elimination";

  Modelica.Electrical.Analog.Ideal.IdealThyristor idealThyristor(
    Ron=Ron,
    Goff=Goff,
    Vknee=Vknee)
  Modelica.Electrical.Analog.Ideal.IdealThyristor idealThyristor1(
    Ron=Ron,
    Goff=Goff,
    Vknee=Vknee)
  Modelica.Electrical.Analog.Basic.Resistor resistor(R=Rdis)
  Modelica.Electrical.Analog.Basic.Capacitor capacitor(C=Cdis)
  Modelica.Blocks.Interfaces.BooleanInput fire1 "Gate"
  Modelica.Electrical.Analog.Interfaces.NegativePin n "Cathode"
  Modelica.Electrical.Analog.Interfaces.PositivePin p "Anode"
equation

  connect(idealThyristor.n, capacitor.n)
  connect(capacitor.n, idealThyristor1.p)
  connect(idealThyristor1.n, resistor.p)
  connect(resistor.p, idealThyristor.p)
  connect(resistor.n, capacitor.p)
  connect(idealThyristor1.fire, fire1)
  connect(idealThyristor.fire, fire1)
  connect(n, idealThyristor.p)
  connect(idealThyristor1.p, p)
end IdealTriac;


Ideal two-way switch. The two-way switch has a positive pin p and two negative pins n1 and n2.
The switching behaviour is controlled
by the input signal control. If control is true, the pin p is connected
with the negative pin n2. Otherwise, the pin p is connected to the negative pin n1.

within Modelica.Electrical.Analog.Ideal;
model IdealTwoWaySwitch "Ideal two-way switch"
  parameter SI.Resistance Ron(final min=0) = 1e-5 "Closed switch resistance";
  parameter SI.Conductance Goff(final min=0) = 1e-5
    "Opened switch conductance";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(final T=
        293.15);
  Interfaces.PositivePin p
  Interfaces.NegativePin n2
  Interfaces.NegativePin n1
  Modelica.Blocks.Interfaces.BooleanInput control
    "true => p--n2 connected, false => p--n1 connected"
protected
  Real s1(final unit="1");
  Real s2(final unit="1") "Auxiliary variables";
  constant SI.Voltage unitVoltage=1
  constant SI.Current unitCurrent=1
equation
  0 = p.i + n2.i + n1.i;

  p.v - n1.v = s1*(if control then unitVoltage else Ron*unitCurrent);
  n1.i = -s1*(if control then Goff*unitVoltage else unitCurrent);
  p.v - n2.v = s2*(if control then Ron*unitCurrent else unitVoltage);
  n2.i = -s2*(if control then unitCurrent else Goff*unitVoltage);
  LossPower = p.i*p.v + n1.i*n1.v + n2.i*n2.v;
end IdealTwoWaySwitch;


Idle branch. The model Idle is a simple idle running branch. That means between both pins no current is running. This ideal device is of no influence on the circuit. Therefore, it can be neglected in each case. For purposes of completeness this component is part of the MSL, as an opposite of the short cut.

within Modelica.Electrical.Analog.Ideal;
model Idle "Idle branch"
  extends Interfaces.OnePort;
equation
  i = 0;
end Idle;


Ideal opening switch with simple arc model. This model is an extension to the IdealOpeningSwitch.

within Modelica.Electrical.Analog.Ideal;
model OpenerWithArc "Ideal opening switch with simple arc model"
  extends Modelica.Electrical.Analog.Interfaces.IdealSwitchWithArc;
  Modelica.Blocks.Interfaces.BooleanInput control
    "false => p--n connected, true => switch open"
equation
  off = control;
end OpenerWithArc;


within Modelica.Electrical.Analog;
package Ideal "Ideal electrical elements such as switches, diode, transformer, operational amplifier"

  extends Modelica.Icons.Package;
end Ideal;


Short cut branch. The model Short is a simple short cut branch. That means the voltage drop between both pins is zero. This device could be neglected if both pins are combined to one node. Besides connecting the nodes of both pins this device has no further function.

within Modelica.Electrical.Analog.Ideal;
model Short "Short cut branch"
  extends Interfaces.OnePort;
equation
  v = 0;
end Short;


Base class to measure the absolute value of a pin variable. The AbsoluteSensor is a partial model for converting values that can be calculated from one pin connector into a real valued signal. The special calculation has to be described in the model which inherits the AbsoluteSensor.  It is often used in sensor devices. To be a true sensor the modeller has to take care that the sensor model does not influence the electrical behavior to be measured.

within Modelica.Electrical.Analog.Interfaces;
partial model AbsoluteSensor
  "Base class to measure the absolute value of a pin variable"
  extends Modelica.Icons.RoundSensor;

  Interfaces.PositivePin p "Positive electrical pin"
  Modelica.Blocks.Interfaces.RealOutput y
    "Measured quantity as Real output signal"

end AbsoluteSensor;


Partial model to include a conditional HeatPort in order to describe the power loss via a thermal network. This partial model provides a conditional heating port for the connection to a thermal network.

within Modelica.Electrical.Analog.Interfaces;
partial model ConditionalHeatPort
  "Partial model to include a conditional HeatPort in order to describe the power loss via a thermal network"

  parameter Boolean useHeatPort = false "= true, if heatPort is enabled"
  parameter SI.Temperature T=293.15
    "Fixed device temperature if useHeatPort = false"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heatPort(final T=T_heatPort, final Q_flow=-LossPower) if useHeatPort
    "Conditional heat port"
  SI.Power LossPower "Loss power leaving component via heatPort";
  SI.Temperature T_heatPort "Temperature of heatPort";
equation
  if not useHeatPort then
     T_heatPort = T;
  end if;
end ConditionalHeatPort;


Interface for current sources. The CurrentSource partial model prepares current sources by providing the pins, and the offset and startTime parameters, which are the same at all current sources. The source behavior is taken from Modelica.Blocks signal sources by inheritance and usage of the replaceable possibilities.

within Modelica.Electrical.Analog.Interfaces;
partial model CurrentSource "Interface for current sources"
  extends Modelica.Electrical.Analog.Icons.CurrentSource;
  extends OnePort;
  replaceable Modelica.Blocks.Interfaces.SignalSource signalSource(
      final offset = offset, final startTime=startTime)

  parameter SI.Current offset=0 "Current offset";
  parameter SI.Time startTime=0 "Time offset";
equation
  i = signalSource.y;
end CurrentSource;


Component with two pairs of each two electrical pins. FourPin is a partial model that consists of two pairs of each two electrical pins.

within Modelica.Electrical.Analog.Interfaces;
partial model FourPin "Component with two pairs of each two electrical pins"
  SI.Voltage v1 "Voltage drop of port 1 (= p1.v - n1.v)";
  SI.Voltage v2 "Voltage drop of port 2 (= p2.v - n2.v)";
  SI.Current i1 "Current flowing from pos. to neg. pin of port 1";
  SI.Current i2 "Current flowing from pos. to neg. pin of port 2";
  PositivePin p1 "Positive electrical pin of port 1"
  NegativePin n1 "Negative electrical pin of port 1"
  PositivePin p2 "Positive electrical pin of port 2"
  NegativePin n2 "Negative electrical pin of port 2"
equation
  v1 = p1.v - n1.v;
  v2 = p2.v - n2.v;
  i1 = p1.i;
  i2 = p2.i;
end FourPin;