Skip to content

Conversation

@AHaumer
Copy link
Contributor

@AHaumer AHaumer commented May 15, 2025

This PR replaces #4485 which will be closed but we still can look up the discussions.
The following explanation could be used for future release notes:
Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimited has been declared as deprecated since some of the results (Modelica.Electrical.Analog.Examples.OpAmps) could not be compared between different tools, because the usage of noEvent() and smooth() for saturation prevented exact events in switching applications.
As a replacement Modelica.Electrical.Analog.Ideal.ImprovedOpAmpLimited has been implemented, thoroughly tested with different tools and used in the above mentioned examples. Saturation has been designed simpler, events are triggered by two Boolean variables that indicate saturation. Additionally a firstOrder models rise time of the OpAmp. Initialization is now without homopotopy acting on the result of the firstOrder (before saturation acts on the output).

@AHaumer AHaumer added this to the MSL4.2.0 milestone May 15, 2025
@AHaumer AHaumer self-assigned this May 15, 2025
@AHaumer AHaumer added bug Critical/severe issue L: Electrical.Analog Issue addresses Modelica.Electrical.Analog labels May 15, 2025
@HansOlsson
Copy link
Contributor

I'll look into it.
Just a quick style-question - is there a particular reason you switched from SI.Frequency (etc) to Modelica.Units.SI.Frequency?

@AHaumer
Copy link
Contributor Author

AHaumer commented May 15, 2025

@HansOlsson this was by accident.
I copied all the OpAmp stuff out of MSL, then developed and tested and copied back in.
You're right, looks clumsy. Therefore replaced all Modelica.Units.SI. by SI.

@maltelenz
Copy link
Contributor

Without looking at the actual changes, I ran the full MSL tests, and got result differences in Adder, ControlCircuit and Subtracter.

Blue is the reference data, orange is the new result with this PR.

Adder:
image

In ControlCircuit it looks like an event became a softer transition at 0.5? This is zoomed in:

image

Subtracter:
image

@AHaumer
Copy link
Contributor Author

AHaumer commented May 15, 2025

Sorry @maltelenz I forgot to mention:

  • In some examples I flipped the output voltage sensor vertically. That explains the drastic differences.
  • Of course, in detail some results might be different (due to the firstOrder!)
    Important: The SignalGenerator runs stable!

@GallLeo please generate new reference results for Modelica.Electrical.Analog.Examples.OpAmps.*
after this PR has been accepted and merged.

@AHaumer
Copy link
Contributor Author

AHaumer commented May 16, 2025

After merging this PR, I'll prepare another PR containing a remake of Modelica.Electrical.Examples.ChuaCircuit using realistic parameters (mH and pF insteaf of H and F), showing the path from 2 periodic attractors to chaos and an additonal example demonstrating how the characteristic of Chua's diode could be implemented with 2 OpAmp-circuits called NIC (negative impedance converter) - that example relies on the OpAmp-model of this PR.

Copy link
Contributor

@HansOlsson HansOlsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general good, but I would need some feedback on the filter-part.

@AHaumer
Copy link
Contributor Author

AHaumer commented May 16, 2025

In general good, but I would need some feedback on the filter-part.

You mean the firstOrder? Give me some time over the weekend to design initialization.

@AHaumer AHaumer requested a review from HansOlsson May 16, 2025 20:18
@AHaumer
Copy link
Contributor Author

AHaumer commented May 16, 2025

@HansOlsson I hope I addressed all your concerns, please re-review.
Now the firstOrder is optional (and therefore the initialization for it). It is needed only in 2 examples: MultiVibrator and SignalGenerator. The results seem to be the same in Dymola, OpenModelica and SystemModeler.
@casella @maltelenz @henrikt-ma may I kindly ask for your review?

Copy link
Contributor

@henrikt-ma henrikt-ma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a domain expert, so this set of changes is too big for me to comprehend. However, I am pleased to see that @maltelenz is reporting any consequences this will have in our test suite, and that @HansOlsson is paying attention to possibly unintentional stylistic changes.

@AHaumer
Copy link
Contributor Author

AHaumer commented May 17, 2025

Ok there a some cosmetic changes (my fault I know) in the examples.
The main work is a nearly complete redesign of the OpAmp model, some more explanations:

  • The differential input voltage is either just amplified by V0 or (optional) additionally delayed with a firstOrder, this gives the fictional intermediate voltage
  • If the optional firstOrder is activated this intermediate voltage can be initialized as Linear, UpperLimit, LowerLimit.
  • This intermediate voltage gets limited between positive and negative supply without triggering events to get output voltage.
  • Events are triggered by 2 Boolean indicators of saturation, so saturation should be documented exactly.

