Analog Simulation Tools Aid Digital-Control-Circuit Designers
DESIGN VIEW is the summary of the complete DESIGN SOLUTION contributed article, which begins on Page 2.
Although analog and digital controllers may appear vastly different, their principles of operation are usually quite similar. Therefore, popular analog tools like Spice can still be used to benefit common digital proportional-integral controllers through analysis without spending hours on complex math or a fortune on specialized software.
Merging proven analog and digital technologies may achieve the best of both worlds. Listed are 10 benefits of analog simulation for digital circuits:
- Leverage decades of proven analog knowledge.
- Enhance intuitive understanding of system dynamics.
- Systematic circuit optimization.
- Time savings over trial-and-error iterations.
- Design validation through multiple-domain operation.
- Partition analog and digital circuitry.
- Substitute low-cost, high-speed op amps.
- Develop valuable education tools.
- Share results over multiple platforms.
- Free evaluation software is adequate for most circuits.
To give readers a hands-on view of these benefits, a digital infrared controller was developed. The PIC MCU drives current through an infrared emitter with its pulse-width modulator and measures the sensor voltage with its analog-to-digital converter.
The article details the simulation of the IR controller through the use of Spice. Among the topics covered are the voltage-controlled voltage source, which is essentially an ideal op amp that can simulate the controller simply by adding resistors and capacitors. Also discussed is execution of the proportional-integral algorithm in Visual Basic. Detailed Spice results are provided.
HIGHLIGHTS: | |
A Digital Controller Example | A closed-loop controller's function is to maintain a desired response despite system changes and disturbances. An infrared controller was developed for this article to guide the reader through the analog simulation of a digital circuit. |
Analog Simulation Of Digital Controllers | One of the most popular programs for simulating analog circuits is Spice, thanks to decades of validated operation and ease of access. An analog equivalent of the digital infrared controller executing the proportional-integral algorithm is provided to illustrate the simulation. The algorithm is executed through a PC in Visual Basic for development ease because it's faster and easier than generating firmware. |
Spice Results | Spice results for various parameters were determined for the example digital controller. For instance, the loop gain showed a 3.25-Hz bandwidth and 72.3° phase margin. The values were calculated automatically by the postprocessor in the evaluation version of Intusoft Spice. Also calculated was the transient step response, which matched the hardware measurement that was reached earlier. |
Full article begins on Page 2
Digital controllers stack up many benefits over their analog counterparts, including reduced parts count, greater flexibility, and ease of modification. In the transition from analog to digital, however, decades of useful knowledge have been cast aside. Countless articles on record talk about analyzing analog circuits to optimize bandwidth and stability margin. Just as many articles get into the tuning of digital controllers through trial-and-error approaches, which often results in less-than-optimal performance.
But transforming a system into its most fundamental elements for simulation has many advantages. Greater intuitive understanding is achieved through both transformation and simulation processes. Many people using varied software can share results, making more tools and application assistance available. Errors are less likely to go undetected when calculations are performed by multiple methods and then compared. Better optimization with respect to performance, robustness, and parts selection is possible with this enhanced understanding and availability of tools. Most importantly, decades of useful knowledge are put to work to benefit new and emerging technologies, which is essential for continued growth.
Although analog and digital controllers may appear vastly different, their principles of operation are usually quite similar. Therefore, popular analog tools like Spice can still be used to benefit common digital proportional-integral (PI) controllers through analysis, without spending hours on complex math or a fortune on specialized software. Merging proven analog and digital technologies may achieve the best of both worlds. Here are ten benefits of analog simulation for digital circuits:
- Leverage decades of proven analog knowledge
- Enhance intuitive understanding of system dynamics
- Systematic circuit optimization
- Time savings over trial-and-error iterations
- Design validation through multiple-domain operation
- Partition analog and digital circuitry
- Substitute low-cost, high-speed op amps
- Develop valuable education tools
- Share results over multiple platforms
- Free evaluation software is adequate for most circuits
We developed a digital controller for educational purposes (Fig. 1). The PIC MCU drives current through an infrared emitter with its pulse-width modulator (PWM) and measures the sensor voltage with its analog-to-digital converter (ADC) (Fig. 2).
The gain and time constant of the infrared circuit are set by resistors R4 and R5, respectively, which are selected for full ADC swing with timing in the range of human recognition. The PWM drive current illuminates the red LED (EMIT), while the supply current of the op amp with burden resistor illuminates the yellow LED response (SENS). This circuit, which reacts to external light or shadowing, has visual feedback to provide an intuitive "touch and feel" for educational control experiments.
Figure 3 is the Visual Basic interface to the digital infrared controller that allows different PI gains to be evaluated for a fast, stable response with minimal overshoot. This PC screenshot illustrates how easily the system may be adjusted for various applications, which is one of the primary advantages of a digital controller.
The benefit of a properly tuned control loop can be observed by noting the tall spike on the PWM drive signal with absence of spiking on the ADC response. The infrared emitter is initially driven hard to quicken the sensor response, but softens to steady state before the sensor can overshoot its desired value. Too much gain will cause the system to oscillate, while too little gain results in a sluggish response. Two independent gains complicate coincident optimization, and the third gain in a proportional-integral-derivative (PID) controller makes it even more challenging to properly tune. The differential term isn’t required for most dominant-pole systems, so it’s omitted in this demonstration.
Gains are typically adjusted empirically rather than analytically, because math in the S and Z domains tends to be cumbersome and mixed-signal control software is often expensive. A few simple approximations, though, enable this digital controller to be simulated with common analog software for systematic optimization of PI gains.
Analog Simulation of Digital Controllers One of the most popular programs for simulating analog circuits is Spice. Advantages of this program include decades of validated operation with countless application notes and ease of access–including free student versions.Early Spice versions possessed limitations, including lack of digital simulation, so third-party vendors introduced upgraded versions with increased capabilities. Despite mixed-signal upgrades, there are still advantages to defining systems in terms of simple analog components. These include portability between software packages and the intuitive understanding associated with universally defined parts.
A common and useful component in Spice is the Voltage-Controlled Voltage Source (VCVS). This essentially ideal op amp amplifies and buffers a voltage signal with programmable gain. The VCVS is identified in schematics and netlists by a reference designator that begins with the letter "E." The VCVS in Spice can simulate the digital infrared controller of Figure 2 simply by adding resistors and capacitors. Using these generic components lets the circuit run in virtually any analog simulator from any vendor.
Figure 4 shows the analog equivalent of the digital infrared controller executing the PI algorithm. The upper portion of the schematic is the infrared hardware from PWM to AD0, and the lower portion is the PI control software from AD0 to PWM. Together, these circuits simulate a digital closed-loop controller in Spice. Although this particular circuit was developed to simulate the digital infrared controller, its generic architecture may be used to simulate a wide range of analog and digital closed-loop control applications.
The precise gain and bandwidth of the infrared circuitry isn’t readily apparent from inspection of component data sheets, as is the case with many real systems. Operational performance is application-dependent and subject to variations in manufacturing and environment. Therefore, the infrared gain and bandwidth is derived empirically from the open-loop step response of AD0 to a sudden change in PWM.
The software interface program in Figure 3 lets the PWM drive be changed instantaneously, while observing the infrared response at AD0 in the actual hardware. A 10% duty-cycle step change in the PWM drive yields a 20% (1 V) change in the AD0 voltage response, which indicates an open-loop gain of two. It takes approximately 0.47 seconds for the response to reach 63% (1 − e−1 ≈ 0.63) of its final value. This is expected because the dynamic response of the circuit is dominated by the RC filter (1 MΩ × 0.47 µF = 0.47 seconds).
The infrared transistor in Figure 2 effectively acts as a current source driving a 20-kΩ load from a 5-V supply. The Thevenin equivalent of the emitter and sensor combination is then represented by the VCVS designated EIR with a gain of two and 20-kΩ impedance limited to 4.7 V by a zener diode. The RC filter is reproduced directly and the LM358 buffer is replicated with the unity-gain VCVS designated Ebuf. The remaining circuitry is the PI closed-loop controller.
The PI algorithm is executed through the PC in Visual Basic for development ease because high-level programming in a resource-rich PC is faster and easier than generating firmware in a resource-limited processor. The advantage of this approach is that a variety of control algorithms can be tested and compared quickly prior to committing to an embedded design. The penalty of this method is slower updates, which are limited by serial-data-transfer time and PC interrupt latency. It’s interesting to note that despite higher data rates, USB is usually slower in simple interactive applications due to extensive software overhead in a time-shared polled system.
The unique aspect of this software-to-analog conversion effort is to replicate operation of the PI software algorithm. Replication isn’t that difficult since PI is a direct adaptation of an op-amp circuit. However, one challenging aspect is to simulate sampled discrete operation of a digital system with continuous analog circuits. Therefore, reasonable approximations are employed for simplicity.
An average sample interval of 12.8 ms is measured, which includes reading micro inputs, calculating new control values, and writing micro outputs. This sample time is simulated with a 6.4-ms RC network, Rsamp/Csamp, that’s a reasonable approximation based on Nyquist criteria–which defines a relationship of two between signal and sample rates. It’s typically used to determine the required sample time for a given analog signal. But this application requires the inverse operation. The delay network Rdel/Cdel is added, because the MCU contributes an additional sample-cycle delay due to ADC oversampling and digital filtering for enhanced accuracy and resolution.
The unity-gain error-amp Err takes the difference between the desired setpoint and the measured response to be compensated for desired dynamics by the op-amp Ecomp with proportional and integral gains. Ecomp has a high open-loop gain of 100k, so its closed-loop gain is set by the ratio of feedback impedance Cint + Rprop to input impedance Rin. These amplifiers are configured such that a single inversion occurs throughout the control loop for negative feedback. Control textbooks normally use separate op amps for each P and I gain term. But practical circuits combine them for reduced parts count.
The primary purpose of integral gain, a function of Cint and Rin, is to have high gain at low frequencies for low steady-state error. The capacitor in the op amp’s feedback reduces amplifier gain at higher frequencies to avoid instability. At these higher frequencies, the impedance of Cint is much less than Rprop, so the proportional gain set by the ratio of Rprop to Rin dominates over the integrator. This technique eliminates the phase lag contributed by the integrator, which could otherwise induce instability when combined with the inherent phase lag of the infrared circuit.
To calculate the values of Cint and Rprop, it’s necessary to review the PI control software. It’s written in Visual Basic as follows:
Loop every Tsamp = 12.8mS data sample update.
The Spice analog conversion of this Visual Basic PI code is:
The Spice circuit also contains two independent voltage sources. Vsetpt is varied in the time domain for transient response and Vloop is used to evaluate stability in the frequency domain. These sources serve as tools to quantify behavior of the circuit.
Spice Results Loop gain is the ratio of ac response (PI in Figure 4) to ac stimulus (PWM in Figure 4) through the feedback loop. A system is stable with less than 180° lag at unity gain or 0 dB. Phase margin indicates the additional lag before instability is reached. The loop starts at 180° in a negative feedback system so 180° lag actually occurs at 360°, which is the same as 0°.This stability criterion can be interpreted to state that the gain through the loop should roll off to unity in response to a single pole. Each pole contributes 90° total phase lag, and multiple uncompensated poles can induce instability. The infrared filter contributes one pole and the integrator capacitor contributes another. Therefore, the pole of the integrator must be cancelled by the proportional term prior to the unity-loop-gain frequency.
Figure 5 shows the loop gain of the simulated infrared controller, which shows a 3.25-Hz bandwidth and 72.3° phase margin. These values were calculated automatically by the postprocessor in the evaluation version of Intusoft Spice. Mathematically, the ratio of PI to PWM is taken as a difference when calculating gain in dB, as well as phase.
While the hardware step response in Figure 3 gives a rough indication of loop bandwidth and phase margin, it doesn’t pave the way to optimization as well as the loop-gain plot in Figure 5. This graphic demonstrates that bandwidth is ultimately limited by sample frequency, and that proportional correction must exceed integral correction at the unity-gain frequency. These types of valuable observations are easier to reach after working with analytical tools than trial-and-error methods.
For example, if this exercise were repeated without proportional gain, the system step response would be on the verge of oscillation. This is because the lag of the integrator combined with the lag of the infrared circuit drives the loop phase dangerously close to 180° at the unity-gain frequency. On the other hand, without integral gain the system would be stable, but possess significant steady-state error. This is due to dc loop gain being low with only the proportional term. If lower gains were used for both terms, the loop bandwidth would be reduced and the circuit response to changes would be slow. Proper combination of proportional and integral gain is essential for a fast, stable, and accurate response.
In this case, the frequency in which proportional gain exceeds integral gain \{f = 1/\[(2π)(50 kΩ)(6.4 µF)\] = 0.50 Hz\} comes slightly after the corner frequency of the infrared circuit \{f = 1/\[(2π)(1 MΩ)(0.47 µF)\] = 0.34 Hz\} to maintain a single-pole roll-off to unity-loop gain. Proportional gain is selected to achieve a control-loop bandwidth (3.25 Hz) approximately one decade higher than the infrared circuit bandwidth (0.34 Hz).
Figure 6 is the transient step response of the simulated infrared controller, which matches the hardware measurement in Figure 3 very well. Gains and time constants of the infrared hardware and software compensation were varied, and multiple simulations were successfully compared to hardware results to validate the proposed techniques.
These gains were chosen conservatively for a robust response, despite changing conditions and production variations. Inspecting the Figure 5 Bode Plot of loop gain reveals that a more-aggressive design with higher bandwidth can be achieved by doubling both gains. Increasing KP to 10 (Rprop = 100 KΩ) and KI to 0.4 (Cint = 3.2 µF) results in an 8.1-Hz loop bandwidth with 60° phase margin. This modification is experimentally confirmed by passing a thin object through the infrared path shown in Figure 1, and noting a smaller AD0 disturbance in Figure 3 compared to the original gains of KP = 5 and KI = 0.2.