Timeline for Why do I get wrong values from non-linear capacitor model in LTspice?
Current License: CC BY-SA 4.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Apr 17, 2023 at 23:42 | comment | added | Ste Kulov |
@A.Stickel I think you might've misunderstood what I said (or maybe it doesn't work on your specific equation). I meant that if your charge equation is something like Q=x*({C0+Csat})/2+({Csat-C0})/4*{Vtra}*ln(cosh((x-{Vth})*2/{Vtra})) , you should change it to Q=abs(x)*({C0+Csat})/2+({Csat-C0})/4*{Vtra}*ln(cosh((abs(x)-{Vth})*2/{Vtra})) (notice the abs(x) in two spots). I tried it myself before I suggested it and it worked. Only thing is it causes weirdness around zero so if you sweep both positive and negative it gets an annoying glitch. Regardless, I like your solution better.
|
|
Apr 16, 2023 at 20:31 | comment | added | A. Stickel | @Kulov I tried the abs(x) and this didn't help, which it turns out is because of how LTSpice integrates the charge. I ended up starting with a C(v) function that is symmetrical for positive and negative V values "C = (Cmax - Cmin) / (1 + Slope * V^2) + Cmin". I fit the curve to measured data with a Python fitting script, then plugged the constants Cmin, Cmax, and Slope into the integral of that equation "Q = ( ( ( Cmax - Cmin ) * arctan( sqrt( Slope ) * V ) ) / ( sqrt( Slope ) ) + Cmin * V". After some verification this works consistently! Thanks for getting me started in the right direction! | |
Apr 7, 2023 at 5:57 | comment | added | Ste Kulov |
@A.Stickel I believe it has something to do with \$tanh()\$ being an odd function, so it's only valid for positive arguments when trying to fit the DC bias model. You can probably get around this by replacing all instances of x with abs(x) in the integrated charge expression. This should imply that tanh(_) turns into tanh(abs(_)) when it's differentiated, turning it into an even function (i.e. symmetric along the y-axis). You might also have to plot the abs() of the current in the waveform viewer too if you're going to sweep both positive and negative values in one run.
|
|
Apr 6, 2023 at 16:07 | comment | added | A. Stickel | Thanks, this totally worked! However, I now notice that it seems to only give good results for positive voltages on the cap. I tried abs(x) and no difference at all. Did you find anything special to deal with negative voltages? | |
Apr 6, 2023 at 1:59 | vote | accept | A. Stickel | ||
Apr 5, 2023 at 16:36 | comment | added | Ste Kulov | @Kubahasn'tforgottenMonica Right. That all makes sense. I was talking about the fact of why it makes you integrate, only for it to undo the integration with differentiation to recover C. It would only need to do that if it needs Q for something...and indeed it does. After looking at the ngspice source code again, I was reminded that the numerical integration function uses Q to simplify the calculation. So it needs Q to be compatible with that function. With constant C, it gets Q trivially as shown above. | |
Apr 5, 2023 at 5:59 | comment | added | Kuba hasn't forgotten Monica | It is fairly easy to do symbolic differentiation, whereas symbolic integration to the extent necessary here would be an order of magnitude larger task at least and probably not worth it in the context of a circuit simulator. Of course, there are shortcuts - most capacitance vs voltage curves can be rather well approximated with polynomials or splines, and those have integrals that are easy to derive symbolically. | |
Apr 5, 2023 at 5:48 | history | answered | Ste Kulov | CC BY-SA 4.0 |