Ideal semiconductor. This is an ideal semiconductor which is

open (off), if it is reversed biased (voltage drop less than 0)

closed (on), if it is conducting (current > 0).

This is the behaviour if all parameters are exactly zero.

Note, there are circuits, where this ideal description
with zero resistance and zero conductance is not possible.
In order to prevent singularities during switching, the opened
semiconductor has a small conductance Gon
and the closed semiconductor has a low resistance Roff which is default.

within Modelica.Electrical.Analog.Interfaces;
partial model IdealSemiconductor "Ideal semiconductor"
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  parameter SI.Resistance Ron(final min=0) = 1e-5
    "Forward state-on differential resistance (closed resistance)";
  parameter SI.Conductance Goff(final min=0) = 1e-5
    "Backward state-off conductance (opened conductance)";
  parameter SI.Voltage Vknee(final min=0) = 0
    "Forward threshold voltage";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort;
  Boolean off(start=true) "Switching state";
protected
  Real s(start=0, final unit="1")
    "Auxiliary variable for actual position on the ideal diode characteristic";
  /* s = 0: knee point
     s < 0: below knee point, blocking
     s > 0: above knee point, conducting */
  constant SI.Voltage unitVoltage=1
  constant SI.Current unitCurrent=1
equation
  v = s*(if off then unitVoltage else Ron*unitCurrent) + Vknee;
  i = s*(if off then Goff*unitVoltage else unitCurrent) + Goff*Vknee;
  LossPower = v*i;
end IdealSemiconductor;


Ideal electrical switch. The ideal switch has a positive pin p and a negative pin n.
The switching behaviour is controlled by the boolean signal off.
If off is true, pin p is not connected with negative pin n.
Otherwise, pin p is connected with negative pin n.

In order to prevent singularities during switching, the opened
switch has a (very low) conductance Goff
and the closed switch has a (very low) resistance Ron.
The limiting case is also allowed, i.e., the resistance Ron of the
closed switch could be exactly zero and the conductance Goff of the
open switch could be also exactly zero. Note, there are circuits,
where a description with zero Ron or zero Goff is not possible.

Please note:
In case of useHeatPort=true the temperature dependence of the electrical
behavior is not modelled. The parameters are not temperature dependent.

within Modelica.Electrical.Analog.Interfaces;
partial model IdealSwitch "Ideal electrical switch"
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  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);
protected
  Boolean off "Indicates off-state";
  Real s(final unit="1") "Auxiliary variable";
  constant SI.Voltage unitVoltage=1
  constant SI.Current unitCurrent=1
equation
  v = s*(if off then unitVoltage else Ron*unitCurrent);
  i = s*(if off then Goff*unitVoltage else unitCurrent);
  LossPower = v*i;
end IdealSwitch;


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

within Modelica.Electrical.Analog.Interfaces;
partial model IdealSwitchWithArc "Ideal switch with simple arc model"
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  parameter SI.Resistance Ron=1E-5 "Closed switch resistance";
  parameter SI.Conductance Goff=1E-5
    "Opened switch conductance";
  parameter SI.Voltage V0(start=30) "Initial arc voltage";
  parameter SI.VoltageSlope dVdt(start=10E3)
    "Arc voltage slope";
  parameter SI.Voltage Vmax(start=60) "Max. arc voltage";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(final T=293.15);
  Boolean off(start=true) "Indicates off-state (but maybe not quenched)";
protected
  Boolean quenched(start=true, fixed=true)
    "Indicating quenched arc (if switch is off)";
  discrete SI.Time tSwitch(start=-Modelica.Constants.inf, fixed=true)
    "Last switch off time instant";
equation
  when edge(off) then
    tSwitch = time;
  end when;
  quenched = off and (abs(i) <= abs(v)*Goff or pre(quenched));
  if off then
    if quenched then
      i = Goff*v;
    else
      v = min(Vmax, V0 + dVdt*(time - tSwitch))*sign(i);
    end if;
  else
    v = Ron*i;
  end if;
  LossPower = v*i;
end IdealSwitchWithArc;


Component with two electrical pins p and n and current i from p to n. Superclass of elements which have two electrical pins: the positive pin connector p, and the negative pin connector n. It is assumed that the current flowing into pin p is identical to the current flowing out of pin n. This current is provided explicitly as current i.

within Modelica.Electrical.Analog.Interfaces;
partial model OnePort
  "Component with two electrical pins p and n and current i from p to n"
  extends TwoPin;
  SI.Current i "Current flowing from pin p to pin n";
equation
  0 = p.i + n.i;
  i = p.i;
end OnePort;


within Modelica.Electrical.Analog;
package Interfaces "Connectors and partial models for Analog electrical components"
  extends Modelica.Icons.InterfacesPackage;
end Interfaces;


Partial model to include a conditional HeatPort in order to dissipate losses, used for graphical modeling, i.e., for building models by drag-and-drop. This partial model provides a conditional heat port for dissipating losses.

within Modelica.Electrical.Analog.Interfaces;
partial model PartialConditionalHeatPort
  "Partial model to include a conditional HeatPort in order to dissipate losses, used for graphical modeling, i.e., for building models by drag-and-drop"
  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 if useHeatPort
    "Optional port to which dissipated losses are transported in form of heat"
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature fixedTemperature(final T=T) if not useHeatPort
protected
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a internalHeatPort
equation
  connect(heatPort, internalHeatPort)
  connect(fixedTemperature.port, internalHeatPort)
end PartialConditionalHeatPort;


Base class to measure a relative variable between two pins. The RelaticeSensor is a partial model for converting values that can be calculated from two pin connectors into a real valued signal. The special calculation has to be described in the model which inherits the RelativeSensor.  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 RelativeSensor
  "Base class to measure a relative variable between two pins"
  extends Modelica.Icons.RoundSensor;

  Interfaces.PositivePin p "Positive electrical pin"
  Interfaces.NegativePin n "Negative electrical pin"
  Modelica.Blocks.Interfaces.RealOutput y
    "Measured quantity as Real output signal"
end RelativeSensor;


Component with two electrical pins.

within Modelica.Electrical.Analog.Interfaces;
partial model TwoPin "Component with two electrical pins"
  SI.Voltage v "Voltage drop of the two pins (= p.v - n.v)";

  PositivePin p "Positive electrical pin"
  NegativePin n "Negative electrical pin"
equation
  v = p.v - n.v;
end TwoPin;


Component with two electrical ports, including current. TwoPort is a partial model that consists of two ports. Like OnePort each port has two pins. It is assumed that the current flowing into the positive  pin   is identical to the current flowing out of pin n. This currents of each port are  provided explicitly as currents i1 and i2, the voltages respectively as v1 and v2.

within Modelica.Electrical.Analog.Interfaces;
partial model TwoPort
  "Component with two electrical ports, including current"
  extends FourPin;

equation
  0 = p1.i + n1.i;
  0 = p2.i + n2.i;
end TwoPort;


Interface for voltage sources. The VoltageSource partial model prepares voltage sources by providing the pins, and the offset and startTime parameters, which are the same at all voltage 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 VoltageSource "Interface for voltage sources"
  extends Modelica.Electrical.Analog.Icons.VoltageSource;
  extends OnePort;
  replaceable Modelica.Blocks.Interfaces.SignalSource signalSource(
      final offset = offset, final startTime=startTime)
  parameter SI.Voltage offset=0 "Voltage offset";
  parameter SI.Time startTime=0 "Time offset";
equation
  v = signalSource.y;
end VoltageSource;


Multiple OLine. The segment model is part of the multiple line model. It describes one line segment as outlined in the M_OLine description. Using the loop possibilities of Modelica it is formulated by connecting components the number of which depends on the number of lines.

within Modelica.Electrical.Analog.Lines;
model M_OLine "Multiple OLine"

  parameter SI.Length length(final min=Modelica.Constants.small)=
       0.1 "Length of line";
  parameter Integer N(final min=2) = 5 "Number of lumped segments";
  parameter Integer lines(final min=2) = 4 "Number of lines";
protected
  parameter Integer dim_vector_lgc=div(lines*(lines + 1), 2);
public
  parameter Real r[lines](
    each final min=Modelica.Constants.small,
    each unit="Ohm/m") = {4.76e5,1.72e5,1.72e5,1.72e5} "Resistance per meter";

  parameter Real l[dim_vector_lgc](
    each final min=Modelica.Constants.small,
    each unit="H/m") = {5.98e-7,4.44e-7,4.39e-7,3.99e-7,5.81e-7,4.09e-7,
    4.23e-7,5.96e-7,4.71e-7,6.06e-7} "Inductance per meter";

  parameter Real g[dim_vector_lgc](
    each final min=Modelica.Constants.small,
    each unit="S/m") = {8.05e-6,3.42e-5,2.91e-5,1.76e-6,9.16e-6,7.12e-6,
    2.43e-5,5.93e-6,4.19e-5,6.64e-6} "Conductance per meter";

  parameter Real c[dim_vector_lgc](
    each final min=Modelica.Constants.small,
    each unit="F/m") = {2.38e-11,1.01e-10,8.56e-11,5.09e-12,2.71e-11,2.09e-11,
    7.16e-11,1.83e-11,1.23e-10,2.07e-11} "Capacitance per meter";
  parameter Boolean useInternalGround=true "= true if internal ground is used, otherwise use reference pin"
  parameter SI.LinearTemperatureCoefficient alpha_R=0
    "Temperature coefficient of resistance (R_actual = R*(1 + alpha*(heatPort.T - T_ref))";
  parameter SI.LinearTemperatureCoefficient alpha_G=0
    "Temperature coefficient of conductance (G_actual = G/(1 + alpha*(heatPort.T - T_ref))";
  parameter Boolean useHeatPort=false "= true, if heatPort is enabled"
  parameter SI.Temperature T=293.15
    "Fixed device temperature if useHeatPort = false"
  parameter SI.Temperature T_ref=300.15 "Reference temperature";
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heatPort if useHeatPort
  model segment "Multiple line segment model"

    parameter Integer lines(final min=1) = 3 "Number of lines";
    parameter Integer dim_vector_lgc=div(lines*(lines + 1), 2)
      "Length of the vectors for l, g, c";
    Modelica.Electrical.Analog.Interfaces.PositivePin p[lines] "Positive pin"
    Modelica.Electrical.Analog.Interfaces.NegativePin n[lines] "Negative pin"
    Modelica.Electrical.Analog.Interfaces.NegativePin refPin
      "Reference pin"

    parameter Real Cl[dim_vector_lgc]=fill(1, dim_vector_lgc)
      "Capacitance matrix";
    parameter Real Rl[lines]=fill(7, lines) "Resistance matrix";
    parameter Real Ll[dim_vector_lgc]=fill(2, dim_vector_lgc)
      "Inductance matrix";
    parameter Real Gl[dim_vector_lgc]=fill(1, dim_vector_lgc)
      "Conductance matrix";
    parameter SI.LinearTemperatureCoefficient alpha_R
      "Temperature coefficient of resistance (R_actual = R*(1 + alpha*(heatPort.T - T_ref))";
    parameter SI.LinearTemperatureCoefficient alpha_G
      "Temperature coefficient of conductance (G_actual = G/(1 + alpha*(heatPort.T - T_ref))";
    parameter Boolean useHeatPort=false "= true, if heatPort is enabled"
    parameter SI.Temperature T=293.15
      "Fixed device temperature if useHeatPort = false"
    parameter SI.Temperature T_ref "Reference temperature";

    Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heatPort if useHeatPort
    Modelica.Electrical.Analog.Basic.Capacitor C[dim_vector_lgc](C=Cl);
    Modelica.Electrical.Analog.Basic.Resistor R[lines](
      R=Rl,
      T_ref=fill(T_ref, lines),
      alpha=fill(alpha_R, lines),
      useHeatPort=fill(useHeatPort, lines),
      T=fill(T, lines));
    Modelica.Electrical.Analog.Basic.Conductor G[dim_vector_lgc](
      G=Gl,
      T_ref=fill(T_ref, dim_vector_lgc),
      alpha=fill(alpha_G, dim_vector_lgc),
      useHeatPort=fill(useHeatPort, dim_vector_lgc),
      T=fill(T, dim_vector_lgc));
    Modelica.Electrical.Analog.Basic.M_Transformer inductance(N=lines, L=Ll);
    Modelica.Electrical.Analog.Ideal.Short M
  equation
    for j in 1:lines - 1 loop

      connect(R[j].p, p[j]);
      connect(R[j].n, inductance.p[j]);
      connect(inductance.n[j], n[j]);
      connect(inductance.n[j], C[((1 + (j - 1)*lines) - div(((j - 2)*(j - 1)),
        2))].p);
      connect(C[((1 + (j - 1)*lines) - div(((j - 2)*(j - 1)), 2))].n, M.p);
      connect(inductance.n[j], G[((1 + (j - 1)*lines) - div(((j - 2)*(j - 1)),
        2))].p);
      connect(G[((1 + (j - 1)*lines) - div(((j - 2)*(j - 1)), 2))].n, M.p);

      for i in j + 1:lines loop
        connect(inductance.n[j], C[((1 + (j - 1)*lines) - div(((j - 2)*(j - 1)),
          2)) + 1 + i - (j + 1)].p);
        connect(C[((1 + (j - 1)*lines) - div(((j - 2)*(j - 1)), 2)) + 1 + i
           - (j + 1)].n, inductance.n[i]);
        connect(inductance.n[j], G[((1 + (j - 1)*lines) - div(((j - 2)*(j - 1)),
          2)) + 1 + i - (j + 1)].p);
        connect(G[((1 + (j - 1)*lines) - div(((j - 2)*(j - 1)), 2)) + 1 + i
           - (j + 1)].n, inductance.n[i]);

      end for;
    end for;
    connect(R[lines].p, p[lines]);
    connect(R[lines].n, inductance.p[lines]);
    connect(inductance.n[lines], n[lines]);
    connect(inductance.n[lines], C[dim_vector_lgc].p);
    connect(C[dim_vector_lgc].n, M.p);
    connect(inductance.n[lines], G[dim_vector_lgc].p);
    connect(G[dim_vector_lgc].n, M.p);

    if useHeatPort then

      for j in 1:lines - 1 loop
        connect(heatPort, R[j].heatPort);
        connect(heatPort, G[((1 + (j - 1)*lines) - div(((j - 2)*(j - 1)), 2))].heatPort);
        for i in j + 1:lines loop
          connect(heatPort, G[((1 + (j - 1)*lines) - div(((j - 2)*(j - 1)), 2))
             + 1 + i - (j + 1)].heatPort);
        end for;
      end for;
      connect(heatPort, R[lines].heatPort);
      connect(heatPort, G[dim_vector_lgc].heatPort);
    end if;

    connect(M.n, refPin)
  end segment;

  model segment_last "Multiple line last segment model"

    Modelica.Electrical.Analog.Interfaces.PositivePin p[lines] "Positive pin"
    Modelica.Electrical.Analog.Interfaces.NegativePin n[lines] "Negative pin"
    parameter Integer lines(final min=1) = 3 "Number of lines";
    parameter Integer dim_vector_lgc=div(lines*(lines + 1), 2)
      "Length of the vectors for l, g, c";
    parameter Real Rl[lines]=fill(1, lines) "Resistance matrix";
    parameter Real Ll[dim_vector_lgc]=fill(1, dim_vector_lgc)
      "Inductance matrix";
    parameter SI.LinearTemperatureCoefficient alpha_R
      "Temperature coefficient of resistance (R_actual = R*(1 + alpha*(heatPort.T - T_ref))";
    parameter Boolean useHeatPort=false "= true, if HeatPort is enabled"
    parameter SI.Temperature T=293.15
      "Fixed device temperature if useHeatPort = false"
    parameter SI.Temperature T_ref(start=293.15) "Reference temperature";
    Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heatPort if useHeatPort
    Modelica.Electrical.Analog.Basic.Resistor R[lines](
      R=Rl,
      T_ref=fill(T_ref, lines),
      useHeatPort=fill(useHeatPort, lines),
      T=fill(T, lines));
    Modelica.Electrical.Analog.Basic.M_Transformer inductance(N=lines, L=Ll);

  equation
    for j in 1:lines - 1 loop

      connect(p[j], inductance.p[j]);
      connect(inductance.n[j], R[j].p);
      connect(R[j].n, n[j]);

    end for;
    connect(p[lines], inductance.p[lines]);
    connect(inductance.n[lines], R[lines].p);
    connect(R[lines].n, n[lines]);

    if useHeatPort then
      for j in 1:lines - 1 loop
        connect(heatPort, R[j].heatPort);
      end for;
      connect(heatPort, R[lines].heatPort);
    end if;
  end segment_last;

  segment s[N - 1](
    lines=fill(lines, N - 1),
    dim_vector_lgc=fill(dim_vector_lgc, N - 1),
    Rl=fill(r*length/N, N - 1),
    Ll=fill(l*length/N, N - 1),
    Cl=fill(c*length/N, N - 1),
    Gl=fill(g*length/N, N - 1),
    alpha_R=fill(alpha_R, N - 1),
    alpha_G=fill(alpha_G, N - 1),
    T_ref=fill(T_ref, N - 1),
    useHeatPort=fill(useHeatPort, N - 1),
    T=fill(T, N - 1));
  segment s_first(
    lines=lines,
    dim_vector_lgc=dim_vector_lgc,
    Rl=r*length/(2*N),
    Cl=c*length/(N),
    Ll=l*length/(2*N),
    Gl=g*length/(N),
    alpha_R=alpha_R,
    alpha_G=alpha_G,
    T_ref=T_ref,
    useHeatPort=useHeatPort,
    T=T);
  segment_last s_last(
    lines=lines,
    Rl=r*length/(2*N),
    Ll=l*length/(2*N),
    alpha_R=alpha_R,
    T_ref=T_ref,
    useHeatPort=useHeatPort,
    T=T);
  Modelica.Electrical.Analog.Interfaces.PositivePin p[lines] "Positive pin"
  Modelica.Electrical.Analog.Interfaces.NegativePin n[lines] "Negative pin"

  Modelica.Electrical.Analog.Interfaces.NegativePin refPin if not useInternalGround "Reference pin"
  Modelica.Electrical.Analog.Basic.Ground ground if useInternalGround
equation
  connect(p, s_first.p);
  connect(s_first.n, s[1].p);
  for i in 1:N - 2 loop
    connect(s[i].n, s[i + 1].p);
  end for;
  connect(s[N - 1].n, s_last.p);
  connect(s_last.n, n);
  connect(s_first.refPin, refPin);
  connect(s_first.refPin, ground.p);
  for i in 1:N-1 loop
    connect(s[i].refPin, refPin);
    connect(s[i].refPin, ground.p);
  end for;
  if useHeatPort then
    connect(heatPort, s_first.heatPort);
    for i in 1:N - 1 loop
      connect(heatPort, s[i].heatPort);
    end for;
    connect(heatPort, s_last.heatPort);
  end if;
end M_OLine;


Lossy Transmission Line. Like in the picture below, the lossy transmission line OLine is a single-conductor lossy transmission line which consists of segments of lumped resistors and inductors in series and conductor and capacitors that are connected with the reference pin p3. The precision of the model depends on the number N of lumped segments.

within Modelica.Electrical.Analog.Lines;
model OLine "Lossy Transmission Line"
  //extends Interfaces.ThreePol;
  Modelica.Electrical.Analog.Interfaces.Pin p1
  Modelica.Electrical.Analog.Interfaces.Pin p2
  Modelica.Electrical.Analog.Interfaces.Pin p3
  SI.Voltage v13;
  SI.Voltage v23;
  SI.Current i1;
  SI.Current i2;
  parameter Real r(
    final min=Modelica.Constants.small,
    unit="Ohm/m",
    start=1) "Resistance per meter";
  parameter Real l(
    final min=Modelica.Constants.small,
    unit="H/m",
    start=1) "Inductance per meter";
  parameter Real g(
    final min=Modelica.Constants.small,
    unit="S/m",
    start=1) "Conductance per meter";
  parameter Real c(
    final min=Modelica.Constants.small,
    unit="F/m",
    start=1) "Capacitance per meter";
  parameter SI.Length length(final min=Modelica.Constants.small,
      start=1) "Length of line";
  parameter Integer N(final min=1, start=1) "Number of lumped segments";
  parameter SI.LinearTemperatureCoefficient alpha_R=0
    "Temperature coefficient of resistance (R_actual = R*(1 + alpha*(heatPort.T - T_ref))";
  parameter SI.LinearTemperatureCoefficient alpha_G=0
    "Temperature coefficient of conductance (G_actual = G/(1 + alpha*(heatPort.T - T_ref))";
  parameter Boolean useHeatPort=false "= true, if heatPort is enabled"
  parameter SI.Temperature T=293.15
    "Fixed device temperature if useHeatPort = false"
  parameter SI.Temperature T_ref=300.15 "Reference temperature";
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heatPort if useHeatPort
  output SI.Voltage v[N]=G.v "Voltages at the connections of the elements";
  output SI.Current i[N+1]=R.i "Currents at the connections of the elements";
  /*
  The components R[N+1], L[N+1], C[N] and G[N] have been protected in the previous release(s)
  to avoid excessive size of simulation results.
  Voltages and currents at the connections are now mirrored to alias variables
  to be able to initialize and to track travelling waves along the line.
  */
protected
  Modelica.Electrical.Analog.Basic.Resistor R[N + 1](
    R=rm,
    T_ref=fill(T_ref, N + 1),
    alpha=fill(alpha_R, N + 1),
    useHeatPort=fill(useHeatPort, N + 1),
    T=fill(T, N + 1));
  Modelica.Electrical.Analog.Basic.Inductor L[N + 1](L=lm);
  Modelica.Electrical.Analog.Basic.Capacitor C[N](C=fill(c*length/(N), N));
  Modelica.Electrical.Analog.Basic.Conductor G[N](
    G=fill(g*length/(N), N),
    T_ref=fill(T_ref, N),
    alpha=fill(alpha_G, N),
    useHeatPort=fill(useHeatPort, N),
    T=fill(T, N));
  parameter SI.Resistance rm[N + 1]=
  {if i==1 or i==N + 1 then r*length/(N*2) else r*length/N for i in 1:N+1};
  parameter SI.Inductance lm[N + 1]=
  {if i==1 or i==N + 1 then l*length/(N*2) else l*length/N for i in 1:N+1};
equation
  v13 = p1.v - p3.v;
  v23 = p2.v - p3.v;
  i1 = p1.i;
  i2 = p2.i;
  connect(p1, R[1].p);
  for i in 1:N loop
    connect(R[i].n, L[i].p);
    connect(L[i].n, C[i].p);
    connect(L[i].n, G[i].p);
    connect(C[i].n, p3);
    connect(G[i].n, p3);
    connect(L[i].n, R[i + 1].p);
  end for;
  connect(R[N + 1].n, L[N + 1].p);
  connect(L[N + 1].n, p2);
  if useHeatPort then
    for i in 1:N + 1 loop
      connect(heatPort, R[i].heatPort);
    end for;
    for i in 1:N loop
      connect(heatPort, G[i].heatPort);
    end for;
  end if;
end OLine;


within Modelica.Electrical.Analog;
package Lines "Lossy and lossless segmented transmission lines, and LC distributed line models"
  extends Modelica.Icons.Package;
end Lines;


Lossless transmission line with characteristic impedance Z0 and transmission delay TD. Lossless transmission line with characteristic impedance Z0 and transmission delay TD. The lossless transmission line TLine is a two Port.
Both port branches consist of a resistor with characteristic impedance Z0 and a controlled voltage source that takes into consideration the transmission delay TD.
For further details see [Branin1967].
The model parameters can be derived from inductance and capacitance per length (L' resp. C'), i. e. Z0 = sqrt(L' / C').

within Modelica.Electrical.Analog.Lines;
model TLine
  "Lossless transmission line with characteristic impedance Z0 and transmission delay TD"
  extends Modelica.Electrical.Analog.Interfaces.TwoPort;
  parameter Modelica.Units.SI.Resistance Z0(start=1) "Characteristic impedance";
  parameter Modelica.Units.SI.Time TD=0
    "Transmission delay: specify > 0 if F and NL are not given";
  parameter Modelica.Units.SI.Frequency F=0
    "Frequency: specify > 0 if TD is not given";
  parameter Real NL=1/4 "Normalized length: specify if TD is not given";
  Modelica.Units.SI.Voltage es(start=0) "Voltage source of forward travelling wave";
  Modelica.Units.SI.Voltage er(start=0) "Voltage source of reflected wave";
protected
  parameter Modelica.Units.SI.Time TDi=if F > 0 then NL/F else TD
    "Internally used transmission delay";
equation
  assert(Z0 > 0, "Z0 has to be positive");
  assert((F > 0) or (TD > 0), "F or TD has to be positive");
  i1 = (v1 - es)/Z0;
  i2 = (v2 - er)/Z0;
  es = 2*delay(v2, TDi) - delay(er, TDi);
  er = 2*delay(v1, TDi) - delay(es, TDi);
end TLine;


