Ever wanted to include an ADC + DSP/MCU + DAC chain in your SPICE analog circuit simulation? Here is an approach where you can directly use the program code of your DSP or microcontroller (MCU) firmware. You only have to program a small adapter routine to simulate ADC and DAC behavior. Then all this can be integrated in the SPICE simulation.
How does it work?
Ngspice is the next generation of the SPICE analog circuit simulator. It includes XSPICE which supports custom so called "Code Models", i.e. models for circuit element which are provided by the user as C routines. I've developed such a Code Model which simulates periodic ADC sampling and DAC output updates. For every period the adapter routine is executed which itself can execute the original DSP/MCU firmware code. So, the DSP/MCU firmware is an actual component in the SPICE simulation.
Example: FIR Filter
Consider a finite impulse response (FIR) Filter implemented in a DSP or MCU, e.g. as an audio processor.
As an example, an 11-th order FIR low-pass filter was implemented as a simple C function. The input signal was provided by another custom code model. This was configured to generate a sweep from 100Hz to 22kHz with logarithmic increments within 220ms. The sampling rate of the FIR filter was set to 44.1kHz. The following image shows the input and output signal (orangein1
and blue out1
, respectively) as well as the output signal filtered by a 10kHz RC low-pass reconstruction filter (red vout
). The amplitude of out1
clearly shows the filter characteristics with stopband ripples as predicted by Matlab's fvtool
.
Application: Source Measurement Unit
A Source Measurement Unit (SMU, also called SourceMeter) is an instrument which does precise voltage and current measurements as well as constant voltage or constant current supply. It can operate in all four quadrants (source and load for positive and negative voltages and currents). The main application of the above mentioned Code Model is the development of an SMU with a fully digital control loop. The only analog part is a Class AB push-pull output stage, everything else, especially the control algorithm, is implemented by software.
Note that this enhances the above FIR filter example to a closed loop setup.
To be precise, there will be more analog components: translate DAC output voltages to the FET gate voltages, translate actual output voltage to ADC input voltage, shunt resistors for current measurement, ... BTW, the shunt in the positive supply is necessary to set a small but controlled quiescent current through both FETs.
The above mentioned Code Model will be used to test and optimize the control algorithm together with the analog circuitry in a SPICE simulation. The source code can then be used without modifications when compiling the DSP firmware. An ARM Cortex-M4F with floating-point support will be used as DSP. These are readily available with 120MHz, which allows roughly 1200 instructions for the control algorithm at a sampling rate of 100kHz.