Should I include a test model (meaybe in ModelicaTest?) measuring the rise time?
To meet the RiseTime stated in data sheet (e.g. LM741 0.3 µs), the time constant has to be set to V0/log(9)*RiseTime.
RiseTime is measured in a voltageFollower circuit and defined by Tr = t90 - t10 where
0.1 = 1 - exp(-t10/Tau) and 0.9 = 1 - exp(-t90/Tau), using a step input.
The differential equation for the voltageFollower taking the firstOrder into account but avoiding saturation is:
Tau*der(vOut) = V0*(vStep - vOut) - vOut.
Many applications are nearly not affected by this firstOrder, so it is deactivated.
For some applications the user would have to carefully compare time constant and transient behaviour of his input.
For some applications (MultiVibrator and SignalGenerator) the firstOrder is essential to eases numerical solution.

@AHaumer
Copy link
Contributor Author

AHaumer commented May 17, 2025

wait wait wait ... silly me: I forgot to check / adapt the comparisonSignals.

Then I want another change of the order of the examples. After that we get:

  • 10 examples using the ready-to-use models from OpAmpCircuits
  • 4 non-autonomous circuits and 1 autonomous (up to now uncritical) switching circuit
  • 2 autonomous critical circuits

And I'll implement the correct measurement of rise time in ModelicaTest.

All done after the following commit (latest this evening).

nice order of examples
new example MeasureRiseTime
Copy link
Contributor

@christiankral christiankral left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if ImprovedOpAmpLimited is a good choice for a component name. One day IdealizedOpAmpLimited will be removed and we might not remember exactly what was improved ...

@christiankral
Copy link
Contributor

Sorry @maltelenz I forgot to mention:

  • In some examples I flipped the output voltage sensor vertically. That explains the drastic differences.

We might want to add a comment in Modelica.Electrical.Analog.UsersGuide.ReleaseNotes in case someone is wondering why the results appear differently in MSL 4.1.0.

@AHaumer AHaumer requested a review from christiankral May 18, 2025 19:38
@AHaumer
Copy link
Contributor Author

AHaumer commented May 18, 2025

@christiankral I accepted all your valuable suggestions with 9209342.
Regarding the naming, in Modelica.Electrical.Analog.Ideal we have;

  • IdealOpAmp (infinite gain, no saturation)
  • IdealOpAmp3Pin (infinite gain, no saturation)
  • IdealOpAmpLimited (infinite gain, saturation, compulsory supply)
  • deprecated IdealizedOpAmpLimited (finite gain, saturation, optional supply)
  • new ImprovedOpAmpLimited (finite gain, saturation, optional supply, optional firstOrder rise of output, stability)

The new one is not only improved comparing wih the deprecated one, but also with the older three.

Copy link
Contributor

@christiankral christiankral left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK then, so we stick with the name ImprovedOpAmpLimited.

If I everybody else agrees with the name, it's fine with me, too...

@AHaumer
Copy link
Contributor Author

AHaumer commented May 19, 2025

Text for release notes:
ImprovedOpAmpLimited replaces IdealizedOpAmpLimited (which is deprecated), with finite gain, saturation, optional supply and optional firstOrder rise of output which improves stability.
The examples in OpAmps are adapted to use the new ImprovedOpAmpLimited and harmonized polarity of output voltage sensor.
@GallLeo @MatthiasBSchaefer please provide new reference results for all examples in Modelica.Electrical.Analog.Examples.OpAmps after this PR has been merged.

@AHaumer AHaumer merged commit 742bc58 into modelica:master May 19, 2025
2 checks passed
@beutlich beutlich removed request for casella and maltelenz May 19, 2025 18:50
@casella
Copy link
Contributor

casella commented May 20, 2025

Unfortunately the discussion on the naming was too quick for me to react. I don't really think that "Improved" is a good attribute for any Modelica Standard Library model. Same as "New". It is new or improved now, and then it will be soon obsolete, as all things human.

The name should describe what the model represents, not how its development history went.

Why don't we just call it OpAmpLimited? It's not idealized, because it has a finite gain. So, it's just an op amp. @AHaumer do you agree?

@AHaumer AHaumer added the create new reference results create new reference results label May 29, 2025
AHaumer added a commit to AHaumer/ModelicaStandardLibrary that referenced this pull request Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Critical/severe issue create new reference results create new reference results L: Electrical.Analog Issue addresses Modelica.Electrical.Analog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants