Modelling a variable (i.e. nonlinear) capacitor in Simulink: how to make it stable?

30 views (last 30 days)
I am modelling a variable capacitor, which is described by the following nonlinear equation: . To implement this, I have been taking the standard approach of measuring the current i through the variable capacitor, integrating it to get the charge Q, and then dividing it by the capacitance at that time instant (necessary, since the capacitance varies) to get the voltage V across the capacitor, and then finally feeding that into a Controlled Voltage Source to generate that instantaneous voltage. See the image below for what this looks like in Simulink, and a well-done similar implementation on the FileExchange.
While this approach is relatively straightforward and simple, it is extremely sensitive and will produce voltages that approach infinity at the beginning of simulations. Even if I try saturating the output voltage (or alternatively, saturating the integrator), I still get unrealistic results. The only thing that makes it run "correctly" is making the sample time incredibly small, on the order of , which of course makes the simulation very slow and generates many data points (sometimes causing Simulink to crash). I should note that even at these small sample times, the voltage across the variable capacitor is unrealistically noisy. I have tried a number of other tricks but to no avail:
  • Initializing the integrator and the voltage source (and other elements in the larger circuit that this variable capacitor is a part of)
  • Trying a continuous vs. discrete integrator
  • Using a unit delay (or transfer function as advised by Guy on Simulink in this post)
  • Using ode15s or other nonlinear solvers
  • Making the capacitance a static value for several seconds to let the circuit settle into a steady-state before varying it
Note that is generated by a Sine Wave block and is never equal to zero.
I am guessing this is a broader issue pertinent to other applications, since I am feeding a measured quantity directly into an integrator, and the Current Measurement block has no reference for currents prior to simulation beginning (like the "chicken vs. egg").
Does anyone have any tips on how to either model variable capacitors or more generally, make integrators less sensitive? Thank you!
  7 Comments
David Skrovanek
David Skrovanek on 19 Jul 2022
It is attached to a more complicated circuit now, but I had the above mentioned issues even it was just a series RC circuit: the variable capacitor was connected in series with a DC voltage source and a load resistor.
Sam Chak
Sam Chak on 20 Jul 2022
If your capacitance is varying with time, then you can include it in the dynamical RC circuit model as an exogenous variable.

Sign in to comment.

Accepted Answer

Jon
Jon on 19 Jul 2022
It looks like you may be using some circuit block set that I don't have available, however just going back to fundamentals you could model it as shown in the screenshot below from the attached model. In this model I have put the capacitor in series with a voltage source
  3 Comments
Jon
Jon on 20 Jul 2022
I'm thinking that there may be a problem in your approach using the variable voltage source to apply the output of your variable capacitor. While mathematically, this seems to make sense, if you could instantaneously adjust the voltage source to exactly follow the capacitors voltage. I'm wondering though whether in the implementation this causes numerical problems. I can imagine that during a particular time step the voltage source will maintain its voltage regardles of how much current is required. The voltage on the real capacitor on the other hand would immediately respond to the integrated current and start increasing or decreasing. So it would be good if you could try an alternative way of applying the output voltage from your capacitor. I would suggest the following:
First, I'm guessing that you are using Simscape to model the electronic components. As I mentioned, I don't have that so I can't try directly but from browsing the docs a little I see that there are Simulink to Physical and Physical to Simulink Signal blocks https://www.mathworks.com/help/physmod/simscape/ug/creating-and-simulating-a-simple-model.html https://www.mathworks.com/help/physmod/simscape/ref/simulinkpsconverter.html
One idea would be to model the variable capacitor as I indicated (and similar to your approach except with a continous integrator) using the continuous integrator in Simulink with the input current coming from a Physical to Simulink block connected to the rest of the diagram. The voltage, V = Q/C would then be converted to a Simscape signal and applied to your Simscape circuit.

Sign in to comment.

More Answers (0)

Categories

Find more on Composite Components in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!