Skip to content

Operational Amplifiers - #4869

Open
AHaumer wants to merge 9 commits into
modelica:masterfrom
AHaumer:BetterOpAmp
Open

AHaumer wants to merge 9 commits into
modelica:masterfrom
AHaumer:BetterOpAmp

Conversation

@AHaumer

@AHaumer AHaumer commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Enhanced OpAmpLimited, described in detail in #4868.
Since this is much better soultion and the former PR #4643 (and #4653) are only in the master branch 4.2.0 dev, not in a release we should merge this before the next release.

@AHaumer AHaumer added this to the MSL4.2.0 milestone Nov 19, 2026
@AHaumer AHaumer self-assigned this Nov 19, 2026
@AHaumer AHaumer added enhancement New feature or enhancement L: Electrical.Analog Issue addresses Modelica.Electrical.Analog V: 4.2.0-dev Issue originates in MSL v4.2.0-dev (and is not present in earlier releases) labels Nov 19, 2026
@AHaumer AHaumer linked an issue Nov 19, 2026 that may be closed by this pull request
@MSL-RegressionTesting-CI

This comment was marked as outdated.

@MSL-RegressionTesting-CI

This comment was marked as outdated.

@MSL-RegressionTesting-CI

This comment was marked as outdated.

@MSL-RegressionTesting-CI

This comment was marked as outdated.

@MSL-RegressionTesting-CI

This comment was marked as outdated.

@MSL-RegressionTesting-CI

Copy link
Copy Markdown

@MSL-RegressionTesting-CI

This comment was marked as outdated.

@AHaumer

AHaumer commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

@MatthiasBSchaefer what is failing here? I can't find the issue, nothing red.
ok I see. I pushed the second commit (correct html typo) after inspecting the checks but before the CI run had finished.
Interrupting seems to be interpreted as failing. The following CI run was a success.

@MSL-RegressionTesting-CI

Copy link
Copy Markdown

@AHaumer

AHaumer commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Since I read #4723 about problems with smooth() in the SlewRateLimter, my experience during enhancement of the OpAmp:
I wanted to have a first order rise with limited slewrate, but prevent a wind-up effect. Here a simplified listing.
For 1. (satPos and satNeg) the events reaching the limits are handled correctly: satPos and satNeg are used in the rest of the equations.
For 2. (slewLim) the event handling reaching the limit is tool dependent: slewLim is not used in the rest of the equations.
The slew rate might not get limited correctly when using dv_slew = smooth(0, min(slewRate, max(-slewRate, dv)));
Conclusion: Be careful using smooth(0, ..) might lead to tool-dependent results!
Modelica Spec. 3.6 Operator 3.22 smooth "A tool is free to not generate events for expressions inside smooth."

model OpAmpLimited "Improved operational amplifier with limitation"
  parameter Real V0 "No-load amplification";
  parameter Modelica.Units.SI.Voltage Vps "Positive supply voltage";
  parameter Modelica.Units.SI.Voltage Vns "Negative supply voltage";
  parameter Modelica.Units.SI.Time Tau "Time constant of firstOrder rise";
  parameter Modelica.Units.SI.VoltageSlope slewRate "Slew rate";
  // 1. Indicate saturation and provide events without being involved in limitation
  Boolean satPos=v_int>=Vps "Positive Saturation";
  Boolean satNeg=v_int<=Vns "Negative Saturation";
  // 2. Indicate saturation of slew rate
  Boolean slewLim=abs(dv)>=slewRate "Saturation of voltage rise";
  Modelica.Units.SI.Voltage v_in(start=0)=in_p.v - in_n.v "Input voltage difference";
  Modelica.Units.SI.Voltage v_int "Intermediate voltage";
  Modelica.Units.SI.VoltageSlope dv "Unclamped voltage rise";
  Modelica.Units.SI.VoltageSlope dv_slew "Voltage rise clamped to slewRate";
  Modelica.Electrical.Analog.Interfaces.PositivePin in_p
    "Positive pin of the input port";
  Modelica.Electrical.Analog.Interfaces.NegativePin in_n
    "Negative pin of the input port";
  Modelica.Electrical.Analog.Interfaces.PositivePin out
    "Pin of the output port";
equation 
  //zero input currents
  in_p.i = 0;
  in_n.i = 0;
  //slew rate
 dv = (V0*v_in - v_int)/Tau;
 //limit slew rate without smooth(0, ) to enforce events
 dv_slew = min(slewRate, max(-slewRate, dv));
 //first order with anti-windup (stop integrator)
 der(v_int)= if (satPos and dv_slew>0) or (satNeg and dv_slew<0) then 0
    else dv_slew;
  //saturation of output: satPos and satNeg trigger events
  out.v = smooth(0, min(Vps, max(Vns, v_int)));
end OpAmpLimited;

@MSL-RegressionTesting-CI

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or enhancement L: Electrical.Analog Issue addresses Modelica.Electrical.Analog V: 4.2.0-dev Issue originates in MSL v4.2.0-dev (and is not present in earlier releases)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Operational Amplifiers

3 participants