Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSL 4.1.0 Regressions: OpAmps/SignalGenerator #4485

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Modelica/Electrical/Analog/Examples/OpAmps/Adder.mo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ model Adder "Inverting adder"
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 Down
17 changes: 5 additions & 12 deletions Modelica/Electrical/Analog/Examples/OpAmps/ControlCircuit.mo
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,23 @@ model ControlCircuit "Control circuit"
extent={{-10,-10},{10,10}},
rotation=270,
origin={-90,-62})));
OpAmpCircuits.Feedback feedbackA(p1(i(start=0)))
OpAmpCircuits.Feedback feedbackA
annotation (Placement(transformation(extent={{-70,-40},{-50,-20}})));
OpAmpCircuits.PI PIA(
v2(fixed=true),
k=kp,
T=Ti,
opAmp(v_in(start=0)))
v(fixed=true))
annotation (Placement(transformation(extent={{-40,-40},{-20,-20}})));
OpAmpCircuits.FirstOrder firstOrder1A(
v2(fixed=true),
T=T1,
opAmp(v_in(start=0)))
OpAmpCircuits.FirstOrder firstOrder1A(T=T1, v(fixed=true))
annotation (Placement(transformation(extent={{-10,-40},{10,-20}})));
OpAmpCircuits.Add addA(i1_2(start=0), r(i(start=0)))
OpAmpCircuits.Add addA
annotation (Placement(transformation(extent={{30,-40},{50,-20}})));
Sources.StepVoltage step1A(V=1, startTime=0.5) annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={20,-60})));
OpAmpCircuits.FirstOrder firstOrder2A(
v2(fixed=true),
T=T2,
opAmp(v_in(start=0)))
OpAmpCircuits.FirstOrder firstOrder2A(T=T2, v(fixed=true))
annotation (Placement(transformation(extent={{60,-40},{80,-20}})));
Blocks.Sources.Step stepB(height=10, startTime=0.1)
annotation (Placement(transformation(extent={{-100,60},{-80,80}})));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ model DifferentialAmplifier "Differential amplifier"
Vps=+data.VSupply,
Vns=-data.VSupply)
annotation (Placement(transformation(extent={{-20,-10},{0,10}})));
Modelica.Electrical.Analog.Basic.Resistor resistor1(R=data.R1,
i(start=0, fixed=false))
Modelica.Electrical.Analog.Basic.Resistor resistor1(R=data.R1)
annotation (Placement(transformation(extent={{-60,20},{-40,40}})));
Modelica.Electrical.Analog.Basic.Resistor resistor2(R=data.R2,
i(start=0, fixed=false))
Modelica.Electrical.Analog.Basic.Resistor resistor2(R=data.R2)
annotation (Placement(transformation(extent={{-60,-40},{-40,-20}})));
Modelica.Electrical.Analog.Basic.Resistor resistor3(R=data.R3)
annotation (Placement(transformation(extent={{-20,20},{0,40}})));
Expand Down
4 changes: 2 additions & 2 deletions Modelica/Electrical/Analog/Examples/OpAmps/HighPass.mo
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ model HighPass "High-pass filter"
extent={{-10,10},{10,-10}},
rotation=270,
origin={40,0})));
OpAmpCircuits.Derivative derivative(T=1/(2*pi*fG),
v(fixed=true))
OpAmpCircuits.Derivative derivative(
T=1/(2*pi*fG), v(fixed=true))
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
Sources.TrapezoidVoltage vIn(
V=Vin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ model InvertingSchmittTrigger "Inverting Schmitt trigger with hysteresis"
Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp(
Vps=Vps,
Vns=Vns,
out(i(start=0)))
strict=false,
smoothed=false,
regularized=true)
annotation (Placement(transformation(extent={{0,-10},{20,10}})));
Modelica.Electrical.Analog.Basic.Ground ground
annotation (Placement(transformation(extent={{-20,-100},{0,-80}})));
Expand Down
2 changes: 1 addition & 1 deletion Modelica/Electrical/Analog/Examples/OpAmps/LCOscillator.mo
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ model LCOscillator "LC oscillator"
annotation (Placement(transformation(extent={{-50,10},{-30,-10}})));
Modelica.Electrical.Analog.Basic.Resistor r(R=R)
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
Modelica.Electrical.Analog.Basic.Resistor r2(R=R2, i(start=0)) annotation (
Modelica.Electrical.Analog.Basic.Resistor r2(R=R2) annotation (
Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
Expand Down
9 changes: 5 additions & 4 deletions Modelica/Electrical/Analog/Examples/OpAmps/Multivibrator.mo
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ model Multivibrator "Multivibrator with Schmitt trigger"
Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp(
Vps=Vps,
Vns=Vns,
homotopyType = Modelica.Blocks.Types.LimiterHomotopy.LowerLimit,
strict = true) annotation (Placement(transformation(extent={{0,-10},{20,10}})));
strict=false,
regularized=true)
annotation (Placement(transformation(extent={{0,-10},{20,10}})));
Modelica.Electrical.Analog.Basic.Ground ground
annotation (Placement(transformation(extent={{-20,-80},{0,-60}})));
Modelica.Electrical.Analog.Sensors.VoltageSensor vOut annotation (Placement(
transformation(
extent={{-10,10},{10,-10}},
rotation=270,
origin={50,-20})));
Modelica.Electrical.Analog.Basic.Resistor r1(R=R1, i(start=0)) annotation (
Modelica.Electrical.Analog.Basic.Resistor r1(R=R1, p(i(start=0))) annotation (
Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270,
Expand All @@ -31,7 +32,7 @@ model Multivibrator "Multivibrator with Schmitt trigger"
origin={10,-20})));
Modelica.Electrical.Analog.Basic.Resistor r(R=R)
annotation (Placement(transformation(extent={{20,20},{0,40}})));
Modelica.Electrical.Analog.Basic.Capacitor c(C=C, v(start=1, fixed=true))
Modelica.Electrical.Analog.Basic.Capacitor c(C=C, v(start=0.1, fixed=true))
annotation (Placement(transformation(
extent={{10,-10},{-10,10}},
rotation=90,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
within Modelica.Electrical.Analog.Examples.OpAmps.OpAmpCircuits;
model FirstOrder "Lowpass filter operational amplifier circuit"
extends PartialOpAmp(v2(start=0));
extends PartialOpAmp;
import Modelica.Constants.pi;
parameter Real k(final min=0)=1 "Desired amplification";
parameter SI.Resistance R1=1000 "Resistance at negative input of OpAmp";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
within Modelica.Electrical.Analog.Examples.OpAmps.OpAmpCircuits;
model Integrator "Integrating operational amplifier circuit"
extends PartialOpAmp(v2(start=0));
extends PartialOpAmp;
import Modelica.Constants.pi;
parameter Real k(final min=0)=1 "Desired amplification at frequency f";
parameter SI.Frequency f "Frequency";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
within Modelica.Electrical.Analog.Examples.OpAmps.OpAmpCircuits;
model PI "PI controller operational amplifier circuit"
extends PartialOpAmp(v2(start=0));
extends PartialOpAmp;
import Modelica.Constants.pi;
parameter Real k(final min=0)=1 "Desired amplification";
parameter SI.Resistance R1=1000 "Resistance at negative input of OpAmp";
Expand All @@ -13,6 +13,7 @@ model PI "PI controller operational amplifier circuit"
annotation (Placement(transformation(extent={{30,20},{10,40}})));
Basic.Capacitor c(C=C)
annotation (Placement(transformation(extent={{60,20},{40,40}})));
SI.Voltage v(start=0)=c.v "Capacitor voltage = state";
equation
connect(n1, n2)
annotation (Line(points={{-100,-100},{100,-100}}, color={0,0,255}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ partial model PartialOpAmp
V0=V0,
final useSupply=false,
final Vps=Vps,
final Vns=Vns,
out(i(start=0, fixed=false)))
final Vns=Vns)
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
annotation (Icon(coordinateSystem(preserveAspectRatio=false), graphics={
Text(
Expand Down
11 changes: 6 additions & 5 deletions Modelica/Electrical/Analog/Examples/OpAmps/SchmittTrigger.mo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ model SchmittTrigger "Schmitt trigger with hysteresis"
Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp(
Vps=Vps,
Vns=Vns,
out(i(start=0)))
strict=false,
smoothed=false,
regularized=true)
annotation (Placement(transformation(extent={{0,10},{20,-10}})));
Modelica.Electrical.Analog.Basic.Ground ground
annotation (Placement(transformation(extent={{-20,-100},{0,-80}})));
Expand Down Expand Up @@ -64,8 +66,7 @@ equation
<p>The example is taken from: U. Tietze and C. Schenk, Halbleiter-Schaltungstechnik (German), 11th edition, Springer 1999, Chapter 6.5.2</p>
</html>"),
experiment(
StartTime=0,
StopTime=1,
Tolerance=1e-006,
Interval=0.001));
Interval=0.001,
Tolerance=1e-06,
__Dymola_Algorithm="Dassl"));
end SchmittTrigger;
10 changes: 4 additions & 6 deletions Modelica/Electrical/Analog/Examples/OpAmps/SignalGenerator.mo
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ model SignalGenerator "Rectangle-Triangle generator"
Vps=Vps,
Vns=Vns,
strict=false,
homotopyType=Modelica.Blocks.Types.LimiterHomotopy.LowerLimit)
regularized=true)
annotation (Placement(transformation(extent={{-60,10},{-40,-10}})));
Modelica.Electrical.Analog.Basic.Resistor r2(R=R2, i(start=Vps/R2))
Modelica.Electrical.Analog.Basic.Resistor r2(R=R2, p(i(start=0)))
annotation (Placement(transformation(
extent={{10,10},{-10,-10}},
rotation=180,
Expand All @@ -29,11 +29,9 @@ model SignalGenerator "Rectangle-Triangle generator"
annotation (Placement(transformation(extent={{-10,-60},{10,-40}})));
Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp2(
Vps=Vps,
Vns=Vns,
v_in(start=0),
strict=false)
Vns=Vns)
annotation (Placement(transformation(extent={{30,-10},{50,10}})));
Modelica.Electrical.Analog.Basic.Capacitor c(C=C, v(fixed=true, start=0))
Modelica.Electrical.Analog.Basic.Capacitor c(C=C, v(fixed=true, start=10))
annotation (Placement(transformation(extent={{50,20},{30,40}})));
Modelica.Electrical.Analog.Basic.Resistor r(R=R)
annotation (Placement(transformation(extent={{-10,20},{10,40}})));
Expand Down
2 changes: 1 addition & 1 deletion Modelica/Electrical/Analog/Examples/OpAmps/Subtracter.mo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ model Subtracter "Inverting subtracter"
extent={{10,10},{-10,-10}},
rotation=270,
origin={40,0})));
OpAmpCircuits.Feedback feedback(p1_2(i(start=0)))
OpAmpCircuits.Feedback feedback
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
equation
connect(feedback.n1, ground.p)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ model VoltageFollower "Reproduce input voltage"
parameter SI.Resistance Rl=1 "Load resistance";
Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited opAmp(
Vps=Vps,
Vns=Vns,
v_in(start=0))
Vns=Vns)
annotation (Placement(transformation(extent={{0,-10},{20,10}})));
Modelica.Electrical.Analog.Basic.Ground ground
annotation (Placement(transformation(extent={{-20,-100},{0,-80}})));
Expand Down
2 changes: 1 addition & 1 deletion Modelica/Electrical/Analog/Examples/OpAmps/package.order
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ Comparator
InvertingSchmittTrigger
SchmittTrigger
Multivibrator
SignalGenerator
LCOscillator
SignalGenerator
OpAmpCircuits
85 changes: 72 additions & 13 deletions Modelica/Electrical/Analog/Ideal/IdealizedOpAmpLimited.mo
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ model IdealizedOpAmpLimited "Idealized operational amplifier with limitation"
annotation (Dialog(enable=not useSupply));
parameter SI.Voltage Vns=-15 "Negative supply voltage"
annotation (Dialog(enable=not useSupply));
parameter Boolean strict=true "= true, if strict limits with noEvent(..)"
parameter Boolean strict=false "= true, if strict limits with noEvent(..)"
annotation (Evaluate=true, choices(checkBox=true), Dialog(tab="Advanced"));
parameter Boolean smoothed=false "= true, if usage of smooth(0, ..)"
annotation (Evaluate=true, choices(checkBox=true), Dialog(tab="Advanced"));
parameter Boolean regularized=false "= true, if regularization instead of strict / smoothed"
annotation (Evaluate=true, choices(checkBox=true), Dialog(tab="Advanced"));
parameter Modelica.Blocks.Types.LimiterHomotopy homotopyType = Modelica.Blocks.Types.LimiterHomotopy.NoHomotopy "Simplified model for homotopy-based initialization"
annotation (Evaluate=true, Dialog(group="Initialization"));
SI.Voltage vps "Positive supply voltage";
SI.Voltage vns "Negative supply voltage";
SI.Voltage v_in=in_p.v - in_n.v "Input voltage difference";
SI.Voltage vps(start=Vps) "Positive supply voltage";
SI.Voltage vns(start=Vns) "Negative supply voltage";
SI.Voltage v_in(start=0)=in_p.v - in_n.v "Input voltage difference";
SI.Voltage v_out=out.v "Output voltage to ground";
SI.Current i_out(start=0)=-out.i "Output current";
SI.Power p_in=in_p.v*in_p.i + in_n.v*in_n.i "Input power";
SI.Power p_out=out.v*out.i "Output power";
SI.Power p_s=-(p_in + p_out) "Supply power";
Expand Down Expand Up @@ -49,19 +54,41 @@ equation
else if homotopyType == Modelica.Blocks.Types.LimiterHomotopy.UpperLimit then vps
else if homotopyType == Modelica.Blocks.Types.LimiterHomotopy.LowerLimit then vns
else 0);
if strict then
if regularized then
if homotopyType == Modelica.Blocks.Types.LimiterHomotopy.NoHomotopy then
v_out = smooth(0, noEvent(if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in));
v_out = (if v_in>0 then vps else -vns)*(2/(1 + Modelica.Math.exp(-v_in/(0.01*(if v_in>0 then vps else -vns)/V0)))-1);
else
v_out = homotopy(actual = smooth(0, noEvent(if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in)),
simplified=simplifiedExpr);
v_out = homotopy(actual = (if v_in>0 then vps else -vns)*(2/(1 + Modelica.Math.exp(-v_in/(0.01*(if v_in>0 then vps else -vns)/V0)))-1), simplified=simplifiedExpr);
end if;
else
if homotopyType == Modelica.Blocks.Types.LimiterHomotopy.NoHomotopy then
v_out = smooth(0, if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in);
else
v_out = homotopy(actual = smooth(0, if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in),
simplified=simplifiedExpr);
if strict and smoothed then
if homotopyType == Modelica.Blocks.Types.LimiterHomotopy.NoHomotopy then
v_out = smooth(0, noEvent(if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in));
else
v_out = homotopy(actual = smooth(0, noEvent(if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in)),
simplified=simplifiedExpr);
end if;
elseif strict and not smoothed then
if homotopyType == Modelica.Blocks.Types.LimiterHomotopy.NoHomotopy then
v_out = (noEvent(if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in));
else
v_out = homotopy(actual = (noEvent(if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in)),
simplified=simplifiedExpr);
end if;
elseif not strict and smoothed then
if homotopyType == Modelica.Blocks.Types.LimiterHomotopy.NoHomotopy then
v_out = smooth(0, (if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in));
else
v_out = homotopy(actual = smooth(0, (if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in)),
simplified=simplifiedExpr);
end if;
else // neither strict nor smoothed
if homotopyType == Modelica.Blocks.Types.LimiterHomotopy.NoHomotopy then
v_out = ((if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in));
else
v_out = homotopy(actual = (noEvent(if V0*v_in>vps then vps else if V0*v_in<vns then vns else V0*v_in)),
simplified=simplifiedExpr);
end if;
end if;
end if;
annotation (defaultComponentName="opAmp",
Expand Down Expand Up @@ -94,6 +121,38 @@ equation
</ul>
<p>Supply voltage is either defined by parameter Vps and Vns or by (optional) pins s_p and s_n.</p>
<p>In the first case the necessary power is drawn from an implicit internal supply, in the second case from the external supply.</p>
<p>You may choose between different implementations for calculating output voltage from input voltage:</p>
<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\">
<tr>
<th>regularized</th><th>smoothed</th><th>strict </th>
<th>explanation</th>
</tr>
<tr>
<td>true </td><td> </td><td> </td>
<td>uses a regularization formula which is nearly linear around 0 and saturates at positive resp. negative supply</td>
</tr>
<tr>
<td>false </td><td>false </td><td>false </td>
<td>uses a linear relationship and saturates at positive resp. negative supply without using smooth and/or noEvent</td>
</tr>
<tr>
<td>false </td><td>true </td><td>false </td>
<td>uses a linear relationship and saturates at positive resp. negative supply using smooth but without noEvent</td>
</tr>
<tr>
<td>false </td><td>false </td><td>true </td>
<td>uses a linear relationship and saturates at positive resp. negative supply without using smooth but using noEvent</td>
</tr>
<tr>
<td>false </td><td>true </td><td>true </td>
<td>uses a linear relationship and saturates at positive resp. negative supply using both smooth and noEvent</td>
</tr>
</table>
<p>
Recommendation:<br>
Use of the opAmp in the linear range: regularized = false, smoothed = false, strict = false.<br>
Use of the opAmp as switching device: regularized = true, smoothed = false, strict = false.
</p>
<p>If initialization is problematic for a model containing this as a component you can set the <strong>homotopyType</strong> parameter.
Using <strong>Linear</strong> ignores the saturation initially which simplifies the initialization, and may help if the component
is connected with negative feedback; but generally fails if the feedback is positive.
Expand Down
Loading