Kicad simulator model incorporating c functions, xspice and verilog - Page 1
Forum section: electronics / general

author: Slh
author_rank: Regular Contributor
timestamp: March 30, 2024, 05:13:44 pm
content: 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

author: djsb
author_rank: Super Contributor
timestamp: March 31, 2024, 07:38:35 pm
content: 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.

author: Slh
author_rank: Regular Contributor
timestamp: April 01, 2024, 10:23:33 am
content: 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.

author: JohnG
author_rank: Frequent Contributor
timestamp: April 01, 2024, 05:40:38 pm
content: 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

author: Slh
author_rank: Regular Contributor
timestamp: April 01, 2024, 07:33:40 pm
content: 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.

author: wilhe_jo
author_rank: Regular Contributor
timestamp: April 16, 2024, 02:06:01 pm
content: 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

author: hvogt
author_rank: Contributor
timestamp: April 20, 2024, 02:53:40 pm
content: I have made some introductory videos David might be interested in:https://www.youtube.com/@holger8105Videos on C code, code models, Verilog are still due ...

author: 2nOrderEDO
author_rank: Regular Contributor
timestamp: April 26, 2024, 11:10:39 am
content: Looking forward to those videos, and thanks for what you shared so far!