I managed to get a c code model running in the kicad 8.0.1 simulator. It enables you to include algorithms that would run on your microcontroller in your simulation. Potentially you can then debug is with gdb (or printf if you're a bit more like me
)
The example model is just a simple current controller with a half bridge and inductor.
See link for full details and the model:
https://forum.kicad.info/t/mixed-mode-simulation-including-c-code-and-verilog/49752
This is interesting, but could you make something simple like blinking an LED or putting current through a resistor so we can understand how it all works. I've still not got my head around the standard use of ngspice simulation yet.
I might get around to doing a simpler one however realistically this currently requires pretty detailed SPICE simulation knowledge (including writing your own models) to set up your own models so I don't know how useful such a basic model would be. Between my example and the original that I started from (linked in the kicad forum post) there should be enough information for an experienced user to get whatever they want running.
Once the microcontroller model is made (including the c-code main function) it should be easy to use but given how many functions microcontrollers have nowadays unless you use the same peripherals then you'll have to modify the model. Longer term, I expect that the c-code main function could be generated from a script.
My main reason for getting it working was for power electronics simulation (similar to PLECS or PSIM) hence why I made a basic buck converter. It runs fast enough at the moment for me to be happy using it. I look forward to seeing how it fast it is with CLLC and DAB converters.
This looks like some really nice work, thanks.
I find it interesting that ngspice has many of the same features of QSPICE, but in a completely open-source form. I don't know how the two compare performance-wise.
John
Thank you. I'd love to see how it compares to Qspice speed wise but until Qspice runs on Linux I can't run it.
The c code function has only just been merged into ngspice so I'm hoping that now there's an example it will inspire better software folk than me to integrate it better into kicad (and maybe ngspice) but for now it's good enough for me.
I tried to get my PhD on circuit simulation but ("sadly") ended up getting self employed .
However, doing "basic" circuits simulation isn't that complicated. I ended up doing a simulation core using eigen3 and boost libs. Those have more or less everything needed.
The real problem is the lack of common model standards.
For example, just the basic transistor models are standardized and you find convergence tricks for specific simulator implementations all over the place.
If you want, I can give you input on some dead-ends I found in my endeavours...
73
Looking forward to those videos, and thanks for what you shared so far!