Author Topic: Compensating an OpAmp  (Read 2230 times)

0 Members and 1 Guest are viewing this topic.

Offline npelovTopic starter

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: bg
    • Microlab.info
Compensating an OpAmp
« on: February 27, 2023, 03:17:22 pm »
I read somewhere that there is no such thing as "internally compensated opamp". Opamps get less stable at unity gain (correct me if I'm wrong). I've used opamps without compensation before and it works fine (at low frequencies and low adc resulution).

I'm asking in for a specific case - buffering voltages of high resistor value dividers (200k:20k)  with built in 10 bit ADC of PIC16F15324. The pin input capacitance is 5pF, Sampling capacitor of ADC is 10pF. The interconnect resistance + sampling switch resistance = 8kOhm, so the sampling cap 10pF can be pretty much ignored. There will be some PCB capacitance which shouldn't be that much - no ground plane, 10-20mm (<1inch) trace from output to pin, 0.6mm trace.

But also I want to know in general when should I compensate OpAmp and when I'm overdoing it. I don't want to be able to do the calculations - I already tried that, and as many of you pointed out - in most cases you can just workaround the math by simulation, building the circuit and testing, using best practices ... etc. I'm too old for math:)

So I attached 3 levels of compensation (not 100% sure what I'm doing - schematics could be wrong).  fig 2 amplifies by 2, so the divider has to be changed. fig. 3 fixes that, but multiply that by two inputs and component count is getting ridiculous. But even if this doesn't make sense for 10 bits, I was curious about those 22 bit ADCs MCP3550. What if I want to play with microvolts.

I also found this one  - with the cap and resistor connected directly on the opamp output.

TLDR:
So when and how I should compensate?
« Last Edit: February 28, 2023, 12:11:39 am by npelov »
 

Online David Hess

  • Super Contributor
  • ***
  • Posts: 16748
  • Country: us
  • DavidH
Re: Compensating an ApAmp
« Reply #1 on: February 27, 2023, 04:13:32 pm »
I read somewhere that there is no such thing as "internally compensated opamp". Opamps get less stable at unity gain (correct me if I'm wrong). I've used opamps without compensation before and it works fine (at low frequencies and low adc resulution).

Operational amplifiers are almost always compensated internally with an on-chip capacitor, which is what allows them to operate at low gain, but phase margin does decrease at lower closed loop gain decreasing stability, but they can be completely stable.  The feedback capacitor you are adding externally requires the operational amplifier to be unity gain stable, otherwise it would cause oscillation.

Example 2 and 3 that you give are circuits used to compensate an operational amplifier so that it can drive a capacitive load, which might be required to achieve a low AC impedance at high frequencies, but is not necessary in your application; just drive the microcontroller's analog input directly, or through an RC filter to control bandwidth.
 

Online TimFox

  • Super Contributor
  • ***
  • Posts: 7987
  • Country: us
  • Retired, now restoring antique test equipment
Re: Compensating an ApAmp
« Reply #2 on: February 27, 2023, 05:21:33 pm »
The minority of op-amps that are not unity-gain stable ("decompensated") are designed for use at closed-loop gain (actually, "noise gain") greater than unity, with greater slew rate than a similar device compensated for unity-gain stability.
They usually bring out the terminals for an external compensation capacitor, which could be chosen for unity-gain stability with a slower slew rate, or to match a gain somewhat greater than unity.
With such a device, you can "overcompensate" with a larger external capacitor, which would give greater phase margin at unity gain and an even slower slew rate, if that tradeoff is useful.
Another technique with a non-unity-gain-stable op-amp is to add a resistor (or resistor-capacitor series network) between the two inputs to increase the noise gain.
In popular devices, 1/2 of a 5532 is unity-gain stable, but the similar (single) 5534 requires an external 22 pF capacitor for unity gain and 6 V/us slew, but is suitable for gain >3 at 13 V/us without external compensation.
(The 8 pin package for the 5532 does not have extra pins for external compensation.)
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 6848
  • Country: pl
Re: Compensating an ApAmp
« Reply #3 on: February 27, 2023, 05:38:04 pm »
I read somewhere that there is no such thing as "internally compensated opamp". Opamps get less stable at unity gain (correct me if I'm wrong). I've used opamps without compensation before and it works fine (at low frequencies and low adc resulution).

I'm asking in for a specific case - buffering voltages of high resistor value dividers (200k:20k)  with built in 10 bit ADC of PIC16F15324. The pin input capacitance is 5pF, Sampling capacitor of ADC is 10pF. The interconnect resistance + sampling switch resistance = 8kOhm, so the sampling cap 10pF can be pretty much ignored. There will be some PCB capacitance which shouldn't be that much - no ground plane, 10-20mm (<1inch) trace from output to pin, 0.6mm trace.
There is such a thing as unity gain stable opamps, and they are stable at unity gain unless driving significant capacitive load.
The exact value of "significant" may vary from type to type, but a few pF shouldn't be a problem for any common general purpose opamp.

Speaking of your application, I'm not sure if the PIC ADC needs buffering when output impedance of the divider is only 20kΩ (actually, even a little less). But I have zero familiarity with PICs so do your own homework.

The first circuit from your examples only makes things worse. If anything, put the series resistor after the feedback takeoff point (this, of course, increases output impedance of the amplifier).
 

Online David Hess

  • Super Contributor
  • ***
  • Posts: 16748
  • Country: us
  • DavidH
Re: Compensating an ApAmp
« Reply #4 on: February 27, 2023, 07:36:35 pm »
There is such a thing as unity gain stable opamps, and they are stable at unity gain unless driving significant capacitive load.
The exact value of "significant" may vary from type to type, but a few pF shouldn't be a problem for any common general purpose opamp.

Many modern parts are unity gain stable and will drive either large capacitive loads, or any capacitive load, while remaining stable.

But it will not be a problem in this application, and practically any operational amplifier will drive 10s of picofarads without issues.
 

Offline npelovTopic starter

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: bg
    • Microlab.info
Re: Compensating an OpAmp
« Reply #5 on: February 28, 2023, 12:38:40 am »
just drive the microcontroller's analog input directly, or through an RC filter to control bandwidth.
Thanks for that tip. While reading about compensation I got that the opamp can become unstable at high frequencies + low gain - so I could use a capacitor on the lower part of the divider to make a low pass filter - reduce the noise, prevent aliasing and improve stability.

There is such a thing as unity gain stable opamps, and they are stable at unity gain unless driving significant capacitive load.

This reminds me that all of my efforts to make current source with an opamp end up in oscillation. By putting caps here and there (advised in forums) I was able to reduce the oscillation amplitude low, but it does happen sometimes and it depends on what load I'm using. When I use mosfet the high gate capacitance is a problem. With BJT I can't get down to 0 volts. I had some good results with a really high on resistance MOSFET that has lower gate capacitance.  But I still get oscillations sometimes. Which circuits are best for driving high capacitive loads - 1 to 10 nF. I want it to be stable as a rock even if it doesn't respond that fast. For example I want it to be stable when using PWM (or at least the frequency of oscillation should be equal to PWM frequency at lower frequencies).
 

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 1479
Re: Compensating an OpAmp
« Reply #6 on: February 28, 2023, 01:56:46 am »
I read somewhere that there is no such thing as "internally compensated opamp". Opamps get less stable at unity gain (correct me if I'm wrong). I've used opamps without compensation before and it works fine (at low frequencies and low adc resulution).

I'm asking in for a specific case - buffering voltages of high resistor value dividers (200k:20k)  with built in 10 bit ADC of PIC16F15324. The pin input capacitance is 5pF, Sampling capacitor of ADC is 10pF. The interconnect resistance + sampling switch resistance = 8kOhm, so the sampling cap 10pF can be pretty much ignored. There will be some PCB capacitance which shouldn't be that much - no ground plane, 10-20mm (<1inch) trace from output to pin, 0.6mm trace.

But also I want to know in general when should I compensate OpAmp and when I'm overdoing it. I don't want to be able to do the calculations - I already tried that, and as many of you pointed out - in most cases you can just workaround the math by simulation, building the circuit and testing, using best practices ... etc. I'm too old for math:)

So I attached 3 levels of compensation (not 100% sure what I'm doing - schematics could be wrong).  fig 2 amplifies by 2, so the divider has to be changed. fig. 3 fixes that, but multiply that by two inputs and component count is getting ridiculous. But even if this doesn't make sense for 10 bits, I was curious about those 22 bit ADCs MCP3550. What if I want to play with microvolts.

I also found this one  - with the cap and resistor connected directly on the opamp output.

TLDR:
So when and how I should compensate?


Hello,

It looks like your time domain response for Fig 3 is:
Vout=1-e^(-(0.0055*t)/Cout)*cos((5e-4*sqrt(400000000000*Cout-121)*t)/Cout)

so you could investigate the theoretical response using that to get an idea what is going on.
You can note that Cout is part of the exponential and part of the angular frequency, so as you change Cout the response either dies down faster or slower, and the frequency increases or decreases.  Now if Cout is a certain value, the frequency will be 'faster' than the exponential can damp the response, so you will get ringing.  That means overshoot and plenty of oscillation until it dies down, or just a little overshoot until it dies down.  So it's like a race between the exponential part and the oscillatory cosine part ... if the oscillatory part takes a long time to reach a peak, the exponential damps the response down and there will be little or no overshoot.

If Cout is very small, the cos() part changes to cosh() and that means no oscillation at all.  However, you dont really need that you can get by with a larger value of Cout.  For example, if you stay under 100pf you should see a decent response.  If you go up to 1000pf you will see overshoot.

The usual idea now is to figure out what you need in terms of settling time because that is very typical using an ADC.
You dont want to be too slow, but if you go too fast you get ringing and much overshoot.  The overshoot however leads to faster response, so it ends up being a trade off.  If your response time is not really too important then you are probably ok with the circuit as is.  It may even be fast enough for many applications.

This is a theoretical result using an ideal op amp.  The real life response of the op amp could change this to some extent, but that function above is good for getting a grip on what is happening with this circuit.
« Last Edit: February 28, 2023, 02:04:16 am by MrAl »
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 6848
  • Country: pl
Re: Compensating an OpAmp
« Reply #7 on: February 28, 2023, 06:39:44 am »
This reminds me that all of my efforts to make current source with an opamp end up in oscillation.

I want it to be stable as a rock even if it doesn't respond that fast.
A common solution for dummy loads / active current sinks or sources is like your fig2 with the MOSFET and sense resistor circuit in place of R1. And R3 can be removed if you want U1 to run unity gain. The product of R2·C1 ("time constant" - look it up) determines how "slow" the circuit becomes.

Dave did a video on a simple opamp+FET dummy load which used this exact technique IIRC.
 

Offline npelovTopic starter

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: bg
    • Microlab.info
Re: Compensating an OpAmp
« Reply #8 on: February 28, 2023, 05:38:37 pm »
If Cout is very small, the cos() part changes to cosh() and that means no oscillation at all.  However, you dont really need that you can get by with a larger value of Cout.  For example, if you stay under 100pf you should see a decent response.  If you go up to 1000pf you will see overshoot.

The usual idea now is to figure out what you need in terms of settling time because that is very typical using an ADC.
You dont want to be too slow, but if you go too fast you get ringing and much overshoot.  The overshoot however leads to faster response, so it ends up being a trade off.  If your response time is not really too important then you are probably ok with the circuit as is.  It may even be fast enough for many applications.


I didn't understand most of what you said. My math skills are basically zero :(. I don't know which capacitance you refer by Cout. Is it C1 in the schematics I posted or the load capacitance. Load capacitance 1000pf and ADC will probably never meet together in the same circuit. The load capacitance is 1 to 10 nF when driving a power MOS transistor.

Also I'm not sure what to do with the formula. I could find some software and plot it and see what's the amplitude of  Vout, but I don't really know what software to use.


A common solution for dummy loads / active current sinks or sources is like your fig2 with the MOSFET and sense resistor circuit in place of R1. And R3 can be removed if you want U1 to run unity gain. The product of R2·C1 ("time constant" - look it up) determines how "slow" the circuit becomes.

Dave did a video on a simple opamp+FET dummy load which used this exact technique IIRC.

So it's something like this:
https://electronics.stackexchange.com/questions/239888/op-ampmosfet-current-source-why-do-we-need-a-feedback-resistor

I watched Dave's video long time ago. I think he used an LDO which had useful opamp configuration n the feedback circuit. I'll review the video again when I get back to current source again.

I also want to retro-fit current limiting in a normal switching IC - like the Chinese do, but better. Most Chinese DC-DC converters with current limiting do not hold stable voltage while current limiting. There is a transition region where the current  starts to drop before the voltage has reached the set level.

A question: Can I use regular mosfet driver (like TC4428) between the opamp and the MOSTFET? They are usually used for switching. Will they work for continuous/linear drive (not sure how to say it)
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14352
  • Country: de
Re: Compensating an OpAmp
« Reply #9 on: February 28, 2023, 06:04:29 pm »
The MOSFET gate dirvers are for switching only. They usually don't work linear.

For driving the MOSFET in a linear regulated constant current load, the normal way is to have a series resistor (e.g. 22 -100 ohm)  between the OP-amp and the MOSFET gate. So the OP-amp will not directly see the capacitive load but only the combination the resistor and capacitor, which is OK for the OP-amps.
Very large MOSFETs with large gate capacitance may be a bit slow. Parallel channels with seprate op-amps in parallel may be the faster choice.
 

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 1479
Re: Compensating an OpAmp
« Reply #10 on: March 01, 2023, 03:53:25 am »
If Cout is very small, the cos() part changes to cosh() and that means no oscillation at all.  However, you dont really need that you can get by with a larger value of Cout.  For example, if you stay under 100pf you should see a decent response.  If you go up to 1000pf you will see overshoot.

The usual idea now is to figure out what you need in terms of settling time because that is very typical using an ADC.
You dont want to be too slow, but if you go too fast you get ringing and much overshoot.  The overshoot however leads to faster response, so it ends up being a trade off.  If your response time is not really too important then you are probably ok with the circuit as is.  It may even be fast enough for many applications.


I didn't understand most of what you said. My math skills are basically zero :(. I don't know which capacitance you refer by Cout. Is it C1 in the schematics I posted or the load capacitance. Load capacitance 1000pf and ADC will probably never meet together in the same circuit. The load capacitance is 1 to 10 nF when driving a power MOS transistor.

Also I'm not sure what to do with the formula. I could find some software and plot it and see what's the amplitude of  Vout, but I don't really know what software to use.


Oh ok no problem, i'll try to post a couple waveforms so you can see what it looks like.
Cout is of course the capacitance at the output connected to ground.  That means Cout is the load yes.  That was the main concern so i developed the formula to reflect the way the response changes with different values for Cout.

In words, with a fast change in input, with Cout small the output ramps up smoothly and settles out to a constant value.  With Cout larger, the output jumps up and then down a bit then back up a bit then back down a bit, then finally at some point it settles out to a constant value just like before.
The difference is with the small value of load cap the output is very stable, and although it may still be considered stable with larger cap it will oscillate up and down several times before it settles out to a constant value.  The number of times it goes up and down depends on how large the cap value is and is often referred to as 'ringing'.

I'll try to get back tomorrow with some waveforms so you can see exactly what happens.
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 4846
  • Country: vc
Re: Compensating an OpAmp
« Reply #11 on: March 01, 2023, 06:49:31 am »
Without the math you may put the stuff into the LTspice (it is free and easy to use), for example:
 

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 1479
Re: Compensating an OpAmp
« Reply #12 on: March 01, 2023, 08:10:51 pm »
Without the math you may put the stuff into the LTspice (it is free and easy to use), for example:

Yes and that shows the ringing with larger cap values so that's good to see.
I use LT Spice also.
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 6848
  • Country: pl
Re: Compensating an OpAmp
« Reply #13 on: March 01, 2023, 08:56:25 pm »
A common solution for dummy loads / active current sinks or sources is like your fig2 with the MOSFET and sense resistor circuit in place of R1. And R3 can be removed if you want U1 to run unity gain. The product of R2·C1 ("time constant" - look it up) determines how "slow" the circuit becomes.

Dave did a video on a simple opamp+FET dummy load which used this exact technique IIRC.

So it's something like this:
https://electronics.stackexchange.com/questions/239888/op-ampmosfet-current-source-why-do-we-need-a-feedback-resistor
Yes.
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 4846
  • Country: vc
Re: Compensating an OpAmp
« Reply #14 on: March 02, 2023, 01:31:43 pm »
So, how to calculate the optimal R1, C1, when you know the R2(R3), C2 and Ro (open loop output resistance of the opamp) in the above fig3 schematics ????

PS: the stackexchange formula in the link says something like

(R2||R3)_min = C2 * (R1+Ro) / C1

but not sure about.. We do need math here :)

« Last Edit: March 02, 2023, 02:19:10 pm by imo »
 

Offline npelovTopic starter

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: bg
    • Microlab.info
Re: Compensating an OpAmp
« Reply #15 on: March 02, 2023, 09:37:26 pm »
Without the math you may put the stuff into the LTspice (it is free and easy to use), for example:
Oh, that's so valuable! Thanks! I didn't know you can draw graph for multiple values. What I usually do is change the value and run again.

Now only if you tell me where to get good models for LM358, MCP 601(2), MCP6001, and other microchip opamps - I like them a lot.

So, how to calculate the optimal R1, C1, when you know the R2(R3), C2 and Ro (open loop output resistance of the opamp) in the above fig3 schematics ????

PS: the stackexchange formula in the link says something like

(R2||R3)_min = C2 * (R1+Ro) / C1

but not sure about.. We do need math here :)

That's not what I meant by math. Technically it is math too, but I don't think someone will consider that a problem. Thanks for the formula! Is it a good idea to put feedback cap with a bit higher value - just in case? What do I loose (other than slowing down the response)?

Also I don't see frequency in that formula. Does that mean that it''ll work even at high frequency with a fast opamp?
And doesn't it depend on what opamp is used? Not all opamps are the same. Which parameter is important if I'm choosing an opamp for driving capacitive load? Slew rate?
 

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 1479
Re: Compensating an OpAmp
« Reply #16 on: March 03, 2023, 11:42:58 am »
You can get spice models from the companies that produce the components and also with a general web search sometimes.
 

Online David Hess

  • Super Contributor
  • ***
  • Posts: 16748
  • Country: us
  • DavidH
Re: Compensating an OpAmp
« Reply #17 on: March 07, 2023, 12:20:00 am »
A question: Can I use regular mosfet driver (like TC4428) between the opamp and the MOSTFET? They are usually used for switching. Will they work for continuous/linear drive (not sure how to say it)

No, but there are linear buffer chips and circuits which can be used between the operational amplifier output and a capacitive load to more effectively drive the capacitive load.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf