Hey, hey. I’ve been learning to write my own SPICE diode models. In doing so, I learned a bunch about reverse recovery and used that knowledge to answer a question for someone on Stack Exchange:
https://electronics.stackexchange.com/questions/494817/how-does-ltspice-model-reverse-recovery-time
The item of note here (briefly discussed in the question's comments) is the Vp
parameter which is unique to LTspice's implementation. This parameter allows the "2nd half" of the reverse recovery to be properly modeled. The LTspice help section for diodes references the following IEEE paper for the method used to implement this feature:
https://ieeexplore.ieee.org/document/491001
I purchased the paper for myself. According to the license agreement, I cannot just snip or post any of its content publicly....but the jist of it is the following. The diode diffusion charge is normally:
To improve the model, you simply add the Vp
parameter along with the rate of change of Qd
against time to get the modified equation:
Vp
is called the "viscosity of the minority carrier charge" and is compared within the paper to damping factors in mechanical systems. If someone needs to look at the paper, let me know and I can send them the 33.00 USD (via PayPal or something) required to purchase it.
I'm hoping this Vp
parameter can be added to ngspice's internal diode model. I'm writing a diode model library and prefer to make them work with both LTspice and ngspice. I attached a test circuit which can be used to see the current through a simple diode model in reverse recovery. The Vp
is current ignored by ngspice, but if you run the same circuit in LTspice you can see how it affects the response.
On 2020-07-09 17:41, Ste Kulov wrote:
You may want to check out the paper by Denis Zaikin, den913@gmail.com .
He describes a way to convert any given .MODEL dxxxx to a subcircuit
that handles reverse rcovery of that diode with near arbitrary
precision.
The theory is backed up with experimental verification.
-marcel
D. I. Zaikin, "Basic diode SPICE model extension and a software
characterization tool for reverse recovery simulation," 2015 IEEE
International Conference on Industrial Technology (ICIT), Seville,
2015, pp. 941-945, doi: 10.1109/ICIT.2015.7125218.
Related
Feature Requests: #76
Hey, marcel. I know about this already as I discuss it in my Stack Exchange answer. If you don't have time to read the whole answer, at least skip to the end where I talk about it.
I was hoping ngspice could support reverse recovery at the .model level instead of using subcircuits.
For another simulation study I have been using a power diode FT2000KB from Diotec AG. They sent me their Spice model parameters, and indeed these included the vp parameter. Attached I have included input and image files for making some comparison on reverse recovery.
It seems reasonable to me to add the vp parameter to the ngspice diode model. Unfortunately it seems to be not as simple as looking at the equations and adding a source code line. If somebody has experience and some spare time, I would be happy with a patch.
I have also looked at the subcircuit approach. While it is (I assume) scientifically sound, I cannot imagine that the average user will start fiddling around with the diode model. The praised software ciited in the paper seems not to be available for download. I guess the average user in need of better reverse recovery modeling would just use the other simulator, which is bad.
Last edit: Holger Vogt 2020-07-11
On 2020-07-11 15:32, Holger Vogt wrote:
The software can be had with an e-mail to the author (address shown in
my
posting). It is unfortunately an executable for Windows and has a
dependency on a specific simulator, but that could be fixed. However,
replacing a .model with a subcircuit makes measuring current through
pins ( I(D1) ) impossible.
-marcel
Seems like the starting point would be with the following lines in
dioload.c
:You're right that it's going to be more complicated than just changing one of these lines. You have to deal with passing around the
Vp
parameter and I don't know if time derivatives exist in this function, have to be passed around from somewhere else, or computed from scratch.Yes, introduce the parameter Vp is quite easy. The problem is, that you have a implicite DGL. Perhaps it is sufficient to get the dQ/dt from timestep before over the state vector.
My image links to the LaTeX equations went dead. I can't edit the original post anymore, so I'm attaching them here instead. Should be clear in the context of the original post to which equation is which.
After setting up the dev environment from the other week, I decided to take a stab at implementing this. Here is a comparison of my ngspice implementation against LTspice's implementation. I'm using Backwards Euler to solve the differential equation. Attached is my equation for the diffusion charge. The diffusion capacitance equation is the same except
Q -> C
andId -> Gd
. I will try one of the 2nd order methods next to see if those artifacts disappear.Sounds promising. Let us hear about your results.
Perhaps we should open an development branch.
Dietmar
Is it bad that I don't know what that is?
We are working with git code revision system. So we can open an dedicated branch for your diode code enhancement. Later, if it will work we can integrate it into the master branch, means release. Requirement is that you are familiar with git.
Oh, okay. I understand. I've used git before, but not in a long time and not in too much detail. I'm not an official software engineer, but I think I'll be able to figure it out. Just tell me what I need to do to set that up. Thank you.
Also, is it better to discuss technical details regarding this on the ngspice-devel list? For example, I have some data which shows different reverse recovery behavior between LTspice XVII, LTspice IV, and my implementation and would like to ask for feedback and/or opinions on how to proceed. Where is the best place to do this?
Ste Kulov,
in case you are still reading this thread: Can you contribute to our project by unclose your development to this diode enhancement. E.g. attache the dioload.c file to this post or send to my sourceforge mail address. I will then create an new git branch.
Thanks
Dietmar
Hey, Dietmar. My tests were done over the ngspice-33 release. Therefore, I spent some extra time and modified the ngspice-35 code with the same changes and attached a zip with the 6 diode files I changed. If you want the old ngspice-33 code, then let me know. Also attached is a test build to validate my changes still build properly under a ngspice-35 base. Lastly, I attached my mathematical derivations for a few of the numerical integration methods I tried.
Thank you Ste for your contribution.
I just created an new git branch dio_rev_rec based on pre-master mostly with your code as initiation.
I made first checks with BE and TRAP formulas. Works fine even though oscillation appears.
Let us check further.
I found one strange problem: The current which we save in DIOcurrent and plot later with @d1[id] is not the same flowing through the voltage source - see attachment.
I belief we have to separate the diffusion capacitor and integrate by its own.
Marcel, do you can take a look?
On 2021-11-10 10:53, Dietmar Warning wrote:
The current @d1[id] is reconstructed from the charge in the diffusion
capacitor and
is related to the id from the previous timestep. It is not coming from
the output
vector (all outputs solved together at the current time by
Newton-Raphson), like the
current through a voltage source. This can have consequences for
fast-changing
signals and / or local or global feedback loops.
-marcel
Hey, Dietmar. You pointed out to me via email that the Backward Euler derivation has a typo in it. I noticed it too and also noticed the same problem in the 2nd Order Gear derivation. I uploaded a fixed version of the mathematics.
You also mentioned something about maybe using
1/CKTag[0]
instead ofCKTdelta
. This doesn't make sense becauseCKTag[0]
is simply just the pre-computed coefficient for integrating the capacitor charge differential equation (a completely different, and simpler equation). If you consider a standard (linear) capacitor and 1st order integration, thenCKTag[0]
coincidentally is computed as1/CKTdelta
. Therefore, if you're using1/CKTag[0]
, you're just doing double reciprocation like so:1/(1/CKTdelta)
. I attached some mathematics for this as well. You should be able to compare my derived results with what is innicomcof.c
andniinteg.c
forCKTorder=1
.One last point. I noticed you added code for handling the special case if
Vp
parameter is not defined. This should not be necessary since the parameter defaults to zero and all three of the equations I derived reduce down to the original equation whenVp=0
.Hi Ste,
curious - using the corrected cdb and gdb (!) in backward euler simulation goes total worse.
Let us stay with your Trap formulae.
There is no double reciprocation and if look in the load routine to values of 1/CKTag[0] you got the half of CKTdelta.
But nevertheless the problem is that the iterated current follows not the correct internal current which is derived from previous timestep. See picture. This is independent from our used charge integration formulae but dependent from tran step. Also the separate integration over NIintegrate() and convergence test of the diffcharge contribution brings no benefit.
You are right with Vp=0 but I want prevent any (!) additional operation because the diode instance is used extensive in mixed-signal IC design.
In case we get it working I would prefer to introduce a level=2 diode model with self-heating effect, soft recovery model extension and maybe other power diode effects.
Oh, sorry for the confusion. The code for Backward Euler should not have changed. My corrections on the derivation was just to match what was originally written in the code. It did not before.
You get half of CKTdelta because Trap Integration (default) is being used for capacitor integration and the integration coefficients are different.
Good day. I just realized (may be too late) some my article in the discussion. All SW and its sources related to it can be found on ResearchGate: https://www.researchgate.net/publication/283824585_Basic_diode_SPICE_model_extension_and_a_software_characterization_tool_for_reverse_recovery_simulation
Also some preprint (note to myself) using another approach to simulate reverse recovery:
https://doi.org/10.36227/techrxiv.14915139.v2 with free sw tool also.
Thanks Denis. Late - but not too late. Good articles!
In the mean time I setup few Verilog-A models for ngspice usage: https://github.com/dwarning/VA-Models
Beside other also the Lauritzen diode is available: https://github.com/dwarning/VA-Models/blob/main/code/playground/diode_basic.va. There is a ngspice script diode_basic.sp to show the reverse recovery model.
Binary releases are available for linux and win 10 on this side.
Still, for compatibility reasons, and for ease of use, I would like to see the vp parameter added to our standard diode model.
Denys, might it be possible that you care for that (with some help from our side of course)?
Good day, Holger. I would like to help. But could you describe shortly, what is problem to implement Vp in a .model statement? I am not so deeply familiar with the spice-engine. I have the original article that LTspice is based about the Vp parameter, so I can try to dig into it...
Basically, I could not get the engine to integrate the new diffusion differential equation without producing some horrible artifacts. I was hoping to be able to look into this again, but I'll probably be swamped for a couple more years on other projects.