# Why do we compensate PWM controllers?

I have been studying switch mode power supplies for a while. I have understood the working principle of several common topologies But there is a detail in the control circuit structures which I still don't understand. We use the $R_c$ and $C_c$ to "compensate" the voltage feedback. But why? I saw many sample practical designs in PWM controller IC datasheets. Almost all of them include this RC compensation technique. But none of them mention how to choose the values of $R_c$ and $C_c$. Why do we need such a compensation and how do we determine the values of these elements? ## 2 Answers

It's fundamental control and feedback theory. Thank you Mr Lyapunov, Mr Black, and Mr Nyquist.

Consider that everyone everywhere always wants the output of their power supply to have just the right voltage, no matter what. How to manage that? The best way we know of is by using feedback.

Feeding a sample of the output voltage, and current, back around to compare against some reference standard. Since the feedback is negative, or since the difference is take between the output quantity and the reference, an error signal is obtained.

In your example circuit, the difference between Vref and Vfb is taken in the Error Amp to get Verr. For best accuracy, Verr needs be minimized, so the Error amp also applies gain, a lot of gain, the more the better.

It's kind of like the virtual ground situation with an OpAmp. The OpAmp has lots of gain, it's output is fed back to the input in a negative way, and the difference between the positive input and negative input becomes virtually zero. If the OpAmp is ideal with infinite gain the difference between the inputs is zero. Same basic idea with a PWM controller, although with extra stages. According to this idea, you just need infinite gain and bandwidth in the error amp (and everything else) to achieve what everyone everywhere wants all the time.

Infinite Bandwidth? Stop Here

If all the stages of the loop had infinite bandwidth, that would be all there would be to this. No compensation would be needed. But, there are bandwidth limits everywhere.

First, there is the Nyquist frequency of the PWM sampling. Because of sampling once per PWM period the gain and phase of the power modulator, all that stuff in your diagram between the Error amp output and the output filter input, will crash like a load of bricks going over a cliff at the Nyquist frequency.

Then because the switching power supply functions by time sampling various voltages, at least Vin and Vin Rtn, it's raw output is kind of bumpy and get's filtered to be smoothed out. The filter always provides at least 2, sometimes more, and usually complex poles. (Some would say that current mode control gets ride of one of the poles, but really it just gets move out so that you don't really much care about it.) Two plus poles provide 180 Degrees of phase loss, which with the negative feedback and lots of gain will make a wonderful oscillator.

We still need lots of loop gain especially at low frequencies to take care of output error and mains ripple, but how to handle all that phase shift as frequency goes up? Make an integrator of the loop. That way gain is maximally high at DC, but falls off by 20dB per decade, only adding 90 degrees of phase shift at the higher frequencies. Eventually, more poles show up, so loop gain is adjusted to have overall gain less than 0dB by then.

Most of what it takes to turn the loop into an integrator is done by the Error amp and it's compensation. The most simple case will have compensation for a single pole, a form of which is in your diagram with $R_c$ and $C_c$. This sort of compensation works pretty well for loops with current mode control and discontinous Flybacks, which will have a dominant pole at the output filter cap and load ($f$~$\frac{1}{2\pi R_o C_o}$). In this case $R_c$ and $C_c$ are chosen to cover that pole, and to set the Error amp gain to cross 0dB before any other poles show up.

This is rarely done by trial and error, as there are an infinite number of ways to mess up the loop and only a few ways to get it really right.

You should also know that the referenced diagram is a special, but favorite case. The error amp isn't really an OpAmp, but rather a transconductance amp, converting voltage to current. That's why $R_c$ and $C_c$ are shown going to ground instead of the inverting input. Vc ends up being the Error amp output current times the impedance of $R_c$ and $C_c$. It's a favorite case because transconductance amps are easier to make in an IC, so they are very commonly used in PWM controllers.

There are questions on this site that are related, here are a couple:

Control Theory Boost Converter

Here's one from TI about Compensation amps.

If you looked at the open-loop gain of the system you'd see that closing the loop would cause the system to self-oscillate without using the appropriate compensating components.

Imagine Vfb was not connected back to the error amp but instead you monitored it on an O-scope. Set the +input on the error amp to some abitrary dc value and replace Vref with an oscillator input.

Remove the compensation components.

Sweep the input from DC up to several MHz and look at the open-loop Vfb signal. What you'd notice is that there is high gain at low frequencies and this gets smaller as frequency rises. You also see a phase change in the signal and at some abitrary high frequency the Vfb signal would eventually shift phase such that if Vfb were connected there would be positive feedback and the whole circuit would become an oscillator.

The compensation circuit is there to either prevent that phase shift or make the open-loop gain less than unity at the point when the signal does shift in phase.

This stabilizes the system.

How do you choose them? Probably trial and error in many cases because it's possibly quicker than doing the maths.

• Is there somewhere one could look up the maths if they cared to? – Ignacio Vazquez-Abrams Nov 15 '14 at 22:40
• @IgnacioVazquez-Abrams The maths depends on what the circuit is and calcualting the open-loop gain theoretically as a formula. – Andy aka Nov 15 '14 at 22:43