Lossless transmission line with characteristic impedance Z0 and transmission delay TD. Lossless transmission line with characteristic impedance Z0 and transmission delay TD The lossless transmission line TLine1 is a two Port. Both port branches consist of a resistor with characteristic impedance Z0 and a controlled voltage source that takes into consideration the transmission delay TD. For further details see [Branin1967]. The model parameters can be derived from inductance and capacitance per length (L' resp. C'), i. e. Z0 = sqrt(L'/C') and TD = sqrt(L'*C')*length_of_line. Resistance R' and conductance C' per meter are assumed to be zero.

within Modelica.Electrical.Analog.Lines;
model TLine1
  "Lossless transmission line with characteristic impedance Z0 and transmission delay TD"
  extends Modelica.Electrical.Analog.Interfaces.TwoPort;
  extends Modelica.Icons.ObsoleteModel;
  parameter SI.Resistance Z0(start=1)
    "Characteristic impedance";
  parameter SI.Time TD(start=1) "Transmission delay";
  SI.Voltage es(start=0) "Voltage source of forward travelling wave";
  SI.Voltage er(start=0) "Voltage source of reflected wave";
equation
  assert(Z0 > 0, "Z0 has to be positive");
  assert(TD > 0, "TD has to be positive");
  i1 = (v1 - es)/Z0;
  i2 = (v2 - er)/Z0;
  es = 2*delay(v2, TD) - delay(er, TD);
  er = 2*delay(v1, TD) - delay(es, TD);
end TLine1;


Lossless transmission line with characteristic impedance Z0, frequency F and normalized length NL. Lossless transmission line with characteristic impedance Z0, frequency F and normalized length NL The lossless transmission line TLine2 is a two Port. Both port branches consist of a resistor with the value of the characteristic impedance Z0 and a controlled voltage source that takes into consideration the transmission delay. For further details see [Branin1967]. Resistance R' and conductance C' per meter are assumed to be zero. The characteristic impedance Z0 can be derived from inductance and capacitance per length (L' resp. C'), i. e. Z0 = sqrt(L'/C'). The normalized length NL is equal to the length of the line divided by the wavelength corresponding to the frequency F, i. e. the transmission delay TD is the quotient of NL and F.

within Modelica.Electrical.Analog.Lines;
model TLine2
  "Lossless transmission line with characteristic impedance Z0, frequency F and normalized length NL"
  extends Modelica.Electrical.Analog.Interfaces.TwoPort;
  extends Modelica.Icons.ObsoleteModel;
  parameter SI.Resistance Z0(start=1)
    "Characteristic impedance";
  parameter SI.Frequency F(start=1) "Frequency";
  parameter Real NL(start=1) "Normalized length";
  SI.Voltage es(start=0) "Voltage source of forward travelling wave";
  SI.Voltage er(start=0) "Voltage source of reflected wave";
protected
  parameter SI.Time TD=NL/F;
equation
  assert(Z0 > 0, "Z0 has to be positive");
  assert(NL > 0, "NL has to be positive");
  assert(F > 0, "F has to be positive");
  i1 = (v1 - es)/Z0;
  i2 = (v2 - er)/Z0;
  es = 2*delay(v2, TD) - delay(er, TD);
  er = 2*delay(v1, TD) - delay(es, TD);
end TLine2;


Lossless transmission line with characteristic impedance Z0 and frequency F. Lossless transmission line with characteristic impedance Z0 and frequency F The lossless transmission line TLine3 is a two Port. Both port branches consist of a resistor with value of the characteristic impedance Z0 and a controlled voltage source that takes into consideration the transmission delay. For further details see [Branin1967]. Resistance R' and conductance C' per meter are assumed to be zero. The characteristic impedance Z0 can be derived from inductance and capacitance per length (L' resp. C'), i. e. Z0 = sqrt(L'/C'). The length of the line is equal to a quarter of the wavelength corresponding to the frequency F, i. e. the transmission delay is the quotient of 4 and F. In this case, the characteristic impedance is called natural impedance.

within Modelica.Electrical.Analog.Lines;
model TLine3
  "Lossless transmission line with characteristic impedance Z0 and frequency F"
  extends Modelica.Electrical.Analog.Interfaces.TwoPort;
  extends Modelica.Icons.ObsoleteModel;
  parameter SI.Resistance Z0(start=1) "Natural impedance";
  parameter SI.Frequency F(start=1) "Frequency";
  SI.Voltage es(start=0) "Voltage source of forward travelling wave";
  SI.Voltage er(start=0) "Voltage source of reflected wave";
protected
  parameter SI.Time TD=1/F/4;
equation
  assert(Z0 > 0, "Z0 has to be positive");
  assert(F > 0, "F has to be positive");
  i1 = (v1 - es)/Z0;
  i2 = (v2 - er)/Z0;
  es = 2*delay(v2, TD) - delay(er, TD);
  er = 2*delay(v1, TD) - delay(es, TD);
end TLine3;


Lossy RC Line. As can be seen in the picture below, the lossy RC line ULine is a single conductor lossy transmission line which consists of segments of lumped series resistors and capacitors that are connected with the reference pin p3. The precision of the model depends on the number N of lumped segments.
<br>To get a symmetrical line model, the first resistor is cut into two parts (R1 and R_Nplus1). These two new resistors have the half of the resistance of the original resistor.

within Modelica.Electrical.Analog.Lines;
model ULine "Lossy RC Line"
  //extends Interfaces.ThreePol;
  Modelica.Electrical.Analog.Interfaces.Pin p1
  Modelica.Electrical.Analog.Interfaces.Pin p2
  Modelica.Electrical.Analog.Interfaces.Pin p3
  SI.Voltage v13;
  SI.Voltage v23;
  SI.Current i1;
  SI.Current i2;
  parameter Real r(
    final min=Modelica.Constants.small,
    unit="Ohm/m",
    start=1) "Resistance per meter";
  parameter Real c(
    final min=Modelica.Constants.small,
    unit="F/m",
    start=1) "Capacitance per meter";
  parameter SI.Length length(final min=Modelica.Constants.small,
      start=1) "Length of line";
  parameter Integer N(final min=1, start=1) "Number of lumped segments";
  parameter SI.LinearTemperatureCoefficient alpha=0
    "Temperature coefficient of resistance (R_actual = R*(1 + alpha*(heatPort.T - T_ref))";
  parameter Boolean useHeatPort=false "= true, if heatPort is enabled"
  parameter SI.Temperature T=293.15
    "Fixed device temperature if useHeatPort = false"
  parameter SI.Temperature T_ref=300.15 "Reference temperature";
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heatPort if useHeatPort
  Modelica.Electrical.Analog.Basic.Resistor R[N + 1](
    R=rm,
    T_ref=fill(T_ref, N + 1),
    alpha=fill(alpha, N + 1),
    useHeatPort=fill(useHeatPort, N + 1),
    T=fill(T, N + 1));
  Modelica.Electrical.Analog.Basic.Capacitor C[N](C=fill(c*length/(N), N));
protected
   parameter SI.Resistance rm[N + 1]=
  {if i==1 or i==N + 1 then r*length/(N*2) else r*length/N for i in 1:N+1};
equation
  v13 = p1.v - p3.v;
  v23 = p2.v - p3.v;
  i1 = p1.i;
  i2 = p2.i;
  connect(p1, R[1].p);
  for i in 1:N loop
    connect(R[i].n, R[i + 1].p);
  end for;
  for i in 1:N loop
    connect(R[i].n, C[i].p);
  end for;
  for i in 1:N loop
    connect(C[i].n, p3);
  end for;
  connect(R[N + 1].n, p2);
  if useHeatPort then
    for i in 1:N + 1 loop
      connect(heatPort, R[i].heatPort);
    end for;
  end if;
end ULine;


Simple diode with heating port. The simple diode is an electrical one port, where a heat port is added, which is
defined in the Modelica.Thermal library. It consists of the diode itself and a parallel ohmic
resistance R. If useTemperatureDependency is set to true, the diode formula is:

within Modelica.Electrical.Analog.Semiconductors;
model Diode "Simple diode with heating port"
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  parameter SI.Current Ids=1e-6 "Saturation current";
  parameter Boolean useTemperatureDependency = false "= true, if the diode current depends on temperature, otherwise utilizes the voltage equivalent of temperature"
  parameter SI.Voltage Vt=0.04 "Voltage equivalent of temperature (kT/qn)"
  parameter Real Maxexp(final min=Modelica.Constants.small) = 15 "Max. exponent for linear continuation";
  parameter SI.Resistance R=1e8 "Parallel ohmic resistance";
  parameter Real EG=1.11 "Activation energy"
  parameter Real N=1 "Emission coefficient"
  parameter SI.Temperature TNOM=300.15 "Parameter measurement temperature"
  parameter Real XTI=3 "Temperature exponent of saturation current"
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(useHeatPort=useTemperatureDependency);

  SI.Voltage vt_t "Temperature voltage";
  SI.Current id "Diode current";
protected
  SI.Temperature htemp "Auxiliary temperature";
  Real aux;
  Real auxp;
equation
  assert(T_heatPort > 0,"Temperature must be positive");
  htemp = T_heatPort;
  vt_t = k*htemp/q;

  if useTemperatureDependency then
    id = Ids*(exlin(v/(N*vt_t), Maxexp) - 1);
    i = id*pow(htemp/TNOM, XTI/N)*auxp + v/R;
  else
    id = Ids*(exlin(v/Vt, Maxexp) - 1);
    i = smooth(1, id + v/R);
  end if;

  aux = (htemp/TNOM - 1)*EG/(N*vt_t);
  auxp = exp(aux);

  LossPower = i*v;
end Diode;


Improved diode model. This diode model is an improved version of the simple diode model. It includes a series resistance, parallel conductance, and also models reverse breakdown. The model is divided into three parts:

within Modelica.Electrical.Analog.Semiconductors;
model Diode2 "Improved diode model"
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=293.15);
  parameter SI.Voltage Vf = 0.7 "Forward voltage";
  parameter SI.Current Ids = 1e-13 "Reverse saturation current";
  parameter SI.Resistance Rs = 16 "Ohmic resistance";
  parameter SI.Voltage Vt = Modelica.Constants.R * T/Modelica.Constants.F
    "Thermal voltage (kT/q), 0.026 at normal conditions (around 20 degC)"
  parameter Real N = 1 "Emission coefficient";
  parameter SI.Voltage Bv = 100 "Reverse breakdown voltage";
  parameter SI.Conductance Gp = 1e-6
    "Parallel conductance for numerical stability";
  SI.Voltage vd "Voltage across pure diode part";
  SI.Current id "Diode current";
protected
  SI.Voltage VdMax=Vf + (N*Vt_applied) "Linear continuation threshold";
  SI.Current iVdMax=Ids*(exp(VdMax/(N*Vt_applied)) - 1) "Current at threshold";
  SI.Conductance diVdMax=Ids*exp(VdMax/(N*Vt_applied))/(N*Vt_applied) "Conductance at threshold";
  SI.Voltage Vt_applied;
equation
  Vt_applied = if useHeatPort then Modelica.Constants.R * T_heatPort/Modelica.Constants.F else Vt;
  id = smooth(1,
    if vd < -Bv / 2 then
       -Ids * (exp(-(vd+Bv)/(N*Vt_applied)) + 1 - 2*exp(-Bv/(2*N*Vt_applied)))
    elseif vd < VdMax then
      Ids * (exp(vd/(N*Vt_applied)) - 1)
    else
      iVdMax + (vd - VdMax) * diVdMax);
      //Lower half of reverse biased region including breakdown.
      //Upper half of reverse biased region, and forward biased region before conduction.
      //Forward biased region after conduction

  v = vd + id * Rs;
  i = id + v*Gp;
  LossPower=i*v;

  assert(Bv>0, "Bv must be greater than zero");
  assert(Vf>0, "Vf must be greater than zero");
  assert(Vt>0, "Vt must be greater than zero");
end Diode2;


Simple NMOS transistor with heating port. The NMOS model is a simple model of a n-channel metal-oxide semiconductor FET. It differs slightly from the device used in the SPICE simulator. For more details please care for [Spiro1990].

 A heating port is added for thermal electric simulation. The heating port is defined in the Modelica.Thermal library.

The model does not consider capacitances. A high drain-source resistance RDS is included to avoid numerical difficulties.

