Author Topic: Possible to Simulate MCU/FPGA PID Control Loop in LTspice?  (Read 2875 times)

0 Members and 1 Guest are viewing this topic.

Offline farrellTopic starter

  • Contributor
  • Posts: 19
Possible to Simulate MCU/FPGA PID Control Loop in LTspice?
« on: April 23, 2022, 12:52:23 am »
I'd like to simulate an SMPS where a MCU or FPGA outputs PWM to control some SMPS circuitry. Is it possible to simulate this with LTspice? In other words, is it possible to create a component that does something like this pseudocode:

once_per_millisecond {
    read_some_net_voltages;
    do_some_math;
    set_pwm_duty_cycles;
}

I know how to create components composed of passives/diodes/transistors/etc., but is it possible to instead define a component algorithmically?

Thanks,
-Farrell
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26896
  • Country: nl
    • NCT Developments
Re: Possible to Simulate MCU/FPGA PID Control Loop in LTspice?
« Reply #1 on: April 23, 2022, 02:12:13 am »
Laplace transform comes to mind.

However for discrete (sampled systems) simulation Matlab or GNU Octave are probably better tools. https://www.sharetechnote.com/html/Octave_Matlab_SignalProcessing.html
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14445
  • Country: fr
Re: Possible to Simulate MCU/FPGA PID Control Loop in LTspice?
« Reply #2 on: April 23, 2022, 03:19:04 am »
You can start here: https://ltwiki.org/index.php?title=B_sources_(common_examples)
Read till the end. Should give you ideas to try.
 

Offline farrellTopic starter

  • Contributor
  • Posts: 19
Re: Possible to Simulate MCU/FPGA PID Control Loop in LTspice?
« Reply #3 on: April 23, 2022, 05:11:37 am »
Considering how most designs these days are a mix of analog and digital circuits (nearly everything has an MCU or FPGA!) I'm surprised that there isn't a clean way to simulate how those circuits interact. There are simulators for verifying HDL, and simulators for verifying analog circuits, but no simulators that let you test both together? I'm really surprised that a SPICE simulator doesn't support some sort of discrete-time algorithmically-defined component. Some really simple algorithms become ridiculously complicated functions, assuming they can even be translated into pure functions at all.

-Farrell
« Last Edit: April 23, 2022, 04:44:18 pm by farrell »
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14445
  • Country: fr
Re: Possible to Simulate MCU/FPGA PID Control Loop in LTspice?
« Reply #4 on: April 23, 2022, 04:42:59 pm »
Considering how most designs these days are a mix of analog and digital circuits (nearly everything has an MCU or FPGA!) I'm surprised that there isn't a clean way to simulate how those circuits interact. There are simulators for verifying HDL, and simulators for verifying analog circuits, but no simulators that let you test both together? I'm really surprised that a SPICE simulator doesn't support some sort of discrete-time algorithmically-defined component. Some really simple algorithms before ridiculously complicated functions, assuming they can even be translated into pure functions at all.

You can do mixed-signal simulation with a number of tools. ngspice has extensions for this. There's a learning curve.
LTSpice also does mixed-signal simulation, but it's restricted in how the user can define their own digital blocks. You have a number of basic logic/digital primitives, and beyond that, all the rest is hidden from them. But LTSpice sure does make heavy use of mixed-signal sim. for most of their advanced models that include digital blocks, such as SMPS chips.

So with LTSpice, you can do mixed-signal sim, but the user is limited to basic logic primitives. They're probably not going to be convenient for what you want to achieve.
But as I suggested from my link, you can use arbitrary sources and functions for simulating a PID. It will just take a bit of thinking.
 

Offline jpyeron

  • Regular Contributor
  • *
  • Posts: 108
  • Country: us
    • PD Inc
Re: Possible to Simulate MCU/FPGA PID Control Loop in LTspice?
« Reply #5 on: April 23, 2022, 06:11:25 pm »
Considering how most designs these days are a mix of analog and digital circuits (nearly everything has an MCU or FPGA!) I'm surprised that there isn't a clean way to simulate how those circuits interact. There are simulators for verifying HDL, and simulators for verifying analog circuits, but no simulators that let you test both together? I'm really surprised that a SPICE simulator doesn't support some sort of discrete-time algorithmically-defined component. Some really simple algorithms before ridiculously complicated functions, assuming they can even be translated into pure functions at all.

You can do mixed-signal simulation with a number of tools. ngspice has extensions for this. There's a learning curve.

This has the most promise, but it is a major PIA... I have been attacking this for a SDSMPS project. Each change in the external libraries requires a relink of ngspice. In hobby time I am looking to modularize the interface and support dynamic linking.

It also has the pros and cons of using within kicad.
 

Offline farrellTopic starter

  • Contributor
  • Posts: 19
Re: Possible to Simulate MCU/FPGA PID Control Loop in LTspice?
« Reply #6 on: April 25, 2022, 08:48:39 pm »
A little more research revealed that Altium supports mixed-signal simulation:

https://www.altium.com/documentation/altium-designer/mixed-signal-circuit-simulation-overview

But has anyone tried it? I've looked for a tutorial or example of a *mixed-signal* simulation, but have not found any. I've found several examples of normal (analog-only) simulations, but nothing mixed-signal.

-Farrell
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf