@uros I believe that you’re the person behind Isotel.eu?
Thank you for your example c and verilog model. I hope you’re happy how I’ve used it to produce the example model in the first post above. Feel free to take it and use it to update your original example if you want a kicad example to go with your eagle one.
Welcome and thank you for your effort for making a kicad example. I just recently started with kicad/ngspice integration and I am impressed by the progress.
As first I would create a hyper link to this use case.
I am looking at current directory, which is not the project folder but kicad start-up folder. So you had to use an absolute path, which does not make a real sense.
I am not sure if anybody needs ngspice to start like this, whenever I’ve used I’ve always started it from the project folder, so it would make sense that kicad would also change default directory to the project directory. Also python console starts in the same way, but probably we can get the KIPRJMOD variable there and change it, which is not possible in ngspice.
Not sure what is others opinion but I would change default directory to project root not “system default”.
Yes that’s correct. It needs an absolute path at the moment. Interestingly, you only need to change the working directory once per session. After the first run it remembers until you restart kicad.
I agree that the default working path should be the project directory. I haven’t got a GitHub account so haven’t started filing bugs.
I think that there’s also.a memory leak. After a few long runs kicad locks up and then closes.
Paths and project specific directives should be in .spiceinit file in the project folder, so changing the folder would benefit also in reading this file. There additional source paths may be added to find modules from mixedsim etc.
On Linux an easy work-around is to start the kicad <project> from a command line directly from the project directory; but that’s not the way users would use kicad on win*.
I’ve just filed a bug for a crash I keep getting with this simulation. If you run a 200ms transient simulation with 5us timesteps then it crashes before 200ms on my computer.
I suspect it’s running out of memory. It’s taking up 11.2 GB of virtual memory for a 100ms simulation and I’ve got about 12GB available. If it is then I assume that kicad/ngspice is keeping the entire simulation result in memory and it would probably be better to write to a file and just read in what’s required like ltspice.
ngspice will not automatically delete any results generated. You have to understand what memory usage is generated, what is to keep, what to store and what is to delete. You have full control over the simulator, and you have to make use of this control!
I can understand that approach and I will dig into the details to disable saving as much as possible. I was expecting that this is probably a preventable issue.
However, the fact that with the default settings, kicad will just crash silently with this model seemed worth highlighting.
It looks like I might also be running into another bug (issue 16404) where kicad doesn’t get rid of the simulation vectors when a new simulation is run.
I added pre_destroy all to the control section that partially sorts that bit out.
I’ve also turned off saving all data in the kicad analysis tab and added “save v(/hv_lu)” and “save I(v1)”.
When the simulation starts the memory is cleared however it still uses about 11GB (same as before) for a 100ms simulation. I was expecting the amount used to reduce significantly so have I misunderstood the commands or missed an important one?
This circuit contains quite a lot of digital (XSPICE) instances owing to the yosys synthesis tool. This causes the simulation to generate large amounts of digital event data, by default, when it is run. If you do not wish to examine this mass of results via eprint, eprvcd, or plot, then those events do not need to be saved. In the .control…endc section of the schematic, you can include “esave none”, and then no event data results are saved. If you need to see events on only a few digital nodes, then select them individually using “esave <node> …” commands. I ran to completion your netlist for “.tran 5u 200m 0” with “esave none” and the max. program size reported by “rusage” was approx. 224MB. The analog voltage and current results should be the same with or without saving digital events. I hope this helps.
Now that I’ve given it a go, I can confirm that “esave none” solves the memory issue. I see that I was looking in the wrong section of the manual. I was looking in the XSPICE section, not the interactive interpreter section. Looks like I’ve got a lot of manual reading to catch up on.
I’m now happy to use kicad and ngspice for power electronics simulations (and probably more). It’s reasonably fast and can replace most uses of PLECS and LTSPICE for me.
Looking at your original post, I think it’s probably the one that inspired me to give it a go so a big thanks for that.
It was really well timed for me as well since I’m just about to lose access to PLECS (explicitly for power electronics sims) and can’t justify getting my own license.
At some point I may look at importing PLECS switch loss models as well. They appear to be just look up tables in XML so shouldn’t be too hard. I expect that they could be used with either the switch events from the xspice (post processing - should be easy) or maybe incorporated more neatly into the simulation itself.
I actually have past experience writing a PLECS loss model generator. I have the Python code that will generate a valid PLECS XML file with the conduction + switching losses.
If you need help with that, maybe I can share the code.
That’s definitely of interest. I think that I would probably start by working out how to use look up tables with the switch events first before importing the models fully.
I don’t know how much time I’m going to have to do this in the near future (life is getting in the way) but if you can share the code it would be of interest to see how they can be imported.