Skip to content

Commit

Permalink
My suggestion according to discussions in modelica#4333 and modelica#…
Browse files Browse the repository at this point in the history
…4485 (this PR)
  • Loading branch information
AHaumer committed Jan 10, 2025
1 parent 163b01c commit 22c7327
Show file tree
Hide file tree
Showing 30 changed files with 507 additions and 352 deletions.
24 changes: 12 additions & 12 deletions Modelica/Electrical/Analog/Examples/OpAmps/Adder.mo
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
within Modelica.Electrical.Analog.Examples.OpAmps;
model Adder "Inverting adder"
extends Modelica.Icons.Example;
parameter SI.Voltage Vin=5 "Amplitude of input voltage";
parameter SI.Frequency f=10 "Frequency of input voltage";
parameter Modelica.Units.SI.Voltage Vin=5 "Amplitude of input voltage";
parameter Modelica.Units.SI.Frequency f=10 "Frequency of input voltage";
Modelica.Electrical.Analog.Basic.Ground ground
annotation (Placement(transformation(extent={{-20,-40},{0,-20}})));
Sources.SineVoltage vIn1(V=Vin, f=f) annotation (Placement(
transformation(
Modelica.Electrical.Analog.Sources.SineVoltage vIn1(V=Vin, f=f) annotation (
Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={-60,0})));
Sources.ConstantVoltage vIn2(V=Vin) annotation (Placement(
transformation(
Modelica.Electrical.Analog.Sources.ConstantVoltage vIn2(V=Vin) annotation (
Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={-40,-10})));
Modelica.Electrical.Analog.Sensors.VoltageSensor vOut annotation (Placement(
transformation(
extent={{10,10},{-10,-10}},
extent={{-10,10},{10,-10}},
rotation=270,
origin={40,0})));
OpAmpCircuits.Add add(p1_2(i(start=0)))
OpAmpCircuits.Add add
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
equation
connect(add.n1, ground.p)
Expand All @@ -33,10 +33,10 @@ equation
annotation (Line(points={{-10,-20},{-40,-20}}, color={0,0,255}));
connect(ground.p, vIn1.n)
annotation (Line(points={{-10,-20},{-60,-20},{-60,-10}}, color={0,0,255}));
connect(add.p2, vOut.n)
annotation (Line(points={{10,10},{40,10}}, color={0,0,255}));
connect(add.n2, vOut.p)
annotation (Line(points={{10,-10},{40,-10}}, color={0,0,255}));
connect(vOut.p, add.p2)
annotation (Line(points={{40,10},{10,10}}, color={0,0,255}));
connect(vOut.n, add.n2)
annotation (Line(points={{40,-10},{10,-10}}, color={0,0,255}));
annotation (Documentation(info="<html>
<p>This is an inverting adder.</p>
<p>Note: <code>vOut</code> measure the negative output voltage.</p>
Expand Down
53 changes: 32 additions & 21 deletions Modelica/Electrical/Analog/Examples/OpAmps/Comparator.mo
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
within Modelica.Electrical.Analog.Examples.OpAmps;
model Comparator "Comparator"
extends Modelica.Icons.Example;
parameter SI.Voltage Vps=+15 "Positive supply";
parameter SI.Voltage Vns=-15 "Negative supply";
parameter SI.Voltage Vin=5 "Amplitude of input voltage";
parameter SI.Frequency f=10 "Frequency of input voltage";
parameter SI.Voltage Vref=0 "Reference voltage";
parameter Real V0=15000.0 "No-load amplification";
parameter Modelica.Units.SI.Voltage Vps=+15 "Positive supply";
parameter Modelica.Units.SI.Voltage Vns=-15 "Negative supply";
parameter Modelica.Units.SI.Voltage Vin=5 "Amplitude of input voltage";
parameter Modelica.Units.SI.Frequency f=10 "Frequency of input voltage";
parameter Modelica.Units.SI.Voltage Vref=0 "Reference voltage";
parameter Real k=(Vref - Vns)/(Vps - Vns) "Calculated potentiometer ratio to reach Vref";
parameter SI.Resistance R=1000 "Resistance of potentiometer";
Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp(Vps=Vps, Vns=
Vns) annotation (Placement(transformation(extent={{0,10},{20,-10}})));
parameter Modelica.Units.SI.Resistance R=1000 "Resistance of potentiometer";
Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp(
V0=V0,
useSupply=false,
Vps=Vps,
Vns=Vns,
regularized=true,
smoothed=false,
strict=false)
annotation (Placement(transformation(extent={{-10,10},{10,-10}})));
Modelica.Electrical.Analog.Basic.Ground ground
annotation (Placement(transformation(extent={{-20,-100},{0,-80}})));
annotation (Placement(transformation(extent={{-10,-100},{10,-80}})));
Modelica.Electrical.Analog.Sources.TrapezoidVoltage vIn(
rising=0.2/f,
width=0.3/f,
Expand All @@ -23,37 +31,40 @@ model Comparator "Comparator"
offset=-Vin) annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={-80,0})));
origin={-40,0})));
Modelica.Electrical.Analog.Sensors.VoltageSensor vOut annotation (Placement(
transformation(
extent={{-10,10},{10,-10}},
rotation=270,
origin={50,-20})));
origin={40,-10})));
Modelica.Electrical.Analog.Basic.Potentiometer potentiometer(R=R, rConstant=
k) annotation (Placement(transformation(
extent={{-10,10},{10,-10}},
origin={-10,-30})));
origin={-20,-30})));
Modelica.Electrical.Analog.Sources.SupplyVoltage supplyVoltage(Vps=Vps, Vns=
Vns) annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
origin={-10,-50})));
origin={-20,-50})));
equation
connect(vIn.p, opAmp.in_p) annotation (Line(
points={{-80,10},{-10,10},{-10,6},{0,6}}, color={0,0,255}));
points={{-40,10},{-10,10},{-10,6}}, color={0,0,255}));
connect(opAmp.out, vOut.p) annotation (Line(
points={{20,0},{50,0},{50,-10}}, color={0,0,255}));
points={{10,0},{40,0}}, color={0,0,255}));
connect(ground.p, vOut.n) annotation (Line(
points={{-10,-80},{50,-80},{50,-30}}, color={0,0,255}));
points={{0,-80},{40,-80},{40,-20}}, color={0,0,255}));
connect(ground.p, vIn.n) annotation (Line(
points={{-10,-80},{-80,-80},{-80,-10}}, color={0,0,255}));
points={{0,-80},{-40,-80},{-40,-10}}, color={0,0,255}));
connect(potentiometer.contact, opAmp.in_n) annotation (Line(
points={{0,-20},{0,-6}}, color={0,0,255}));
points={{-10,-20},{-10,-6}},
color={0,0,255}));
connect(potentiometer.pin_p, supplyVoltage.pin_p) annotation (Line(
points={{-20,-30},{-20,-50}}, color={0,0,255}));
points={{-30,-30},{-30,-50}}, color={0,0,255}));
connect(potentiometer.pin_n, supplyVoltage.pin_n) annotation (Line(
points={{0,-30},{0,-50}}, color={0,0,255}));
points={{-10,-30},{-10,-50}},
color={0,0,255}));
connect(ground.p, supplyVoltage.ground) annotation (Line(
points={{-10,-80},{-10,-50}}, color={0,0,255}));
points={{0,-80},{-20,-80},{-20,-50}},
color={0,0,255}));
annotation (Documentation(info="<html>
<p>This is a comparator. Resistance R1 can be chosen, resistance R2 is defined by the desired reference voltage Vref (between Vn and Vp). The output switches between Vn for input voltage &lt; Vref and Vp for input voltage &gt; Vref.</p>
</html>"),
Expand Down
33 changes: 18 additions & 15 deletions Modelica/Electrical/Analog/Examples/OpAmps/ControlCircuit.mo
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
within Modelica.Electrical.Analog.Examples.OpAmps;
model ControlCircuit "Control circuit"
extends Modelica.Icons.Example;
parameter SI.Time T1=0.01 "Small time constant";
parameter SI.Time T2=0.01 "Large time constant";
parameter SI.Time Ti=T2 "Integral time constant";
parameter Modelica.Units.SI.Time T1=0.01 "Small time constant";
parameter Modelica.Units.SI.Time T2=0.01 "Large time constant";
parameter Modelica.Units.SI.Time Ti=T2 "Integral time constant";
parameter Real kp=T2/(2*T1) "Proportional gain";
Modelica.Units.SI.Voltage yA=firstOrder2A.v2 "Result obtained with opAmps";
output Real yB=firstOrder2B.y "Exact result";
Modelica.Electrical.Analog.Basic.Ground ground
annotation (Placement(transformation(extent={{-100,-100},{-80,-80}})));
Sources.StepVoltage stepA(V=10, startTime=0.1) annotation (Placement(
transformation(
Modelica.Electrical.Analog.Sources.StepVoltage stepA(V=10, startTime=0.1)
annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={-90,-62})));
Expand All @@ -27,8 +29,8 @@ model ControlCircuit "Control circuit"
annotation (Placement(transformation(extent={{-10,-40},{10,-20}})));
OpAmpCircuits.Add addA(i1_2(start=0), r(i(start=0)))
annotation (Placement(transformation(extent={{30,-40},{50,-20}})));
Sources.StepVoltage step1A(V=1, startTime=0.5) annotation (Placement(
transformation(
Modelica.Electrical.Analog.Sources.StepVoltage step1A(V=1, startTime=0.5)
annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={20,-60})));
Expand All @@ -37,24 +39,25 @@ model ControlCircuit "Control circuit"
T=T2,
opAmp(v_in(start=0)))
annotation (Placement(transformation(extent={{60,-40},{80,-20}})));
Blocks.Sources.Step stepB(height=10, startTime=0.1)
Modelica.Blocks.Sources.Step stepB(height=10, startTime=0.1)
annotation (Placement(transformation(extent={{-100,60},{-80,80}})));
Blocks.Math.Feedback feedbackB
Modelica.Blocks.Math.Feedback feedbackB
annotation (Placement(transformation(extent={{-70,60},{-50,80}})));
Blocks.Continuous.PI PIB(
Modelica.Blocks.Continuous.PI PIB(
k=kp,
T=Ti,
initType=Modelica.Blocks.Types.Init.InitialOutput)
annotation (Placement(transformation(extent={{-40,60},{-20,80}})));
Blocks.Continuous.FirstOrder firstOrder1B(T=T1, initType=Modelica.Blocks.Types.Init.InitialOutput)
Modelica.Blocks.Continuous.FirstOrder firstOrder1B(T=T1, initType=Modelica.Blocks.Types.Init.InitialOutput)
annotation (Placement(transformation(extent={{-10,60},{10,80}})));
Blocks.Math.Add addB
Modelica.Blocks.Math.Add addB
annotation (Placement(transformation(extent={{30,60},{50,80}})));
Blocks.Sources.Step step1B(height=1, startTime=0.5)
annotation (Placement(transformation(extent={{-10,-10},{10,10}},
Modelica.Blocks.Sources.Step step1B(height=1, startTime=0.5) annotation (
Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=90,
origin={20,30})));
Blocks.Continuous.FirstOrder firstOrder2B(T=T2, initType=Modelica.Blocks.Types.Init.InitialOutput)
Modelica.Blocks.Continuous.FirstOrder firstOrder2B(T=T2, initType=Modelica.Blocks.Types.Init.InitialOutput)
annotation (Placement(transformation(extent={{60,60},{80,80}})));
equation
connect(stepA.n, ground.p)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
within Modelica.Electrical.Analog.Examples.OpAmps;
model DifferentialAmplifier "Differential amplifier"
extends Modelica.Icons.Example;
parameter
Modelica.Electrical.Analog.Examples.OpAmps.OpAmpCircuits.DifferentialAmplifierData
data "Parameters for source, OpAmp and measurement"
annotation (Placement(transformation(extent={{50,10},{70,30}})));
parameter OpAmps.OpAmpCircuits.DifferentialAmplifierData data
"Parameters for source, OpAmp and measurement"
annotation (Placement(transformation(extent={{50,10},{70,30}})));
Modelica.Electrical.Analog.Sources.SineVoltage sourceVoltage1(
V=sqrt(2/3)*data.VSource,
phase=1.0471975511966,
Expand Down Expand Up @@ -37,7 +36,12 @@ model DifferentialAmplifier "Differential amplifier"
V0=data.V0,
useSupply=true,
Vps=+data.VSupply,
Vns=-data.VSupply)
Vns=-data.VSupply,
regularized=false,
smoothed=false,
strict=false,
vps(start=+data.VSupply),
vns(start=-data.VSupply))
annotation (Placement(transformation(extent={{-20,-10},{0,10}})));
Modelica.Electrical.Analog.Basic.Resistor resistor1(R=data.R1,
i(start=0, fixed=false))
Expand Down
9 changes: 4 additions & 5 deletions Modelica/Electrical/Analog/Examples/OpAmps/Differentiator.mo
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
within Modelica.Electrical.Analog.Examples.OpAmps;
model Differentiator "Differentiating amplifier"
extends Modelica.Icons.Example;
parameter SI.Voltage Vin=5 "Amplitude of input voltage";
parameter SI.Frequency f=10 "Frequency of input voltage";
parameter Modelica.Units.SI.Voltage Vin=5 "Amplitude of input voltage";
parameter Modelica.Units.SI.Frequency f=10 "Frequency of input voltage";
Modelica.Electrical.Analog.Basic.Ground ground
annotation (Placement(transformation(extent={{-20,-40},{0,-20}})));
Sources.TrapezoidVoltage vIn(
Modelica.Electrical.Analog.Sources.TrapezoidVoltage vIn(
V=2*Vin,
rising=0.2/f,
width=0.3/f,
falling=0.2/f,
period=1/f,
nperiod=-1,
offset=-Vin,
startTime=-(vIn.rising + vIn.width/2))
annotation (Placement(
startTime=-(vIn.rising + vIn.width/2)) annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=270,
Expand Down
11 changes: 5 additions & 6 deletions Modelica/Electrical/Analog/Examples/OpAmps/HighPass.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ within Modelica.Electrical.Analog.Examples.OpAmps;
model HighPass "High-pass filter"
extends Modelica.Icons.Example;
import Modelica.Constants.pi;
parameter SI.Voltage Vin=5 "Amplitude of input voltage";
parameter SI.Frequency f=10 "Frequency of input voltage";
parameter SI.Frequency fG=f/10 "Limiting frequency";
parameter Modelica.Units.SI.Voltage Vin=5 "Amplitude of input voltage";
parameter Modelica.Units.SI.Frequency f=10 "Frequency of input voltage";
parameter Modelica.Units.SI.Frequency fG=f/10 "Limiting frequency";
Modelica.Electrical.Analog.Basic.Ground ground
annotation (Placement(transformation(extent={{-20,-40},{0,-20}})));
Modelica.Electrical.Analog.Sensors.VoltageSensor vOut annotation (Placement(
Expand All @@ -15,16 +15,15 @@ model HighPass "High-pass filter"
OpAmpCircuits.Derivative derivative(T=1/(2*pi*fG),
v(fixed=true))
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
Sources.TrapezoidVoltage vIn(
Modelica.Electrical.Analog.Sources.TrapezoidVoltage vIn(
V=Vin,
rising=0.2/f,
width=0.3/f,
falling=0.2/f,
period=1/f,
nperiod=-1,
offset=0,
startTime=-(vIn.rising + vIn.width/2))
annotation (Placement(
startTime=-(vIn.rising + vIn.width/2)) annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=270,
Expand Down
9 changes: 4 additions & 5 deletions Modelica/Electrical/Analog/Examples/OpAmps/Integrator.mo
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
within Modelica.Electrical.Analog.Examples.OpAmps;
model Integrator "Integrating amplifier"
extends Modelica.Icons.Example;
parameter SI.Voltage Vin=5 "Amplitude of input voltage";
parameter SI.Frequency f=10 "Frequency of input voltage";
parameter Modelica.Units.SI.Voltage Vin=5 "Amplitude of input voltage";
parameter Modelica.Units.SI.Frequency f=10 "Frequency of input voltage";
Modelica.Electrical.Analog.Basic.Ground ground
annotation (Placement(transformation(extent={{-20,-40},{0,-20}})));
Modelica.Electrical.Analog.Sensors.VoltageSensor vOut annotation (Placement(
Expand All @@ -15,16 +15,15 @@ model Integrator "Integrating amplifier"
f=f,
v(fixed=true))
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
Sources.TrapezoidVoltage vIn(
Modelica.Electrical.Analog.Sources.TrapezoidVoltage vIn(
V=2*Vin,
rising=0.2/f,
width=0.3/f,
falling=0.2/f,
period=1/f,
nperiod=-1,
offset=-Vin,
startTime=-(vIn.rising + vIn.width/2))
annotation (Placement(
startTime=-(vIn.rising + vIn.width/2)) annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=270,
Expand Down
11 changes: 5 additions & 6 deletions Modelica/Electrical/Analog/Examples/OpAmps/InvertingAmplifier.mo
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
within Modelica.Electrical.Analog.Examples.OpAmps;
model InvertingAmplifier "Inverting amplifier"
extends Modelica.Icons.Example;
parameter SI.Voltage Vin=5 "Amplitude of input voltage";
parameter SI.Frequency f=10 "Frequency of input voltage";
parameter Modelica.Units.SI.Voltage Vin=5 "Amplitude of input voltage";
parameter Modelica.Units.SI.Frequency f=10 "Frequency of input voltage";
Modelica.Electrical.Analog.Basic.Ground ground
annotation (Placement(transformation(extent={{-20,-40},{0,-20}})));
Modelica.Electrical.Analog.Sources.TrapezoidVoltage vIn(
Expand All @@ -20,7 +20,7 @@ model InvertingAmplifier "Inverting amplifier"
origin={-40,0})));
Modelica.Electrical.Analog.Sensors.VoltageSensor vOut annotation (Placement(
transformation(
extent={{10,10},{-10,-10}},
extent={{-10,10},{10,-10}},
rotation=270,
origin={40,0})));
OpAmpCircuits.Gain gain(k=2)
Expand All @@ -32,14 +32,13 @@ equation
annotation (Line(points={{-10,-10},{-10,-20}}, color={0,0,255}));
connect(gain.n1, vIn.n)
annotation (Line(points={{-10,-10},{-40,-10}}, color={0,0,255}));
connect(gain.p2, vOut.n)
connect(gain.p2, vOut.p)
annotation (Line(points={{10,10},{40,10}}, color={0,0,255}));
connect(gain.n2, vOut.p)
connect(gain.n2, vOut.n)
annotation (Line(points={{10,-10},{40,-10}}, color={0,0,255}));
annotation (
Documentation(info="<html>
<p>This is an inverting amplifier.</p>
<p>Note: <code>vOut</code> measure the negative output voltage.</p>
</html>"),
experiment(
StartTime=0,
Expand Down
Loading

0 comments on commit 22c7327

Please sign in to comment.