within Modelica.Electrical.Analog.Semiconductors;
model NMOS "Simple NMOS transistor with heating port"

        Modelica.Electrical.Analog.Interfaces.Pin D "Drain"
        Modelica.Electrical.Analog.Interfaces.Pin G "Gate"
        Modelica.Electrical.Analog.Interfaces.Pin S "Source"
        Modelica.Electrical.Analog.Interfaces.Pin B "Bulk"
        parameter SI.Length W=20.e-6 "Width";
        parameter SI.Length L=6.e-6 "Length";
        parameter SI.Transconductance Beta=0.041e-3 "Transconductance parameter";
        parameter SI.Voltage Vt=0.8 "Zero bias threshold voltage";
        parameter Real K2=1.144 "Bulk threshold parameter";
        parameter Real K5=0.7311 "Reduction of pinch-off region";
        parameter SI.Length dW=-2.5e-6 "Narrowing of channel";
        parameter SI.Length dL=-1.5e-6 "Shortening of channel";
        parameter SI.Resistance RDS=1e7 "Drain-Source-Resistance";
  parameter Boolean useTemperatureDependency = false "= true, if parameters Beta, K2 and Vt depend on temperature"
  parameter SI.Temperature Tnom=300.15 "Parameter measurement temperature"
  parameter Real kvt=-6.96e-3 "Fitting parameter for Vt"
  parameter Real kk2=6e-4 "Fitting parameter for K2"
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(useHeatPort=useTemperatureDependency);
protected
        Real v;
        Real uds;
        Real ubs;
        Real ugst;
        Real ud;
        Real us;
        Real id;
        Real gds;
        Real beta_t;
        Real vt_t;
        Real k2_t;
equation
  assert(L + dL > 0, "NMOS: Effective length must be positive");
  assert(W + dW > 0, "NMOS: Effective width must be positive");
  assert(T_heatPort > 0,"NMOS: Temperature must be positive");
        gds = if (RDS < 1e-20 and RDS > -1e-20) then 1e20 else 1/RDS;
        v = beta_t*(W + dW)/(L + dL);
        ud = smooth(0,if (D.v < S.v) then S.v else D.v);
        us = smooth(0,if (D.v < S.v) then D.v else S.v);
        uds = ud - us;
        ubs = smooth(0,if (B.v > us) then 0 else B.v - us);
        ugst = (G.v - us - vt_t + k2_t*ubs)*K5;
        id = smooth(0,if (ugst <= 0) then uds*gds else if (ugst > uds) then v*uds*(
          ugst - uds/2) + uds*gds else v*ugst*ugst/2 + uds*gds);

  beta_t = if useTemperatureDependency then Beta*pow((T_heatPort/Tnom), -1.5) else Beta;
  vt_t = if useTemperatureDependency then Vt*(1 + (T_heatPort - Tnom)*kvt) else Vt;
  k2_t = if useTemperatureDependency then K2*(1 + (T_heatPort - Tnom)*kk2) else K2;

        G.i = 0;
        D.i = smooth(0,if (D.v < S.v) then -id else id);
        S.i = smooth(0,if (D.v < S.v) then id else -id);
        B.i = 0;
        LossPower = D.i*(D.v - S.v);
end NMOS;


Simple NPN BJT according to Ebers-Moll with heating port. This model is a simple model of a bipolar NPN junction transistor according to Ebers-Moll.

A heating port is added for thermal electric simulation. The heating port is defined in the Modelica.Thermal library.

A typical parameter set is (the parameter Vt is no longer used):

within Modelica.Electrical.Analog.Semiconductors;
model NPN "Simple NPN BJT according to Ebers-Moll with heating port"
        parameter Real Bf=50 "Forward beta";
        parameter Real Br=0.1 "Reverse beta";
        parameter SI.Current Is=1e-16 "Transport saturation current";
        parameter SI.InversePotential Vak=0.02 "Early voltage (inverse), 1/Volt";
        parameter SI.Time Tauf=0.12e-9 "Ideal forward transit time";
        parameter SI.Time Taur=5e-9 "Ideal reverse transit time";
        parameter SI.Capacitance Ccs=1e-12 "Collector-substrate(ground) cap.";
        parameter SI.Capacitance Cje=0.4e-12 "Base-emitter zero bias depletion cap.";
        parameter SI.Capacitance Cjc=0.5e-12 "Base-coll. zero bias depletion cap.";
        parameter SI.Voltage Phie=0.8 "Base-emitter diffusion voltage";
        parameter Real Me=0.4 "Base-emitter gradation exponent";
        parameter SI.Voltage Phic=0.8 "Base-collector diffusion voltage";
        parameter Real Mc=0.333 "Base-collector gradation exponent";
        parameter SI.Conductance Gbc=1e-15 "Base-collector conductance";
        parameter SI.Conductance Gbe=1e-15 "Base-emitter conductance";
        parameter Real EMin=-100 "If x < EMin, the exp(x) function is linearized";
        parameter Real EMax=40 "If x > EMax, the exp(x) function is linearized";
  parameter Boolean useTemperatureDependency = false "= true, if parameters Bf, Br, Is and Vt depend on temperature"
  parameter SI.Voltage Vt=0.02585 "Voltage equivalent of temperature"
  parameter SI.Temperature Tnom=300.15 "Parameter measurement temperature"
  parameter Real XTI=3 "Temperature exponent for effect on Is"
  parameter Real XTB=0 "Forward and reverse beta temperature exponent"
  parameter SI.Voltage EG=1.11 "Energy gap for temperature effect on Is"
        parameter Real NF=1.0 "Forward current emission coefficient";
        parameter Real NR=1.0 "Reverse current emission coefficient";
  parameter SI.Voltage IC=0 "Initial value of collector to substrate voltage"
  parameter Boolean UIC = false "Decision if initial value IC should be used";
  parameter Boolean useSubstrate = false "= false, if substrate is implicitly grounded";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(useHeatPort=useTemperatureDependency);

        SI.Voltage vbc "Base-collector voltage";
        SI.Voltage vbe "Base-emitter voltage";
  SI.Voltage vcs "Collector-substrate voltage";
        Real qbk "Relative majority carrier charge, inverse";
        SI.Current ibc "Base-collector diode current";
        SI.Current ibe "Base-emitter diode current";
        SI.Capacitance cbc "Total base-collector capacitance";
        SI.Capacitance cbe "Total base-emitter capacitance";
        SI.Capacitance Capcje "Effective base-emitter depletion capacitance";
        SI.Capacitance Capcjc "Effective base-collector depletion capacitance";
        SI.Current is_t "Temperature dependent transport saturation current";
        Real br_t "Temperature dependent forward beta";
        Real bf_t "Temperature dependent reverse beta";
        SI.Voltage vt_t "Voltage equivalent of effective temperature";
        Real hexp "Auxiliary quantity temperature dependent exponent";
        Real htempexp "Auxiliary quantity exp(hexp)";
  SI.Voltage vS "Substrate potential";
  SI.Current iS "Substrate current";

        Modelica.Electrical.Analog.Interfaces.Pin C "Collector"
        Modelica.Electrical.Analog.Interfaces.Pin B "Base"
        Modelica.Electrical.Analog.Interfaces.Pin E "Emitter"
  Modelica.Electrical.Analog.Interfaces.NegativePin S(final i = iS, final v = vS) if useSubstrate "Substrate"
initial equation
  if UIC then
    vcs = IC;
  end if;
equation
        assert(T_heatPort > 0,"Temperature must be positive");
        vbc = B.v - C.v;
        vbe = B.v - E.v;
  vcs = C.v - vS;
        qbk = 1 - vbc*Vak;

        hexp = (T_heatPort/Tnom - 1)*EG/vt_t;
        htempexp = smooth(1, exlin2(hexp, EMin, EMax));

  is_t = if useTemperatureDependency then Is*pow(T_heatPort/Tnom, XTI)*htempexp else Is;
  br_t = if useTemperatureDependency then Br*pow(T_heatPort/Tnom, XTB) else Br;
  bf_t = if useTemperatureDependency then Bf*pow(T_heatPort/Tnom, XTB) else Bf;
  vt_t = if useTemperatureDependency then (k/q)*T_heatPort else Vt;

        ibc = smooth(1, is_t*(exlin2(vbc/(NR*vt_t), EMin, EMax) - 1) + vbc*Gbc);
        ibe = smooth(1, is_t*(exlin2(vbe/(NF*vt_t), EMin, EMax) - 1) + vbe*Gbe);
        Capcjc = smooth(1, Cjc*powlin(vbc/Phic, Mc));
        Capcje = smooth(1, Cje*powlin(vbe/Phie, Me));
        cbc = smooth(1, Taur*is_t/(NR*vt_t)*exlin2(vbc/(NR*vt_t), EMin, EMax) + Capcjc);
        cbe = smooth(1, Tauf*is_t/(NF*vt_t)*exlin2(vbe/(NF*vt_t), EMin, EMax) + Capcje);
  C.i = (ibe - ibc)*qbk - ibc/br_t - cbc*der(vbc) - iS;
        B.i = ibe/bf_t + ibc/br_t + cbc*der(vbc) + cbe*der(vbe);
  E.i = -B.i - C.i - iS;
  iS = -Ccs * der(vcs);
  if not useSubstrate then
    vS = 0;
  end if;
  LossPower = vbc*ibc/br_t + vbe*ibe/bf_t + (ibe - ibc)*qbk*(C.v - E.v);
end NPN;


within Modelica.Electrical.Analog;
package Semiconductors "Semiconductor devices such as diode, MOS and bipolar transistor"
  extends Modelica.Icons.Package;
  import Modelica.Constants.k "Boltzmann's constant, [J/K]";
  import Modelica.Constants.q "Electron charge, [As]";

protected
        function pow "Just a helper function for x^y in order that a symbolic engine can apply some transformations more easily"
          extends Modelica.Icons.Function;
          input Real x;
          input Real y;
          output Real z;
        algorithm
          z := x^y;
        end pow;

        function powlin "Power function (1 - x)^(-y) linearly continued for x > 0 (provided y = const.)"
          extends Modelica.Icons.Function;
          input Real x;
          input Real y;
          output Real z;
        algorithm
          z := if x > 0 then 1 + y*x else pow(1 - x, -y);
        end powlin;

        function exlin "Exponential function linearly continued for x > Maxexp"
          extends Modelica.Icons.Function;
          input Real x;
          input Real Maxexp;
          output Real z;
        algorithm
          z := if x > Maxexp then exp(Maxexp)*(1 + x - Maxexp) else exp(x);
        end exlin;

        function exlin2 "Exponential function linearly continued for x < MinExp and x > Maxexp"
          extends Modelica.Icons.Function;
          input Real x;
          input Real Minexp;
          input Real Maxexp;
          output Real z;
        algorithm
          z := if x < Minexp then exp(Minexp)*(1 + x - Minexp) else exlin(x, Maxexp);
        end exlin2;
end Semiconductors;


Simple PMOS transistor with heating port. The PMOS model is a simple model of a p-channel metal-oxide semiconductor FET. It differs slightly from the device used in the SPICE simulator. For more details please care for [Spiro1990].

A heating port is added for thermal electric simulation. The heating port is defined in the Modelica.Thermal library.

The model does not consider capacitances. A high drain-source resistance RDS is included to avoid numerical difficulties.

within Modelica.Electrical.Analog.Semiconductors;
model PMOS "Simple PMOS transistor with heating port"

        Modelica.Electrical.Analog.Interfaces.Pin D "Drain"
        Modelica.Electrical.Analog.Interfaces.Pin G "Gate"
        Modelica.Electrical.Analog.Interfaces.Pin S "Source"
        Modelica.Electrical.Analog.Interfaces.Pin B "Bulk"
        parameter SI.Length W=20.0e-6 "Width";
        parameter SI.Length L=6.0e-6 "Length";
        parameter SI.Transconductance Beta=0.0105e-3 "Transconductance parameter";
        parameter SI.Voltage Vt=-1.0 "Zero bias threshold voltage";
        parameter Real K2=0.41 "Bulk threshold parameter";
        parameter Real K5=0.839 "Reduction of pinch-off region";
        parameter SI.Length dW=-2.5e-6 "Narrowing of channel";
        parameter SI.Length dL=-2.1e-6 "Shortening of channel";
        parameter SI.Resistance RDS=1e7 "Drain-Source-Resistance";
  parameter Boolean useTemperatureDependency = false "= true, if parameters Beta, K2 and Vt depend on temperature"
  parameter SI.Temperature Tnom=300.15 "Parameter measurement temperature"
  parameter Real kvt=-2.9e-3 "Fitting parameter for Vt"
  parameter Real kk2=6.2e-4 "Fitting parameter for K2"
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(useHeatPort=useTemperatureDependency);
protected
        Real v;
        Real uds;
        Real ubs;
        Real ugst;
        Real ud;
        Real us;
        Real id;
        Real gds;
        Real beta_t;
        Real vt_t;
        Real k2_t;
equation
  assert(L + dL > 0, "PMOS: Effective length must be positive");
  assert(W + dW > 0, "PMOS: Effective width must be positive");
  assert(T_heatPort > 0,"PMOS: Temperature must be positive");
        gds = if (RDS < 1e-20 and RDS > -1e-20) then 1e20 else 1/RDS;
        v = beta_t*(W + dW)/(L + dL);
        ud = smooth(0,if (D.v > S.v) then S.v else D.v);
        us = smooth(0,if (D.v > S.v) then D.v else S.v);
        uds = ud - us;
        ubs = smooth(0,if (B.v < us) then 0 else B.v - us);
        ugst = (G.v - us - vt_t + k2_t*ubs)*K5;
        id = smooth(0,if (ugst >= 0) then uds*gds else if (ugst < uds) then -v*uds*(
          ugst - uds/2) + uds*gds else -v*ugst*ugst/2 + uds*gds);

  beta_t = if useTemperatureDependency then Beta*pow((T_heatPort/Tnom), -1.5) else Beta;
  vt_t = if useTemperatureDependency then Vt*(1 + (T_heatPort - Tnom)*kvt) else Vt;
  k2_t = if useTemperatureDependency then K2*(1 + (T_heatPort - Tnom)*kk2) else K2;

        G.i = 0;
        D.i = smooth(0,if (D.v > S.v) then -id else id);
        S.i = smooth(0,if (D.v > S.v) then id else -id);
        B.i = 0;
        LossPower = D.i*(D.v - S.v);
end PMOS;


Simple PNP BJT according to Ebers-Moll with heating port. This model is a simple model of a bipolar PNP junction transistor according to Ebers-Moll.

A heating port is added for thermal electric simulation. The heating port is defined in the Modelica.Thermal library.

A typical parameter set is (the parameter Vt is no longer used):

within Modelica.Electrical.Analog.Semiconductors;
model PNP "Simple PNP BJT according to Ebers-Moll with heating port"
        parameter Real Bf=50 "Forward beta";
        parameter Real Br=0.1 "Reverse beta";
        parameter SI.Current Is=1e-16 "Transport saturation current";
        parameter SI.InversePotential Vak=0.02 "Early voltage (inverse), 1/Volt";
        parameter SI.Time Tauf=0.12e-9 "Ideal forward transit time";
        parameter SI.Time Taur=5e-9 "Ideal reverse transit time";
        parameter SI.Capacitance Ccs=1e-12 "Collector-substrate(ground) cap.";
        parameter SI.Capacitance Cje=0.4e-12 "Base-emitter zero bias depletion cap.";
        parameter SI.Capacitance Cjc=0.5e-12 "Base-coll. zero bias depletion cap.";
        parameter SI.Voltage Phie=0.8 "Base-emitter diffusion voltage";
        parameter Real Me=0.4 "Base-emitter gradation exponent";
        parameter SI.Voltage Phic=0.8 "Base-collector diffusion voltage";
        parameter Real Mc=0.333 "Base-collector gradation exponent";
        parameter SI.Conductance Gbc=1e-15 "Base-collector conductance";
        parameter SI.Conductance Gbe=1e-15 "Base-emitter conductance";
        parameter Real EMin=-100 "If x < EMin, the exp(x) function is linearized";
        parameter Real EMax=40 "If x > EMax, the exp(x) function is linearized";
  parameter Boolean useTemperatureDependency = false "= true, if parameters Bf, Br, Is and Vt depend on temperature"
  parameter SI.Voltage Vt=0.02585 "Voltage equivalent of temperature"
  parameter SI.Temperature Tnom=300.15 "Parameter measurement temperature"
  parameter Real XTI=3 "Temperature exponent for effect on Is"
  parameter Real XTB=0 "Forward and reverse beta temperature exponent"
  parameter SI.Voltage EG=1.11 "Energy gap for temperature effect on Is"
        parameter Real NF=1.0 "Forward current emission coefficient";
        parameter Real NR=1.0 "Reverse current emission coefficient";
  parameter SI.Voltage IC=0 "Initial value of collector to substrate voltage"
  parameter Boolean UIC = false "Decision if initial value IC should be used";
  parameter Boolean useSubstrate = false "= false, if substrate is implicitly grounded";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(useHeatPort=useTemperatureDependency);

        SI.Voltage vcb "Collector-base voltage";
        SI.Voltage veb "Emitter-base voltage";
  SI.Voltage vcs "Collector-substrate voltage";
        Real qbk "Relative majority carrier charge, inverse";
        SI.Current icb "Collector-base diode current";
        SI.Current ieb "Emitter-base diode current";
        SI.Capacitance ccb "Total collector-base capacitance";
        SI.Capacitance ceb "Total emitter-base capacitance";
        SI.Capacitance Capcje "Effective emitter-base depletion capacitance";
        SI.Capacitance Capcjc "Effective collector-base depletion capacitance";
        SI.Current is_t "Temperature dependent transport saturation current";
        Real br_t "Temperature dependent forward beta";
        Real bf_t "Temperature dependent reverse beta";
        SI.Voltage vt_t "Voltage equivalent of effective temperature";
        Real hexp "Auxiliary quantity temperature dependent exponent";
        Real htempexp "Auxiliary quantity exp(hexp)";
  SI.Voltage vS "Substrate potential";
  SI.Current iS "Substrate current";

        Modelica.Electrical.Analog.Interfaces.Pin C "Collector"
        Modelica.Electrical.Analog.Interfaces.Pin B "Base"
        Modelica.Electrical.Analog.Interfaces.Pin E "Emitter"
  Modelica.Electrical.Analog.Interfaces.NegativePin S(final i = iS, final v = vS) if useSubstrate "Substrate"
initial equation
  if UIC then
    vcs = IC;
  end if;
equation
        assert(T_heatPort > 0,"Temperature must be positive");
        vcb = C.v - B.v;
        veb = E.v - B.v;
  vcs = C.v - vS;
        qbk = 1 - vcb*Vak;

        hexp = (T_heatPort/Tnom - 1)*EG/vt_t;
        htempexp = smooth(1, exlin2(hexp, EMin, EMax));

  is_t = if useTemperatureDependency then Is*pow(T_heatPort/Tnom, XTI)*htempexp else Is;
  br_t = if useTemperatureDependency then Br*pow(T_heatPort/Tnom, XTB) else Br;
  bf_t = if useTemperatureDependency then Bf*pow(T_heatPort/Tnom, XTB) else Bf;
  vt_t = if useTemperatureDependency then (k/q)*T_heatPort else Vt;

        icb = smooth(1, is_t*(exlin2(vcb/(NR*vt_t), EMin, EMax) - 1) + vcb*Gbc);
        ieb = smooth(1, is_t*(exlin2(veb/(NF*vt_t), EMin, EMax) - 1) + veb*Gbe);
        Capcjc = smooth(1, Cjc*powlin(vcb/Phic, Mc));
        Capcje = smooth(1, Cje*powlin(veb/Phie, Me));
        ccb = smooth(1, Taur*is_t/(NR*vt_t)*exlin2(vcb/(NR*vt_t), EMin, EMax) + Capcjc);
        ceb = smooth(1, Tauf*is_t/(NF*vt_t)*exlin2(veb/(NF*vt_t), EMin, EMax) + Capcje);
  C.i = icb/br_t + ccb*der(vcb) + (icb - ieb)*qbk - iS;
        B.i = -ieb/bf_t - icb/br_t - ceb*der(veb) - ccb*der(vcb);
  E.i = -B.i - C.i - iS;
  iS = -Ccs * der(vcs);
  if not useSubstrate then
    vS = 0;
  end if;
  LossPower = vcb*icb/br_t + veb*ieb/bf_t + (icb - ieb)*qbk*(C.v- E.v);
end PNP;


Simple triac, based on Semiconductors.Thyristor model. This is a simple TRIAC model based on the extended thyristor model Modelica.Electrical.Analog.Semiconductors.Thyristor.

Two thyristors are contrarily connected in parallel, whereas each transistor is connected with a diode.

Further information regarding the electrical component TRIAC can be detected in documentation of the ideal TRIAC model.

As an additional information: this model is based on the Modelica.Electrical.Analog.Semiconductors.Thyristor.

within Modelica.Electrical.Analog.Semiconductors;
model SimpleTriac "Simple triac, based on Semiconductors.Thyristor model"
  parameter SI.Voltage VDRM(final min=0) = 100
    "Forward breakthrough voltage";
  parameter SI.Voltage VRRM(final min=0) = 100
    "Reverse breakthrough voltage";
  parameter SI.Current IDRM=0.1 "Saturation current";
  parameter SI.Voltage VTM= 1.7 "Conducting voltage";
  parameter SI.Current IH=6e-3 "Holding current";
  parameter SI.Current ITM= 25 "Conducting current";

  parameter SI.Voltage VGT= 0.7 "Gate trigger voltage";
  parameter SI.Current IGT= 5e-3 "Gate trigger current";

  parameter SI.Time TON = 1e-6 "Switch on time";
  parameter SI.Time TOFF = 15e-6 "Switch off time";
  parameter SI.Voltage Vt=0.04
    "Voltage equivalent of temperature (kT/qn)";
  parameter Real Nbv=0.74 "Reverse Breakthrough emission coefficient";

  Modelica.Electrical.Analog.Interfaces.NegativePin n "Cathode"
  Modelica.Electrical.Analog.Interfaces.PositivePin p "Anode"
  Modelica.Electrical.Analog.Interfaces.PositivePin g "Gate"
  Modelica.Electrical.Analog.Semiconductors.Thyristor thyristor(VDRM=VDRM, VRRM=VRRM, IDRM=IDRM, VTM=VTM, IH=IH, ITM=ITM, VGT=VGT, IGT=IGT, TON=TON, TOFF=TOFF, Vt=Vt, Nbv=Nbv, useHeatPort=useHeatPort, T=T)
  Modelica.Electrical.Analog.Semiconductors.Thyristor thyristor1(VDRM=VDRM, VRRM=VRRM, IDRM=IDRM, VTM=VTM, IH=IH, ITM=ITM, VGT=VGT, IGT=IGT, TON=TON, TOFF=TOFF, Vt=Vt, Nbv=Nbv, useHeatPort=useHeatPort, T=T)
  Modelica.Electrical.Analog.Ideal.IdealDiode idealDiode(Vknee=0)
  Modelica.Electrical.Analog.Ideal.IdealDiode idealDiode1(Vknee=0)
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort;
equation
  if useHeatPort then
   connect(heatPort, thyristor.heatPort);
   connect(heatPort, thyristor1.heatPort);
 end if;
  connect(thyristor.Anode, n)
  connect(thyristor1.Anode, p)
  connect(thyristor1.Anode, thyristor.Cathode)
  connect(thyristor1.Cathode, thyristor.Anode)
  connect(thyristor.Gate, idealDiode.n)
  connect(idealDiode.p, g)
  connect(idealDiode1.n, thyristor1.Gate)
  connect(idealDiode1.p, g)
  LossPower = p.i*p.v + n.i*n.v + g.i*g.v;
end SimpleTriac;


Simple Thyristor Model. This is a simple thyristor model with three pins: Anode, Cathode and Gate. There are three operating modes:conducting, blocking and reverse breakthrough.
<br>As long as the thyristor is in blocking mode it behaves like a linear resistance Roff=VDRM^2/(VTM*IH). But if the voltage between anode and cathode exceeds VDRM or a positive gate current flows for a sufficient time the mode changes to conducting mode. The model stays in conducting mode until the anode current falls below the holding current IH. There is no way to switch off the thyristor via the gate. If the voltage between anode and cathode is negative, the model represents a diode (parameters Vt, Nbv) with reverse breakthrough voltage VRRM.

within Modelica.Electrical.Analog.Semiconductors;
model Thyristor "Simple Thyristor Model"
  parameter SI.Voltage VDRM(final min=0) = 100
    "Forward breakthrough voltage";
  parameter SI.Voltage VRRM(final min=0) = 100
    "Reverse breakthrough voltage";
  parameter SI.Current IDRM=0.1 "Saturation current";
  parameter SI.Voltage VTM= 1.7 "Conducting voltage";
  parameter SI.Current IH=6e-3 "Holding current";
  parameter SI.Current ITM= 25 "Conducting current";

  parameter SI.Voltage VGT= 0.7 "Gate trigger voltage";
  parameter SI.Current IGT= 5e-3 "Gate trigger current";

  parameter SI.Time TON = 1e-6 "Switch on time";
  parameter SI.Time TOFF = 15e-6 "Switch off time";
  parameter SI.Voltage Vt=0.04
    "Voltage equivalent of temperature (kT/qn)";
  parameter Real Nbv=0.74 "Reverse Breakthrough emission coefficient";
 extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort;
  SI.Current iGK "Gate current";
  SI.Voltage vGK "Voltage between gate and cathode";
  SI.Voltage vAK "Voltage between anode and cathode";
  SI.Voltage vControl(start=0);
  SI.Voltage vContot;
  SI.Voltage vConmain;
  parameter SI.Voltage vRef = 0.65;

