Author Topic: Kicad simulator model incorporating c functions, xspice and verilog  (Read 10112 times)

0 Members and 1 Guest are viewing this topic.

Offline SlhTopic starter

  • Regular Contributor
  • *
  • Posts: 136
  • Country: gb
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
 
The following users thanked this post: JohnG

Online djsb

  • Frequent Contributor
  • **
  • Posts: 956
  • Country: gb
Re: Kicad simulator model incorporating c functions, xspice and verilog
« Reply #1 on: March 31, 2024, 07:38:35 pm »
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.
David
Hertfordshire, UK
University Electronics Technician, London, PIC16/18, CCS PCM C, Arduino UNO, NANO,ESP32, KiCad V8+, Altium Designer 21.4.1, Alibre Design Expert 28 & FreeCAD beginner. LPKF S103,S62 PCB router Operator, Electronics instructor. Credited KiCad French to English translator
 

Offline SlhTopic starter

  • Regular Contributor
  • *
  • Posts: 136
  • Country: gb
Re: Kicad simulator model incorporating c functions, xspice and verilog
« Reply #2 on: April 01, 2024, 10:23:33 am »
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.
 

Offline JohnG

  • Frequent Contributor
  • **
  • Posts: 583
  • Country: us
Re: Kicad simulator model incorporating c functions, xspice and verilog
« Reply #3 on: April 01, 2024, 05:40:38 pm »
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
"Reality is that which, when you quit believing in it, doesn't go away." Philip K. Dick (RIP).
 

Offline SlhTopic starter

  • Regular Contributor
  • *
  • Posts: 136
  • Country: gb
Re: Kicad simulator model incorporating c functions, xspice and verilog
« Reply #4 on: April 01, 2024, 07:33:40 pm »
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.
 

Online wilhe_jo

  • Regular Contributor
  • *
  • Posts: 199
  • Country: at
Re: Kicad simulator model incorporating c functions, xspice and verilog
« Reply #5 on: April 16, 2024, 02:06:01 pm »
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
 

Offline hvogt

  • Contributor
  • Posts: 10
  • Country: de
Re: Kicad simulator model incorporating c functions, xspice and verilog
« Reply #6 on: April 20, 2024, 02:53:40 pm »
I have made some introductory videos David might be interested in: https://www.youtube.com/@holger8105

Videos on C code, code models, Verilog are still due ...
« Last Edit: April 20, 2024, 02:57:05 pm by hvogt »
 
The following users thanked this post: djsb, 2nOrderEDO

Online 2nOrderEDO

  • Contributor
  • Posts: 49
  • Country: ch
Re: Kicad simulator model incorporating c functions, xspice and verilog
« Reply #7 on: April 26, 2024, 11:10:39 am »
Looking forward to those videos, and thanks for what you shared so far!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf