Author Topic: Mixed mode simulation in Kicad with c controller  (Read 829 times)

0 Members and 1 Guest are viewing this topic.

Offline SlhTopic starter

  • Regular Contributor
  • *
  • Posts: 156
  • Country: gb
Mixed mode simulation in Kicad with c controller
« on: December 08, 2024, 01:09:34 pm »
I posted a mixed simulation earlier in the year but it was a bit of a mess and needed a lot of work to understand https://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.

 
The following users thanked this post: JohnG, JPortici

Offline SlhTopic starter

  • Regular Contributor
  • *
  • Posts: 156
  • Country: gb
Re: Mixed mode simulation in Kicad with c controller
« Reply #1 on: December 08, 2024, 03:41:00 pm »
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.
2456621-0
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.
2456625-1

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):

2456629-2
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.

2456637-3

No load to 25R step response (14V). Step at 50ms (see blue trace for switch trigger)

2456633-4
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.

2456641-5
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 saturation

The 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.
 
The following users thanked this post: JohnG, JPortici

Offline JohnG

  • Frequent Contributor
  • **
  • Posts: 586
  • Country: us
Re: Mixed mode simulation in Kicad with c controller
« Reply #2 on: December 10, 2024, 03:14:39 pm »
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
 
"Reality is that which, when you quit believing in it, doesn't go away." Philip K. Dick (RIP).
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf