DC Power Supply

In this section, we’ll consider how a DC power supply model could be implemented in Modelica. We’ll show, once again, how a flat system model can be refactored to make use of a reusable subsystem model.

Flat Power Supply Model

In this case, our flat system model will be the DC power supply circuit shown here:

Flat switching power supply model

Implemented in Modelica, this model looks like this:

within ModelicaByExample.Subsystems.PowerSupply.Examples;
model FlatCircuit "A model with power source, AC-DC conversion and load in one diagram"
  import Modelica.Electrical.Analog;
  Analog.Sources.SineVoltage wall_voltage(V=120, freqHz=60)
    annotation (Placement(transformation(
        extent={{-10,-10},{10,10}},
        rotation=270, origin={-90,0})));
  Analog.Ideal.IdealClosingSwitch switch(Goff=0)
    annotation (Placement(transformation(extent={{-80,30},{-60,50}})));
  Analog.Ideal.IdealTransformer transformer(Lm1=1, n=10, considerMagnetization=false)
    annotation (Placement(transformation(extent={{-50,0},{-30,20}})));
  Analog.Ideal.IdealDiode D1(Vknee=0, Ron=1e-5, Goff=1e-5)
    annotation (Placement(
        transformation(
        extent={{-10,-10},{10,10}},
        rotation=45, origin={-12,20})));
  Analog.Basic.Capacitor capacitor(C=1e-2)
    annotation (Placement(
        transformation(
        extent={{-10,-10},{10,10}},
        rotation=270, origin={60,-10})));
  Analog.Basic.Resistor load(R=100)
    annotation (Placement(
        transformation(
        extent={{-10,-10},{10,10}},
        rotation=270, origin={100,-10})));
  Modelica.Blocks.Sources.BooleanStep step(startTime=0.25)
    annotation (Placement(transformation(extent={{-100,50},{-80,70}})));
  Analog.Ideal.IdealDiode D2(Vknee=0, Ron=1e-5, Goff=1e-5)
    annotation (Placement(
        transformation(
        extent={{-10,-10},{10,10}},
        rotation=-45, origin={12,20})));
  Analog.Ideal.IdealDiode D3(Vknee=0, Ron=1e-5, Goff=1e-5)
    annotation (Placement(
        transformation(
        extent={{-10,-10},{10,10}},
        rotation=-45, origin={-12,0})));
  Analog.Ideal.IdealDiode D4(Vknee=0, Ron=1e-5, Goff=1e-5)
    annotation (Placement(
        transformation(
        extent={{-10,-10},{10,10}},
        rotation=45, origin={12,0})));
  Analog.Basic.Ground ground1
    annotation (Placement(transformation(extent={{-100,-52},{-80,-32}})));
equation
  connect(switch.p, wall_voltage.p) annotation (Line(
      points={{-80,40},{-90,40},{-90,10}},
      color={0,0,255}, smooth=Smooth.None));
  connect(switch.n, transformer.p1) annotation (Line(
      points={{-60,40},{-50,40},{-50,15}},
      color={0,0,255}, smooth=Smooth.None));
  connect(step.y, switch.control) annotation (Line(
      points={{-79,60},{-70,60},{-70,47}},
      color={255,0,255}, smooth=Smooth.None));
  connect(D3.n, D4.p) annotation (Line(
      points={{-4.92893,-7.07107},{-2.46446,-7.07107},{-2.46446,-7.07107},{
          1.09406e-006,-7.07107},{1.09406e-006,-7.07107},{4.92893,-7.07107}},
      color={0,0,255}, smooth=Smooth.None));
  connect(D1.n, D2.p) annotation (Line(
      points={{-4.92893,27.0711},{2.18813e-006,28},{4.92893,28},{4.92893, 27.0711}},
      color={0,0,255}, smooth=Smooth.None));
  connect(D1.p, D3.p) annotation (Line(
      points={{-19.0711,12.9289},{-20,10},{-19.0711,7.07107}},
      color={0,0,255}, smooth=Smooth.None));
  connect(D2.n, D4.n) annotation (Line(
      points={{19.0711,12.9289},{19.0711,11.4644},{19.0711,11.4644},{19.0711,10},
          {19.0711,7.07107},{19.0711,7.07107}},
      color={0,0,255}, smooth=Smooth.None));
  connect(transformer.p2, D1.n) annotation (Line(
      points={{-30,15},{-30,34},{0,34},{0,27.0711},{-4.92893,27.0711}},
      color={0,0,255}, smooth=Smooth.None));
  connect(D4.p, transformer.n2) annotation (Line(
      points={{4.92893,-7.07107},{0,-7.07107},{0,-20},{-30,-20},{-30,5}},
      color={0,0,255}, smooth=Smooth.None));
  connect(wall_voltage.n, transformer.n1) annotation (Line(
      points={{-90,-10},{-90,-20},{-50,-20},{-50,5}},
      color={0,0,255}, smooth=Smooth.None));
  connect(wall_voltage.n, ground1.p) annotation (Line(
      points={{-90,-10},{-90,-32}},
      color={0,0,255}, smooth=Smooth.None));
  connect(transformer.n2, ground1.p) annotation (Line(
      points={{-30,5},{-30,-32},{-90,-32}},
      color={0,0,255}, smooth=Smooth.None));
  connect(load.p, D2.n) annotation (Line(
      points={{100,0},{100,12},{20,12},{20,12.9289},{19.0711,12.9289}},
      color={0,0,255}, smooth=Smooth.None));
  connect(load.p, capacitor.p) annotation (Line(
      points={{100,0},{100,12},{60,12},{60,0}},
      color={0,0,255}, smooth=Smooth.None));
  connect(D1.p, capacitor.n) annotation (Line(
      points={{-19.0711,12.9289},{-24,12.9289},{-24,-32},{60,-32},{60,-20}},
      color={0,0,255}, smooth=Smooth.None));
  connect(load.n, capacitor.n) annotation (Line(
      points={{100,-20},{100,-32},{60,-32},{60,-20}},
      color={0,0,255}, smooth=Smooth.None));
end FlatCircuit;

This kind of power supply works by taking an AC input voltage (120V at 60Hz), rectifying it and then passing it through a low-pass filter. If we simulate this model, we see the following voltage across the load resistor:

../../../_images/FC.png

Note that our target here is an output voltage of 12 volts. However, the greater the load on the power supply, the lower the quality of the output signal will be. In this particular simulation, the load is initially zero (because the load connecting the switch to the power supply is open). But when the switch is closed and current begins to flow through the load (the resistor named load), we start to see some artifact.

Hierarchical Power Supply

Once again, we’ll improve upon the flat version of our system by taking some collection of components and organizing them into a subsystem model. Our system level circuit then becomes:

Hierarchical power supply model

This model uses the BasicPowerSupply model whose diagram is shown here:

Reusable power supply subsystem model

The Modelica source code for this reusable power supply subsystem model is:

within ModelicaByExample.Subsystems.PowerSupply.Components;
model BasicPowerSupply "Power supply with transformer and rectifier"
  import Modelica.Electrical.Analog;
  parameter Modelica.SIunits.Capacitance C
    "Filter capacitance"
    annotation(Dialog(group="General"));
  parameter Modelica.SIunits.Conductance Goff=1.E-5
    "Backward state-off conductance (opened diode conductance)"
    annotation(Dialog(group="General"));
  parameter Modelica.SIunits.Resistance Ron=1.E-5
    "Forward state-on differential resistance (closed diode resistance)"
    annotation(Dialog(group="General"));
  parameter Real n
    "Turns ratio primary:secondary voltage"
    annotation(Dialog(group="Transformer"));
  parameter Boolean considerMagnetization=false
    "Choice of considering magnetization"
    annotation(Dialog(group="Transformer"));
  parameter Modelica.SIunits.Inductance Lm1
    "Magnetization inductance w.r.t. primary side"
    annotation(Dialog(group="Transformer", enable=considerMagnetization));

  Analog.Interfaces.NegativePin gnd
    "Pin to ground power supply"
    annotation (Placement(transformation(extent={{-110,-70},{-90,-50}})));
  Analog.Interfaces.PositivePin p
    "Positive pin on supply side"
    annotation (Placement(transformation(extent={{-110,50},{-90,70}})));
  Analog.Interfaces.PositivePin p_load
    "Positive pin for load side"
    annotation (Placement(transformation(extent={{90,50},{110,70}})));
  Analog.Interfaces.NegativePin n_load
    "Negative pin for load side"
    annotation (Placement(transformation(extent={{90,-70},{110,-50}})));
protected
  Analog.Ideal.IdealTransformer transformer(
    final n=n, final considerMagnetization=considerMagnetization,
    final Lm1=Lm1)
    annotation (Placement(transformation(extent={{-60,-10},{-40,10}})));
  Analog.Ideal.IdealDiode D1(final Vknee=0, final Ron=Ron, final Goff=Goff)
    annotation (Placement(
        transformation(
        extent={{-10,-10},{10,10}},
        rotation=45,
        origin={-2,10})));
  Analog.Basic.Capacitor capacitor(C=C)
    annotation (Placement(
        transformation(
        extent={{-10,-10},{10,10}},
        rotation=270,
        origin={70,-20})));
  Analog.Ideal.IdealDiode D2(final Vknee=0, final Ron=Ron, final Goff=Goff)
    annotation (Placement(
        transformation(
        extent={{-10,-10},{10,10}},
        rotation=-45,
        origin={22,10})));
  Analog.Ideal.IdealDiode D3(final Vknee=0, final Ron=Ron, final Goff=Goff)
    annotation (Placement(
        transformation(
        extent={{-10,-10},{10,10}},
        rotation=-45,
        origin={-2,-10})));
  Analog.Ideal.IdealDiode D4(final Vknee=0, final Ron=Ron, final Goff=Goff)
    annotation (Placement(
        transformation(
        extent={{-10,-10},{10,10}},
        rotation=45,
        origin={22,-10})));
equation
  connect(D3.n,D4. p) annotation (Line(
      points={{5.07107,-17.0711},{10,-18},{14.9289,-17.0711}},
      color={0,0,255},
      smooth=Smooth.None));
  connect(D1.n,D2. p) annotation (Line(
      points={{5.07107,17.0711},{10,18},{14.9289,18},{14.9289,17.0711}},
      color={0,0,255},
      smooth=Smooth.None));
  connect(D1.p,D3. p) annotation (Line(
      points={{-9.07107,2.92893},{-10,0},{-9.07107,-2.92893}},
      color={0,0,255},
      smooth=Smooth.None));
  connect(D2.n,D4. n) annotation (Line(
      points={{29.0711,2.92893},{30,0},{29.0711,-2.92893}},
      color={0,0,255},
      smooth=Smooth.None));
  connect(transformer.p2,D1. n) annotation (Line(
      points={{-40,5},{-40,24},{10,24},{10,17.0711},{5.07107,17.0711}},
      color={0,0,255},
      smooth=Smooth.None));
  connect(D4.p,transformer. n2) annotation (Line(
      points={{14.9289,-17.0711},{10,-17.0711},{10,-30},{-40,-30},{-40,-5}},
      color={0,0,255},
      smooth=Smooth.None));
  connect(D1.p, capacitor.n) annotation (Line(
      points={{-9.07107,2.92893},{-14,2.92893},{-14,-42},{70,-42},{70,-30}},
      color={0,0,255},
      smooth=Smooth.None));
  connect(transformer.n1, gnd) annotation (Line(
      points={{-60,-5},{-60,-60},{-100,-60}},
      color={0,0,255},
      smooth=Smooth.None));
  connect(transformer.n2, gnd) annotation (Line(
      points={{-40,-5},{-40,-60},{-100,-60}},
      color={0,0,255},
      smooth=Smooth.None));
  connect(transformer.p1, p) annotation (Line(
      points={{-60,5},{-60,60},{-100,60}},
      color={0,0,255},
      smooth=Smooth.None));
  connect(capacitor.p, D2.n) annotation (Line(
      points={{70,-10},{70,2.92893},{29.0711,2.92893}},
      color={0,0,255},
      smooth=Smooth.None));
  connect(capacitor.p, p_load) annotation (Line(
      points={{70,-10},{70,60},{100,60}},
      color={0,0,255},
      smooth=Smooth.None));
  connect(capacitor.n, n_load) annotation (Line(
      points={{70,-30},{70,-60},{100,-60}},
      color={0,0,255},
      smooth=Smooth.None));
end BasicPowerSupply;

There are a couple of interesting things to note about this model. First, we see the same organizational structure as we have before where parameters and connectors are made public while the internal components are protected. We can also see the use of the Dialog annotation to organize parameters into distinct groupings (in this case, "General" and "Transformer"). We can also see the use of the enable annotation in conjunction with considerMagnetization parameter to selectively expose the Lm1 parameter only in the cases where considerMagnetization is true.

Using our hierarchical system model we get, as expected, exactly the same results as we got for the flat version:

../../../_images/SSC.png

We can augment our system model to include an additional load (that comes online after some delay):

Flat switching power supply model

In that case, if we simulate the model we can see the impact that additional load will have on the quality of power supply output:

../../../_images/SSC_AL.png

By increasing the capacitance in the power supply, we can reduce the amplitude of the voltage fluctuations, e.g.,

../../../_images/SSC_ALC.png

However, if we increase the capacitance level too much, we will find that the power supply output is very slow to respond to load changes, e.g.,

../../../_images/SSC_ALC2.png

Conclusion

This example illustrates, once again, how a collection of components can be organized into a reusable subsystem model. This example follows the best practice of placing parameters and connectors in the public section of the resulting subsystem model while keeping the internal components in the protected section.