public
  Modelica.Electrical.Analog.Interfaces.PositivePin Anode
  Modelica.Electrical.Analog.Interfaces.NegativePin Cathode
  Modelica.Electrical.Analog.Interfaces.PositivePin Gate

protected
  parameter SI.Voltage Von=5;
  parameter SI.Voltage Voff= 1.5;
  parameter SI.Resistance Ron=(VTM-0.7)/ITM
    "Forward conducting mode resistance";
  parameter SI.Resistance Roff=(VDRM^2)/VTM/IH
    "Blocking mode resistance";

equation
  //Kirchhoff's equations
  Anode.i+Gate.i+Cathode.i=0;
  vGK=Gate.v-Cathode.v;
  vAK=Anode.v-Cathode.v;

  // Gate and Control voltage
  iGK = Gate.i;
  vGK = smooth(0,(if vGK < vRef then VGT/IGT*iGK else
        vRef^2/VGT+iGK*(VGT-vRef)/IGT));
  vContot = vConmain + smooth(0, if iGK < 0.95 * IGT then 0 else if iGK < 0.95*IGT + 1e-3 then 10000*(iGK-0.95*IGT)*vAK else 10* vAK);
  der(vControl)= (vContot - vControl) / (if (vContot - vControl) > 0 then 1.87*TON else 0.638*TOFF);

  // Anode-Cathode characteristics
  Anode.i= smooth(1, if vAK < -VRRM then -VRRM/Roff*exp(-(vAK+VRRM)/(Nbv*Vt)) else
         if vControl<Voff then vAK/Roff else
         if vControl<Von then vAK/(sqrt(Ron*Roff)*(Ron/Roff)^((3*((2*vControl-Von-Voff)/(2*(Von-Voff)))-4*((2*vControl-Von-Voff)/(2*(Von-Voff)))^3)/2)) else
          vAK/Ron);

  // holding effect and forward breakthrough
  vConmain = (if Anode.i>IH or vAK>VDRM then Von else 0);
  LossPower = Anode.i*Anode.v + Cathode.i*Cathode.v + Gate.i*Gate.v;
end Thyristor;


Zener diode with 3 working areas. The simple Zener diode is a one port. It consists of the diode itself and an parallel ohmic resistance R. The diode formula is:

within Modelica.Electrical.Analog.Semiconductors;
model ZDiode "Zener diode with 3 working areas"
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  parameter SI.Current Ids=1e-6 "Saturation current";
  parameter SI.Voltage Vt=0.04 "Voltage equivalent of temperature (kT/qn)";
  parameter Real Maxexp(final min=Modelica.Constants.small) = 30
    "Max. exponent for linear continuation";
  parameter SI.Resistance R=1e8 "Parallel ohmic resistance";
  parameter SI.Voltage Bv=5.1 "Breakthrough voltage = Zener- or Z-voltage";
  parameter SI.Current Ibv=0.7 "Breakthrough knee current";
  parameter Real Nbv=0.74 "Breakthrough emission coefficient";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=293.15);
equation
  i = smooth(1, if (v>Maxexp*Vt) then
            Ids*( exp(Maxexp)*(1 + v/Vt - Maxexp)-1) + v/R else
         if ( (v+Bv)<-Maxexp*(Nbv*Vt)) then
            -Ids -Ibv* exp(Maxexp)*(1 - (v+Bv)/(Nbv*Vt) - Maxexp) +v/R else
            Ids*(exp(v/Vt)-1) - Ibv*exp(-(v+Bv)/(Nbv*Vt)) + v/R);
  LossPower = v*i;
end ZDiode;


Sensor to measure the current in a branch. The current sensor converts the current flowing between the two connectors into a real valued signal. The two connectors are in the sensor connected like a short cut. The sensor has to be placed within an electrical connection in series.  It does not influence the current sum at the connected nodes. Therefore, the electrical behavior is not influenced by the sensor.

within Modelica.Electrical.Analog.Sensors;
model CurrentSensor "Sensor to measure the current in a branch"
  extends Modelica.Icons.RoundSensor;

  Interfaces.PositivePin p "Positive pin"
  Interfaces.NegativePin n "Negative pin"
  Modelica.Blocks.Interfaces.RealOutput i(unit="A")
    "Current in the branch from p to n as output signal"

equation
  p.v = n.v;
  p.i = i;
  n.i = -i;
end CurrentSensor;


Sensor to measure current, voltage and power. This multi sensor measures current, voltage and instantaneous electrical power of a single-phase system and has a separated voltage and current path.
The pins of the voltage path are pv and nv, the pins of the current path are pc and nc.
The internal resistance of the current path is zero, the internal resistance of the voltage path is infinite.

within Modelica.Electrical.Analog.Sensors;
model MultiSensor "Sensor to measure current, voltage and power"
  extends Modelica.Icons.RoundSensor;
  Modelica.Electrical.Analog.Interfaces.PositivePin pc
      "Positive pin, current path"
  Modelica.Electrical.Analog.Interfaces.NegativePin nc
      "Negative pin, current path"
  Modelica.Electrical.Analog.Interfaces.PositivePin pv
      "Positive pin, voltage path"
  Modelica.Electrical.Analog.Interfaces.NegativePin nv
      "Negative pin, voltage path"
  Modelica.Blocks.Interfaces.RealOutput i(final quantity="ElectricCurrent", final unit="A")
    "Current as output signal"
  Modelica.Blocks.Interfaces.RealOutput v(final quantity="ElectricPotential", final unit="V")
    "Voltage as output signal"
  Modelica.Blocks.Interfaces.RealOutput power(final quantity="Power", final unit="W")
    "Instantaneous power as output signal"
equation
  pc.i + nc.i = 0;
  pc.v - nc.v = 0;
  pv.i = 0;
  nv.i = 0;
  i = pc.i;
  v = pv.v - nv.v;
  power = v*i;
end MultiSensor;


within Modelica.Electrical.Analog;
package Sensors "Potential, voltage, current, and power sensors"

  extends Modelica.Icons.SensorsPackage;
end Sensors;


Sensor to measure the potential. The potential sensor converts the voltage of a node (with respect to the ground node) into a real valued signal. It does not influence the current sum at the node which voltage is measured, therefore, the electrical behavior is not influenced by the sensor.

within Modelica.Electrical.Analog.Sensors;
model PotentialSensor "Sensor to measure the potential"
  extends Modelica.Icons.RoundSensor;

  Interfaces.PositivePin p "Pin to be measured"
  Modelica.Blocks.Interfaces.RealOutput phi(unit="V")
    "Absolute voltage potential as output signal"
equation
  p.i = 0;
  phi = p.v;
end PotentialSensor;


Sensor to measure the power. This power sensor measures instantaneous electrical power of a single-phase system and has a separated voltage and current path. The pins of the voltage path are pv and nv, the pins of the current path are pc and nc. The internal resistance of the current path is zero, the internal resistance of the voltage path is infinite.

within Modelica.Electrical.Analog.Sensors;
model PowerSensor "Sensor to measure the power"
  extends Modelica.Icons.RoundSensor;
  Modelica.Electrical.Analog.Interfaces.PositivePin pc
      "Positive pin, current path"
  Modelica.Electrical.Analog.Interfaces.NegativePin nc
      "Negative pin, current path"
  Modelica.Electrical.Analog.Interfaces.PositivePin pv
      "Positive pin, voltage path"
  Modelica.Electrical.Analog.Interfaces.NegativePin nv
      "Negative pin, voltage path"
  Modelica.Blocks.Interfaces.RealOutput power(unit="W")
      "Instantaneous power as output signal"
  Modelica.Electrical.Analog.Sensors.VoltageSensor voltageSensor
  Modelica.Electrical.Analog.Sensors.CurrentSensor currentSensor
  Modelica.Blocks.Math.Product product

equation
  connect(pv, voltageSensor.p)
  connect(voltageSensor.n, nv)
  connect(pc, currentSensor.p)
  connect(currentSensor.n, nc)
  connect(currentSensor.i, product.u2)
  connect(voltageSensor.v, product.u1)
  connect(product.y, power)
end PowerSensor;


Sensor to measure the voltage between two pins. The voltage sensor converts the voltage between the two connectors into a real valued signal. It does not influence the current sum at the nodes in between the voltage is measured, therefore, the electrical behavior is not influenced by the sensor.

within Modelica.Electrical.Analog.Sensors;
model VoltageSensor "Sensor to measure the voltage between two pins"
  extends Modelica.Icons.RoundSensor;

  Interfaces.PositivePin p "Positive pin"
  Interfaces.NegativePin n "Negative pin"
  Modelica.Blocks.Interfaces.RealOutput v(unit="V")
    "Voltage between pin p and n (= p.v - n.v) as output signal"

equation
  p.i = 0;
  n.i = 0;
  v = p.v - n.v;
end VoltageSensor;


Source for constant current. The ConstantCurrent source is a simple source for an ideal constant current which is provided by a parameter. There is no internal resistance modeled. No further effects are modeled. Especially, the current flow will never end.

within Modelica.Electrical.Analog.Sources;
model ConstantCurrent "Source for constant current"
  parameter SI.Current I(start=1) "Value of constant current";
  extends Interfaces.OnePort;
  extends Modelica.Electrical.Analog.Icons.CurrentSource;
equation
  i = I;
end ConstantCurrent;


Source for constant voltage. The ConstantVoltage source is a simple source for an ideal constant voltage which is provided by a parameter. There is no internal resistance modeled. If it is used instead of a battery model it is not very realistic: This battery will never be unloaded.

within Modelica.Electrical.Analog.Sources;
model ConstantVoltage "Source for constant voltage"
  parameter SI.Voltage V(start=1) "Value of constant voltage";
  extends Interfaces.OnePort;
  extends Modelica.Electrical.Analog.Icons.VoltageSource;
equation
  v = V;
end ConstantVoltage;


Cosine current source. This current source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model CosineCurrent "Cosine current source"
  parameter SI.Current I(start=1) "Amplitude of cosine wave";
  parameter SI.Angle phase=0 "Phase of cosine wave";
  parameter SI.Frequency f(start=1) "Frequency of cosine wave";
  extends Interfaces.CurrentSource(redeclare Modelica.Blocks.Sources.Cosine
      signalSource(
      final amplitude=I,
      final f=f,
      final phase=phase));

end CosineCurrent;


Cosine current source with variable frequency and amplitude. This current source provides a cosine current with variable frequency f and variable amplitude I,
i.e. the phase angle of the sine wave is integrated from 2*π*f.

within Modelica.Electrical.Analog.Sources;
model CosineCurrentVariableFrequencyAndAmplitude
  "Cosine current source with variable frequency and amplitude"
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  extends Modelica.Electrical.Analog.Icons.CurrentSource;
  import Modelica.Constants.pi;
  parameter Boolean useConstantAmplitude=false "Enable constant amplitude";
  parameter SI.Current constantAmplitude=1 "Constant amplitude"
  parameter Boolean useConstantFrequency=false "Enable constant frequency";
  parameter SI.Frequency constantFrequency=1 "Constant frequency"
  parameter SI.Current offset=0 "Offset of the sine wave";
  SI.Angle phi(start=0) "Phase of the sine wave";
  Blocks.Interfaces.RealInput I(unit="A") if not useConstantAmplitude
    "Amplitude"
  Blocks.Interfaces.RealInput f(unit="Hz") if not useConstantFrequency
    "Frequency"
protected
  Blocks.Sources.Constant I_constant(final k=constantAmplitude) if useConstantAmplitude
  Blocks.Sources.Constant f_constant(final k=constantFrequency) if useConstantFrequency
  Blocks.Interfaces.RealInput I_internal(unit="A") "Amplitude"
  Blocks.Interfaces.RealInput f_internal(unit="Hz") "Frequency"
equation
  der(phi) = 2*pi*f_internal;
  i = offset + I_internal*cos(phi);
  connect(f,f_internal)
  connect(I,I_internal)
  connect(f_constant.y,f_internal)
  connect(I_constant.y,I_internal)
end CosineCurrentVariableFrequencyAndAmplitude;


Cosine voltage source. This voltage source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model CosineVoltage "Cosine voltage source"
  parameter SI.Voltage V(start=1) "Amplitude of cosine wave";
  parameter SI.Angle phase=0 "Phase of cosine wave";
  parameter SI.Frequency f(start=1) "Frequency of cosine wave";
  extends Interfaces.VoltageSource(redeclare Modelica.Blocks.Sources.Cosine
      signalSource(
      final amplitude=V,
      final f=f,
      final phase=phase));

end CosineVoltage;


Cosine voltage source with variable frequency and amplitude. This voltage source provides a cosine voltage with variable frequency f and variable amplitude V,
i.e. the phase angle of the sine wave is integrated from 2*π*f.

within Modelica.Electrical.Analog.Sources;
model CosineVoltageVariableFrequencyAndAmplitude
  "Cosine voltage source with variable frequency and amplitude"
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  extends Modelica.Electrical.Analog.Icons.VoltageSource;
  import Modelica.Constants.pi;
  parameter Boolean useConstantAmplitude=false "Enable constant amplitude";
  parameter SI.Voltage constantAmplitude=1 "Constant amplitude"
  parameter Boolean useConstantFrequency=false "Enable constant frequency";
  parameter SI.Frequency constantFrequency=1 "Constant frequency"
  parameter SI.Voltage offset=0 "Offset of the sine wave";
  SI.Angle phi(start=0) "Phase of the sine wave";
  Blocks.Interfaces.RealInput V(unit="V") if not useConstantAmplitude
    "Amplitude"
  Blocks.Interfaces.RealInput f(unit="Hz") if not useConstantFrequency
    "Frequency"
protected
  Blocks.Interfaces.RealInput V_internal(unit="V") "Amplitude"
  Blocks.Interfaces.RealInput f_internal(unit="Hz") "Frequency"
  Blocks.Sources.Constant V_constant(final k=constantAmplitude) if useConstantAmplitude
  Blocks.Sources.Constant f_constant(final k=constantFrequency) if useConstantFrequency
equation
  der(phi) = 2*pi*f_internal;
  v = offset + V_internal*cos(phi);
  connect(f, f_internal)
  connect(V, V_internal)
  connect(f_constant.y, f_internal)
  connect(V_constant.y, V_internal)
end CosineVoltageVariableFrequencyAndAmplitude;


Simple model of a DC power supply cv - cp - cc. This is a simple model of a DC power supply, as used in laboratories.
It can only work in one quadrant, i.e., positive voltage, delivering current.
It has three limitations:

within Modelica.Electrical.Analog.Sources;
model DCPowerSupply "Simple model of a DC power supply cv - cp - cc"
  import Modelica.Constants.eps;
  parameter SI.Voltage V0(final min = eps) = 60 "No-load voltage";
  parameter SI.Current I0(final min = eps) = 50 "Short-circuit current";
  parameter SI.Power   P0(final min = eps) = 1200 "Maximum power";
  parameter SI.Resistance  Rcv(final min = eps) = 1e-3 "Inner resistance in constant voltage region"
  parameter SI.Conductance Gcc(final min = eps) = 1e-3 "Inner conductance in constant current region"
  parameter SI.Current iBack = 1e-3 "Allowed back current"
  SI.Voltage v(start=V0) = p.v - n.v "Terminal voltage";
  SI.Current i = p.i "Current (delivered < 0)";
  SI.Power P = v * i "Power (delivered < 0)";
  Modelica.Electrical.Analog.Interfaces.PositivePin p
  Modelica.Electrical.Analog.Interfaces.NegativePin n
protected
  parameter SI.Voltage vLim(fixed=false) "Voltage limit for cc";
  parameter SI.Current iLim(fixed=false) "Current limit for cv";
  parameter Boolean cp(fixed=false) "Is cp present?";
  Boolean cv(start=true)  "Operation in cv, otherwise cc (or cp)";
  Boolean cc(start=false) "Operation in cc, otherwise cv (or cp)";
initial algorithm
  assert(Rcv < (V0/I0), "Rcv too high!");
  assert(Gcc < (I0/V0), "Gcc too high!");
  vLim:=(V0 - Rcv * I0) / (1 - Rcv * Gcc);
  iLim:=(I0 - Gcc * V0) / (1 - Gcc * Rcv);
  cp:=false;
  if vLim*iLim > P0 then
    cp:=true;
    assert(Rcv < (V0^2/(4*P0)), "Rcv too high!");
    assert(Gcc < (I0^2/(4*P0)), "Gcc too high!");
    vLim:=(I0 - sqrt(I0^2 - 4*Gcc*P0)) / (2*Gcc);
    iLim:=(V0 - sqrt(V0^2 - 4*Rcv*P0)) / (2*Rcv);
  end if;
equation
  p.i + n.i = 0;
  assert(v >= 0, "Only voltage >= 0 allowed");
  assert(i <= iBack, "Back current exceeded!");
  cv = (-i) <= iLim;
  cc =   v  <= vLim;
  if cp then
    if cv then
       v = V0 - Rcv*(-i);
    elseif cc then
      -i = I0 - Gcc*v;
    else// cp
      P0 = v*(-i);
    end if;
  else
    if cv then
       v = V0 - Rcv*(-i);
    else//cc
      -i = I0 - Gcc*v;
    end if;
  end if;

Constant Power:  P0 = v*(-i);

ConstantCurrent: -i = I0 - Gcc*v;

Remember that current delivered by the power supply is negative.

"));
end DCPowerSupply;


Rising and falling exponential current source. This current source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model ExponentialsCurrent "Rising and falling exponential current source"
  parameter Real iMax(start=1) "Upper bound for rising edge";
  parameter SI.Time riseTime(min=0, start=0.5) "Rise time";
  parameter SI.Time riseTimeConst(min=Modelica.Constants.small, start=0.1)
    "Rise time constant";
  parameter SI.Time fallTimeConst(min=Modelica.Constants.small, start=
        riseTimeConst) "Fall time constant";
  extends Interfaces.CurrentSource(redeclare
      Modelica.Blocks.Sources.Exponentials signalSource(
      final outMax=iMax,
      final riseTime=riseTime,
      final riseTimeConst=riseTimeConst,
      final fallTimeConst=fallTimeConst));
end ExponentialsCurrent;


Rising and falling exponential voltage source. This voltage source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model ExponentialsVoltage "Rising and falling exponential voltage source"
  parameter Real vMax(start=1) "Upper bound for rising edge";
  parameter SI.Time riseTime(min=0, start=0.5) "Rise time";
  parameter SI.Time riseTimeConst(min=Modelica.Constants.small, start=0.1)
    "Rise time constant";
  parameter SI.Time fallTimeConst(min=Modelica.Constants.small, start=
        riseTimeConst) "Fall time constant";
  extends Interfaces.VoltageSource(redeclare
      Modelica.Blocks.Sources.Exponentials signalSource(
      final outMax=vMax,
      final riseTime=riseTime,
      final riseTimeConst=riseTimeConst,
      final fallTimeConst=fallTimeConst));
end ExponentialsVoltage;


Exponentially damped sine current source. This current source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model ExpSineCurrent "Exponentially damped sine current source"
  parameter Real I(start=1) "Amplitude of sine wave";
  parameter SI.Frequency f(start=2) "Frequency of sine wave";
  parameter SI.Angle phase=0 "Phase of sine wave";
  parameter SI.Damping damping(start=1) "Damping coefficient of sine wave";
  extends Interfaces.CurrentSource(redeclare Modelica.Blocks.Sources.ExpSine
      signalSource(
      final amplitude=I,
      final f=f,
      final phase=phase,
      final damping=damping));
end ExpSineCurrent;


Exponentially damped sine voltage source. This voltage source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model ExpSineVoltage "Exponentially damped sine voltage source"
  parameter SI.Voltage V(start=1) "Amplitude of sine wave";
  parameter SI.Frequency f(start=2) "Frequency of sine wave";
  parameter SI.Angle phase=0 "Phase of sine wave";
  parameter SI.Damping damping(start=1) "Damping coefficient of sine wave";
  extends Interfaces.VoltageSource(redeclare Modelica.Blocks.Sources.ExpSine
      signalSource(
      final amplitude=V,
      final f=f,
      final phase=phase,
      final damping=damping));
end ExpSineVoltage;


Lightning impulse voltage or current trajectory. Simplified trajectory of an impulse (like the current of lightnings) as one of two choices:

within Modelica.Electrical.Analog.Sources;
block LightningImpulse "Lightning impulse voltage or current trajectory"
  import Modelica.Electrical.Analog.Types.ImpulseApproximation;
  import Modelica.Constants.small;
  parameter ImpulseApproximation approximation=Modelica.Electrical.Analog.Types.ImpulseApproximation.Heidler
    "Approximation of impulse";
  parameter Real amplitude "Amplitude";
  parameter Modelica.Units.SI.Time T1=10e-6 "Rise time";
  parameter Modelica.Units.SI.Time T2=350e-6 "Decay time to half value";
  extends Modelica.Blocks.Interfaces.SignalSource;
  parameter Integer m(final min=2)=5 "Integer exponent of Heidler-function 5..10"
protected
  parameter Real eta(final min=small, fixed=false, start=1)
    "Amplitude parameter";
  parameter Modelica.Units.SI.Time T0=
    if approximation==ImpulseApproximation.DoubleExp then T2*T1/(T2 - T1)*log(T2/T1)
    else T1*(m*T2/T1)^(1/(m + 1))
    "Initial value of time parameter";
  parameter Modelica.Units.SI.Time T(final min=small,
    fixed=false, start=T0) "Time when maximum occurs";
  parameter Modelica.Units.SI.Time T10(final min=small,
    fixed=false, start=if approximation==ImpulseApproximation.DoubleExp then 0.01*T0 else 0.1*T0) "Time to 10%";
  parameter Modelica.Units.SI.Time tau1(final min=small,
    fixed=false, start=if approximation==ImpulseApproximation.DoubleExp then T2 else T1) "Time constant 1";
  parameter Modelica.Units.SI.Time tau2(final min=small,
    fixed=false, start=if approximation==ImpulseApproximation.DoubleExp then T1 else T2) "Time constant 2";
initial equation
  if approximation==ImpulseApproximation.DoubleExp then
    //y=1/eta*(exp(-time/tau1) - exp(-time/tau2));
    //time T when maximum occurs
    exp(-T/tau1)/tau1 = exp(-T/tau2)/tau2;
    //eta to reach amplitude at T
    eta=exp(-T/tau1) - exp(-T/tau2);
    //at T10 the output rises to 10% of the amplitude
    0.1*eta=exp(-T10/tau1) - exp(-T10/tau2);
    //at T10 + 0.8*T1 the output rises to 90% of the amplitude
    0.9*eta=exp(-(T10 + 0.8*T1)/tau1) - exp(-(T10 + 0.8*T1)/tau2);
    //at T2 from virtual start the output falls below 50% of the amplitude
    0.5*eta=exp(-(T10 - 0.1*T1 + T2)/tau1) - exp(-(T10 - 0.1*T1 + T2)/tau2);
  else
    //y=1/eta*(time/tau1)^m/(1 + (time/tau1)^m)*exp(-time/tau2);
    //time T when maximum occurs
    tau2/T*m=1 + (T/tau1)^m;
    //eta to reach amplitude at T
    eta=(T/tau1)^m/(1 + (T/tau1)^m)*exp(-T/tau2);
    //at T10 the output rises to 10% of the amplitude
    0.1*eta=(T10/tau1)^m/(1 + (T10/tau1)^m)*exp(-T10/tau2);
    //at T10 + 0.8*T1 the output rises to 90% of the amplitude
    0.9*eta=((T10 + 0.8*T1)/tau1)^m/(1 + ((T10 + 0.8*T1)/tau1)^m)*exp(-(T10 + 0.8*T1)/tau2);
    //at T2 from virtual start the output falls below 50% of the amplitude
    0.5*eta=((T10 - 0.1*T1 + T2)/tau1)^m/(1 + ((T10 - 0.1*T1 + T2)/tau1)^m)*exp(-(T10 - 0.1*T1 + T2)/tau2);
  end if;
equation
  assert(approximation==ImpulseApproximation.Heidler or T1<0.2*T2,"Rise time has to be smaller than 0.2*decay time!");
  if time<startTime then
    y=offset;
  else
    if approximation==ImpulseApproximation.DoubleExp then
      y=offset + amplitude/eta*(exp(-(time - startTime)/tau1) - exp(-(time - startTime)/tau2));
    else
      y=offset + amplitude/eta*((time - startTime)/tau1)^m/(1 + ((time - startTime)/tau1)^m)*exp(-(time - startTime)/tau2);
    end if;
  end if;
end LightningImpulse;


Lightning impulse current. Lightning impulse current using either a double exponential function or a Heidler function,
see block LightningImpulse.

within Modelica.Electrical.Analog.Sources;
model LightningImpulseCurrent "Lightning impulse current"
  parameter Modelica.Electrical.Analog.Types.ImpulseApproximation approximation=
     Modelica.Electrical.Analog.Types.ImpulseApproximation.Heidler "Approximation of impulse";
  parameter SI.Current I "Amplitude";
  parameter SI.Time T1=10e-6 "Rise time";
  parameter SI.Time T2=350e-6 "Decay time to half value";
  parameter Integer m(final min=2)=5 "Integer exponent of Heidler-function 5..10"
  extends Modelica.Electrical.Analog.Interfaces.CurrentSource(redeclare
      Modelica.Electrical.Analog.Sources.LightningImpulse signalSource(
      final approximation=approximation,
      final amplitude=I,
      final T1=T1,
      final T2=T2,
      final m=m));
end LightningImpulseCurrent;


Lightning impulse voltage. Lightning impulse voltage using either a double exponential function or a Heidler function,
see block LightningImpulse.

within Modelica.Electrical.Analog.Sources;
model LightningImpulseVoltage "Lightning impulse voltage"
  parameter Modelica.Electrical.Analog.Types.ImpulseApproximation approximation=
     Modelica.Electrical.Analog.Types.ImpulseApproximation.Heidler "Approximation of impulse";
  parameter SI.Voltage V "Amplitude";
  parameter SI.Time T1=10e-6 "Rise time";
  parameter SI.Time T2=350e-6 "Decay time to half value";
  parameter Integer m(final min=2)=5 "Integer exponent of Heidler-function 5..10"
  extends Modelica.Electrical.Analog.Interfaces.VoltageSource(redeclare
      Modelica.Electrical.Analog.Sources.LightningImpulse signalSource(
      final approximation=approximation,
      final amplitude=V,
      final T1=T1,
      final T2=T2,
      final m=m));
end LightningImpulseVoltage;


within Modelica.Electrical.Analog;
package Sources "Time-dependent and controlled voltage and current sources"

  extends Modelica.Icons.SourcesPackage;
end Sources;


Pulse current source. This current source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model PulseCurrent "Pulse current source"
  parameter SI.Current I(start=1) "Amplitude of pulse";
  parameter Real width(
    final min=Modelica.Constants.small,
    final max=100,
    start=50) "Width of pulse in % of period";
  parameter SI.Time period(final min=Modelica.Constants.small, start=1)
    "Time for one period";
  extends Interfaces.CurrentSource(redeclare Modelica.Blocks.Sources.Pulse
      signalSource(
      final amplitude=I,
      final width=width,
      final period=period));

end PulseCurrent;


Pulse voltage source. This voltage source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model PulseVoltage "Pulse voltage source"
  parameter SI.Voltage V(start=1) "Amplitude of pulse";
  parameter Real width(
    final min=Modelica.Constants.small,
    final max=100,
    start=50) "Width of pulse in % of period";
  parameter SI.Time period(final min=Modelica.Constants.small, start=1)
    "Time for one period";
  extends Interfaces.VoltageSource(redeclare Modelica.Blocks.Sources.Pulse
      signalSource(
      final amplitude=V,
      final width=width,
      final period=period));
end PulseVoltage;


Ramp current source. This current source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model RampCurrent "Ramp current source"
  parameter SI.Current I(start=1) "Height of ramp";
  parameter SI.Time duration(min=Modelica.Constants.small, start=2)
    "Duration of ramp";
  extends Interfaces.CurrentSource(redeclare Modelica.Blocks.Sources.Ramp
      signalSource(final height=I, final duration=duration));
end RampCurrent;


Ramp voltage source. This voltage source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model RampVoltage "Ramp voltage source"
  parameter SI.Voltage V(start=1) "Height of ramp";
  parameter SI.Time duration(min=Modelica.Constants.small, start=2)
    "Duration of ramp";
  extends Interfaces.VoltageSource(redeclare Modelica.Blocks.Sources.Ramp
      signalSource(final height=V, final duration=duration));
end RampVoltage;


Saw tooth current source. This current source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model SawToothCurrent "Saw tooth current source"
  parameter SI.Current I(start=1) "Amplitude of saw tooth";
  parameter SI.Time period(start=1) "Time for one period";
  extends Interfaces.CurrentSource(redeclare Modelica.Blocks.Sources.SawTooth
      signalSource(final amplitude=I, final period=period));
end SawToothCurrent;


Saw tooth voltage source. This voltage source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model SawToothVoltage "Saw tooth voltage source"
  parameter SI.Voltage V(start=1) "Amplitude of saw tooth";
  parameter SI.Time period(start=1) "Time for one period";
  extends Interfaces.VoltageSource(redeclare Modelica.Blocks.Sources.SawTooth
      signalSource(final amplitude=V, final period=period));
end SawToothVoltage;


Generic current source using the input signal as source current. The signal current source is a parameterless converter of real valued signals into a the source current. No further effects are modeled. The real valued signal has to be provided by components of the blocks library. It can be regarded as the "Opposite" of a current sensor.

within Modelica.Electrical.Analog.Sources;
model SignalCurrent
  "Generic current source using the input signal as source current"
  extends Modelica.Electrical.Analog.Icons.CurrentSource;
  Interfaces.PositivePin p
  Interfaces.NegativePin n
  Modelica.Blocks.Interfaces.RealInput i(unit="A")
    "Current flowing from pin p to pin n as input signal"
  SI.Voltage v "Voltage drop between the two pins (= p.v - n.v)";
equation
  v = p.v - n.v;
  0 = p.i + n.i;
  i = p.i;
end SignalCurrent;


Generic voltage source using the input signal as source voltage. The signal voltage source is a parameterless converter of real valued signals into a the source voltage. No further effects are modeled. The real valued signal has to be provided by components of the blocks library. It can be regarded as the "Opposite" of a voltage sensor.

within Modelica.Electrical.Analog.Sources;
model SignalVoltage
  "Generic voltage source using the input signal as source voltage"
  extends Modelica.Electrical.Analog.Icons.VoltageSource;
  Interfaces.PositivePin p
  Interfaces.NegativePin n
  Modelica.Blocks.Interfaces.RealInput v(unit="V")
    "Voltage between pin p and n (= p.v - n.v) as input signal"
  SI.Current i "Current flowing from pin p to pin n";
equation
  v = p.v - n.v;
  0 = p.i + n.i;
  i = p.i;
end SignalVoltage;


Sine current source. This current source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model SineCurrent "Sine current source"
  parameter SI.Current I(start=1) "Amplitude of sine wave";
  parameter SI.Angle phase=0 "Phase of sine wave";
  parameter SI.Frequency f(start=1) "Frequency of sine wave";
  extends Interfaces.CurrentSource(redeclare Modelica.Blocks.Sources.Sine
      signalSource(
      final amplitude=I,
      final f=f,
      final phase=phase));

end SineCurrent;


Sine current source with variable frequency and amplitude. This current source provides a sinusoidal current with variable frequency f and variable amplitude I,
i.e. the phase angle of the sine wave is integrated from 2*π*f.

within Modelica.Electrical.Analog.Sources;
model SineCurrentVariableFrequencyAndAmplitude
  "Sine current source with variable frequency and amplitude"
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  extends Modelica.Electrical.Analog.Icons.CurrentSource;
  import Modelica.Constants.pi;
  parameter Boolean useConstantAmplitude=false "Enable constant amplitude";
  parameter SI.Current constantAmplitude=1 "Constant amplitude"
  parameter Boolean useConstantFrequency=false "Enable constant frequency";
  parameter SI.Frequency constantFrequency=1 "Constant frequency"
  parameter SI.Current offset=0 "Offset of the sine wave";
  SI.Angle phi(start=0) "Phase of the sine wave";
  Blocks.Interfaces.RealInput I(unit="A") if not useConstantAmplitude
    "Amplitude"
  Blocks.Interfaces.RealInput f(unit="Hz") if not useConstantFrequency
    "Frequency"
protected
  Blocks.Sources.Constant I_constant(final k=constantAmplitude) if useConstantAmplitude
  Blocks.Sources.Constant f_constant(final k=constantFrequency) if useConstantFrequency
  Blocks.Interfaces.RealInput I_internal(unit="A") "Amplitude"
  Blocks.Interfaces.RealInput f_internal(unit="Hz") "Frequency"
equation
  der(phi) = 2*pi*f_internal;
  i = offset + I_internal*sin(phi);
  connect(f,f_internal)
  connect(I,I_internal)
  connect(f_constant.y,f_internal)
  connect(I_constant.y,I_internal)
end SineCurrentVariableFrequencyAndAmplitude;


Sine voltage source. This voltage source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model SineVoltage "Sine voltage source"
  parameter SI.Voltage V(start=1) "Amplitude of sine wave";
  parameter SI.Angle phase=0 "Phase of sine wave";
  parameter SI.Frequency f(start=1) "Frequency of sine wave";
  extends Interfaces.VoltageSource(redeclare Modelica.Blocks.Sources.Sine
      signalSource(
      final amplitude=V,
      final f=f,
      final phase=phase));

end SineVoltage;


Sine voltage source with variable frequency and amplitude. This voltage source provides a sinusoidal voltage with variable frequency f and variable amplitude V,
i.e. the phase angle of the sine wave is integrated from 2*π*f.

within Modelica.Electrical.Analog.Sources;
model SineVoltageVariableFrequencyAndAmplitude
  "Sine voltage source with variable frequency and amplitude"
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  extends Modelica.Electrical.Analog.Icons.VoltageSource;
  import Modelica.Constants.pi;
  parameter Boolean useConstantAmplitude=false "Enable constant amplitude";
  parameter SI.Voltage constantAmplitude=1 "Constant amplitude"
  parameter Boolean useConstantFrequency=false "Enable constant frequency";
  parameter SI.Frequency constantFrequency=1 "Constant frequency"
  parameter SI.Voltage offset=0 "Offset of the sine wave";
  SI.Angle phi(start=0) "Phase of the sine wave";
  Blocks.Interfaces.RealInput V(unit="V") if not useConstantAmplitude
    "Amplitude"
  Blocks.Interfaces.RealInput f(unit="Hz") if not useConstantFrequency
    "Frequency"
protected
  Blocks.Interfaces.RealInput V_internal(unit="V") "Amplitude"
  Blocks.Interfaces.RealInput f_internal(unit="Hz") "Frequency"
  Blocks.Sources.Constant V_constant(final k=constantAmplitude) if useConstantAmplitude
  Blocks.Sources.Constant f_constant(final k=constantFrequency) if useConstantFrequency
equation
  der(phi) = 2*pi*f_internal;
  v = offset + V_internal*sin(phi);
  connect(f, f_internal)
  connect(V, V_internal)
  connect(f_constant.y, f_internal)
  connect(V_constant.y, V_internal)
end SineVoltageVariableFrequencyAndAmplitude;


Step current source. This current source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model StepCurrent "Step current source"
  parameter SI.Current I(start=1) "Height of step";
  extends Interfaces.CurrentSource(redeclare Modelica.Blocks.Sources.Step
      signalSource(final height=I));
end StepCurrent;


Step voltage source. This voltage source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model StepVoltage "Step voltage source"
  parameter SI.Voltage V(start=1) "Height of step";
  extends Interfaces.VoltageSource(redeclare Modelica.Blocks.Sources.Step
      signalSource(final height=V));
end StepVoltage;


Supply voltage (positive and negative). This is a simple model of a constant supply voltage with positive and negative supply, the potential between positive and negative supply is accessible.

within Modelica.Electrical.Analog.Sources;
model SupplyVoltage "Supply voltage (positive and negative)"
  parameter SI.Voltage Vps=+15 "Positive supply";
  parameter SI.Voltage Vns=-15 "Negative supply";
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_p
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_n
  Modelica.Electrical.Analog.Interfaces.NegativePin ground
  Modelica.Electrical.Analog.Sources.ConstantVoltage positiveSupply(final V=
        Vps)
  Modelica.Electrical.Analog.Sources.ConstantVoltage negativeSupply(final V=-
        Vns)
equation
  connect(pin_p, positiveSupply.p)
  connect(negativeSupply.n, pin_n)
  connect(positiveSupply.n, ground)
  connect(ground, negativeSupply.p)
end SupplyVoltage;


Current source by linear interpolation in a table. This current source uses the corresponding signal source of the Modelica.Blocks.Sources package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model TableCurrent "Current source by linear interpolation in a table"
  parameter Real table[:, :]=[0, 0; 1, 1; 2, 4]
    "Table matrix (time = first column, current = second column)";
  extends Interfaces.CurrentSource(redeclare
      Modelica.Blocks.Sources.TimeTable signalSource(final table=table));
end TableCurrent;


Voltage source by linear interpolation in a table. This voltage source uses the corresponding signal source of the Modelica.Blocks.Sources package.  Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model TableVoltage "Voltage source by linear interpolation in a table"
  parameter Real table[:, :]=[0, 0; 1, 1; 2, 4]
    "Table matrix (time = first column, voltage = second column)";
  extends Interfaces.VoltageSource(redeclare
      Modelica.Blocks.Sources.TimeTable signalSource(final table=table));
end TableVoltage;