Mixed mode simulation in Kicad with c controller - Page 1
Forum section: electronics / general

author: Slh
author_rank: Regular Contributor
timestamp: December 08, 2024, 01:09:34 pm
content: I posted a mixed simulation earlier in the year but it was a bit of a mess and needed a lot of work to understandhttps://www.eevblog.com/forum/kicad/kicad-simulator-model-incorporating-c-functions-xspice-and-verilog/msg5424569.I've published a better model that is easier to use and hopefully makes it easier to modify. It can be found here:https://forum.kicad.info/t/easier-mixed-mode-simulation-and-real-world-comparison/56530. It's a digitally controlled buck converter that can operate over the range 0-60V input and out and up to around 4A.I also made a small buck converter using an MSP430 and ran the same controller code on it. There's an example of the no load start up in simulation and on real hardware in the link. I did a bunch more comparisons and it showed a really good correlation. If I get the time I'll upload a few here.

author: Slh
author_rank: Regular Contributor
timestamp: December 08, 2024, 03:41:00 pm
content: This (below) is basically a copy and paste of a short article I did on it elsewhere. I should mention that the current measurements are using a homemade Rogowski coil so are at best indicative measurements.The buck converter that I built has a 16 bit, 16MHz MSP430G2553 for control and USB-C for logic power. on/off control is via the UART.The simulation has a basic model of the microcontroller with 10 bit ADCs for input voltage, output voltage and inductor current. and a simple triangle PWM generator. The voltage and current measurement circuit gains are all set as per the hardware. The basic algorithm was a modified version of the example linked above with an inner current loop and outer voltage loop.Switching frequency is 25kHz. Actual calculation time with measurements is currently around 35us which leaves 5us spare. The processor isn't too powerful so it's all fixed point with careful scheduling of ADC measurements and use of what passes for DMA on it. I used it as a challenge but would not recommend it for serious power converter designs.I'm using a 25R resistive load for step tests, input voltage 27V due to my available power supplies and output 14V.No load start up simulation (there's a 40ms start up ramp):No load start up measurements: Current measurement is indicative only. It's a home made rogowski coil but it shows the same frequency oscillations as the voltage.No load to 25R step response (14V). Step at 50ms (see blue trace for switch trigger)Measured: load step from no load to 25R. Blue channel 4, Vout,this looks even better than simulation as well. There's a bit of oscillation when load step occurs but it decays rapidly.The simulation has oscillations on start up at around 330Hz whereas the measured one is around 400Hz. This could be because I didn't model delays in the measurements or gate drivers. Alternatively, it could be down to the non ideal nature of the inductors and capacitors used. The inductor used is an iron powder core which has a soft saturationThe controller was tuned in simulation and transferred to real hardware where it reacts in a similar way. I wasn't trying to get perfect control but just good enough to show that the Kicad can be used for useful power electronics simulations. Since the modelling tool is a varient of SPICE (ngspice,https://ngspice.sourceforge.io/), you can get the model running with basic switches (as I did) and then drop in your gate driver and MOSFET models to get loss results. You can also model the layout parasitics to get switching spikes. ngspice is also used as the simulation engine in Eagle, Fusion Electronics and Altium but I've no idea how you would set it up to do this sort of simulation (or which version of ngspice is used -this requires one from this year).I did test it with a 48V supply that I have lying around after I was confident it wouldn't blow up and it seemed to be performing just as well. Capacitors and MOSFETs were all at least 60V rated and the voltage dividers on the input and output max out at 60V anyway.

author: JohnG
author_rank: Frequent Contributor
timestamp: December 10, 2024, 03:14:39 pm
content: Thank you. This is great work.There has been a lot of progress on the KiCad ngspice interface in the last couple years. Maybe it's time to give it another try.John