"Timestep too small" is killing me

Hi everyone. I have been trying to avoid asking for help and searched the forum for anything that would help, but I have accepted the fact that I need your expert guidance. I am simulating a simple boost converter. It took quite a while (over a week), but I eventually got a working simulation with the ngspice built-in SPICE models (C,L,NMOS,R). From the beginning I was struggling with the simulation terminating with the timestep too small error. I eventually found a post that mentioned that high frequency transients can cause such an error, so I added filters, slowed slew rates, etc to soften everything as much as reasonable. I would find a configuration that would run for a while without errors, but always I run back into the same issue. Sometimes I spend a day or so trying to get the sim happy again. I have tried adjusting the max step time, up and down, sometimes it helps, often it does not.

I feel like I might be missing something fundamental that is giving me so much problem with this. I expected to find this issue pervasive throughout the forum, but the relative scarcity seems to indicate that the simulations should not be this fragile, and I am doing something wrong. I wonā€™t bother posting the circuit yet, but can if that would be helpful. I am really wanting to be able to use the simulator right in KiCAD but I am loosing valuable time at this point. Any help appreciated.

Thank you,
Daniel

Welcome @theoatmit

I canā€™t help with your problem, but I know the first person able to help will want to know your OS and Kicad version.

Go to Kicad > Help > About Kicad, then click ā€œCopy Version Infoā€ (top RH corner) and Paste into a new post. :slightly_smiling_face:

Application: KiCad Schematic Editor x86_64 on x86_64

Version: 7.0.6, release build

Libraries:
wxWidgets 3.2.2
FreeType 2.12.1
HarfBuzz 5.2.0
FontConfig 2.14.1
libcurl/7.86.0-DEV OpenSSL/3.0.9 zlib/1.2.13 nghttp2/1.55.0

Platform: Linux 5.4.0-155-generic x86_64, 64 bit, Little endian, wxGTK, cinnamon, x11

Build Info:
Date: Jul 31 2023 17:41:51
wxWidgets: 3.2.2 (wchar_t,wx containers) GTK+ 3.24
Boost: 1.82.0
OCC: 7.7.1
Curl: 7.86.0-DEV
ngspice: 40
Compiler: GCC 12.2.0 with C++ ABI 1017

Build settings:
KICAD_SPICE=ON

1 Like

In my limited experience with ngspice, the time step error is only rarely about the time step. It often means that thereā€™s something else subtly wrong. The fact that it sometimes works is a odd one thoughā€¦

With any ngspice issue, it would be very helpful (for others to debug) if you can upload the whole project including spice libraries, preferably in the same folder as everything else. zip file compression of the whole folder is preferred.

ā€œTimestep too smallā€ is just one the many useless error messages in ngspice.
It basically tells you your simulation wonā€™t converge, which again means something else is wrong.
It can be the model itself, pin sequencing, an instable circuit, you name it.

Welcome to the fun of simulation.

I have never used NGSpice but I design power and I have been using LTSpice in my job a lot recently. I am NOT AN EXPERT with LTSpice or any simulation program. My thing is much more design and much less simulation. Butā€¦that being saidā€¦

I have had LTSpice runs advancing at femtoseconds/second. When this happens the simulation is usually in trouble. Microseconds/second are more normal.

Is there any selection between things like gear integration or trapezoidal or modified trapezoidal integration? If so, try those various options.

I have not used ngspice, so canā€™t offer a specific answer. I have used ltspice and various others going back to the days of the fortran distribution on 9-track tape :slight_smile:

I will second the Gear method for integration, and other adjustable sim parameters ā€“ that helped me years ago when doing some long and problematic transient sims that often refused to converge.

You can also try some tricks like temporarily replacing sections of the circuit with macromodels that have minimal computational needs ā€“ when you isolate an area of the circuit you can investigate more.

Another thing I found handy at times is to lower circuit impedances ā€“ I mean a brute-force adding a 1G-resistor-from-each-node-to-ground sort of thing. Add em on all the nodes and see if it converges, then remove some resistors, re-testā€¦ If you have very fast-slewing transitions you might add a bit of capacitance to some nodes. I donā€™t know quite how the number-crunching goes in spice, maybe something to do with very-large or very-tiny numbers, but there are some practical ways you can massage your circuit to help the simulation.

https://www.youtube.com/watch?v=hxJPJ6JY0Pk

I appreciate the advice, thank you. I donā€™t know how to play with simulation integration options in ngspice. Anyone know? I did find that putting in lots of transient softening stuff helped. I have been rebuilding the circuit from scratch again to try to find where things start going sideways and will upload the project when it gets jammed up again. I am currently thinking that the built in VDMOS n-channel mosfet model and its associated default parameters may be the issue. I am using lots of body diode action in my circuit, and it seems like this model may be quite temperamental in that department because when I replace the mosfet (with gate shorted to source) with a diode, it seems to be happy.

So my current course of action is to find an actual model for an actual nmos that I will use in the circuit. Any suggestions appreciated. My goal is to purchase the cheapest (or close to cheapest) nchannel mosfet on lcsc.com and use that. This particular circuit doesnā€™t need to be super efficient because even though it is on a battery operated device, it is something that will be used for a few seconds once every few days, but there will be hundreds of them. So cost is much more important than efficiency. I have read all the horror stories about finding models. I donā€™t know anything about mosfet models, and havenā€™t the slightest clue what most of those parameters mean or do in the various built in models, and donā€™t really care to learn since this is a small part of a much larger project. So if anyone really knows this stuff, I would really appreciate your guidance. Happy to pay if that is helpful.

Suggestions on mosfets and models much appreciated.
Thank you,
Daniel

Some simulator options for simulating power supplies:
.options method=gear chgtol=1e-11 reltol=0.01 rshunt=1G rseries=0.05 cshunt=1p trtol=1
For details see ngspice manual, chapter 15.1.

If you want more info please add a better specification of what your circuit is supposed to do. What we know right now is: Boost converter, cheapest NMOSFET. This is not very precise.

In the old days, we would purchase a dozen or so candidate parts, solder up a little proto circuit for testing them, sit down with a decent oscilloscope and select the best part and a few substitutes.

Yeah, I am headed that direction. I really wanted to give sim a solid chance, but without readily available models, its kindof looking like a no go.

There is lots of PowerMOS models around, either directly from device makers, from distributors, or the open source community.

But indeed also for me it was not possible to find a spice model for the ā€œthe cheapest (or close to cheapest) nchannel mosfetā€.

Simulation has its place for me. Simple analog ac stuff like tweaking response. Seeing the response envelope as components vary over their tolerance ranges. Adding noise sources here and there to find which opamp needs to be pricey and which ones do not. Adding a source in the feedback loop of a power supply to find phase/gain response. Transient startups. Using crude timesteps to get far enough out time to grab cap voltages and inductor currents, and then plugging those in as initial conditions for a fine-timestep run. But for me Iā€™ve never felt the need to completely model everything in a circuit when crude models let me run a simulation much faster and I can spent the time detailing just a small area of interest. Though I realize that there are many simulation use-cases I have never explored. Thereā€™s no replacement for good bench testing though.

Hi all, so after a break and then spending more time on this I have made some progress. I got a windows laptop and tried the windows version wondering if the linux version was perhaps a bit more buggy. That made no difference. Then I took a break for a few weeks. When I came back I built up the circuit from scratch again, and found that I was having trouble because of the capacitors I was using which were ā€œidealā€ instead of ā€œbehavioral.ā€ Once changed to behavioral, the circuit was much more stable. I also found mosfet models from a manufacturer and they seem to be stable. The problem I am running into now, is that I am getting (and have gotten in the past) ā€œError:Vector I(MQ2) not found!ā€ e.g. when I try to probe certain parts of the circuit after simulation. Now I havenā€™t searched the forum for that yet, and will do that next to see if there is something that I am doing to cause it. But I wanted to just give an update of progress on this rather than just ghost the topic. Thanks everyone for the help so far.

I am assuming it is a known bug that certain actions to modify a circuit while the simulation window is open causes an application crash? That has been a minor nuisance. When does the next upgrade come out?

Never happened to me (Lubuntu 20.04, 7.0.7).

it is telling me the current vector isnā€™t found where the current tool is in the image. No idea why it would trim that.

I was having this identical problem, and also in a boost circuit. NGspice was giving the ā€œTimestep too smallā€ error, or other problems relating to the diode. I tried adding a few 1M resistors to ground at the problematic junction but that didnā€™t work.

The solution was to remove the diode, and replace it with a NPN transistor. Connect the Common ā€œCā€ pin to the node that links with the N-channel MOSFET drain and the inductor -ve pin. The Emitter ā€œEā€ pin is connected to the R(load).

The Base ā€œBā€ pin is then connected directly to a DC power supply (I had a 10V supply and used that). This ensures that the transistor is always ā€œOnā€ and conventional current will flow from C to E, but not from E to C. Effectively, this replaces the diode and the circuit will work. I think the NPN transistor in KiCad is ā€˜idealā€™ so there wonā€™t be any current flowing through BE which would make a mess of your simulation.

The error appears to be in the diodeā€™s SPICE file or default settings. Iā€™m not sure how to fix it though. Problem for another day.

Hope this works for you.

1 Like

As we are working here with voltages hihgher than in typical integrated circuits, it is advisable to relax the precision constraints a bit, e.g. by putting

.options chgtol=1e-11 abstol=10u

into a text box onto the Eeschema canvas.

1 Like

Thank you, very helpful. It occurred to me exactly as you are saying that some part models may not be good enough to handle anything beyond more typical use. Boost circuits are highly dynamic, and hence if the models arenā€™t really good, there seems to be trouble keeping the sim stable in the face of high frequency high voltage ringing etc.

Hi, can you say more about that? I am still new to spice, so I am not sure what you are suggesting. Thank you!