Possible to Simulate MCU/FPGA PID Control Loop in LTspice? - Page 1
Forum section: electronics / general

author: farrell
author_rank: Contributor
timestamp: April 23, 2022, 12:52:23 am
content: 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

author: nctnico
author_rank: Super Contributor
timestamp: April 23, 2022, 02:12:13 am
content: 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

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 23, 2022, 03:19:04 am
content: You can start here:https://ltwiki.org/index.php?title=B_sources_(common_examples)Read till the end. Should give you ideas to try.

author: farrell
author_rank: Contributor
timestamp: April 23, 2022, 05:11:37 am
content: 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

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 23, 2022, 04:42:59 pm
content: Quote from: farrell on April 23, 2022, 05:11:37 amYou 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.

author: jpyeron
author_rank: Regular Contributor
timestamp: April 23, 2022, 06:11:25 pm
content: Quote from: SiliconWizard on April 23, 2022, 04:42:59 pmThis 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.

author: farrell
author_rank: Contributor
timestamp: April 25, 2022, 08:48:39 pm
content: A little more research revealed that Altium supports mixed-signal simulation:https://www.altium.com/documentation/altium-designer/mixed-signal-circuit-simulation-overviewBut 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