# LM358P output saturation around 6.05V (root cause turned out to be related to Arduino protection diodes)

For a constant current drain using a PWM input I am using the following setup:

simulate this circuit – Schematic created using CircuitLab

For small currents it seems to work as expected - the op-amp producing a voltage to the MOSFET which causes the current flow over the battery be such that the voltage drop over the 3.3 Ohm sense resistor becomes exactly the configured voltage, as expected.

But there must be something I have missed, because the current I can get maxes out much earlier than expected. This happens around 150 mA corresponding to an input voltage to the op-amps positive input (via PWM) of around 0.45V. At this point, the output from the opamp to the MOSFET seems to saturate around 6.05V. The problem is that further increases in the op-amps positive input has no effect. The opamp keeps producing a 6.05V output even though there is a large difference between the positive and negative input. I can see the opamp is getting, say, 0.8V at the positive input and is only seeing 0.45V at the negative input, yet it refuses to output more than 6.05-6.1V.

The Vcc to the op-amp is 12V so there should be plenty of headroom for it to output higher voltages even though it isnt a rail-to-rail opamp. I have looked in the datasheet but I cant seem to find a limitation that would explain this behavior, so I hope someone can explain what I am missing.

Update! I am a bit closer to resolving the mystery. I had a wire (not on the drawing) going from the output of the op-amp and to an analog input on the Arduino. I thought the analog inputs were high impedance so it wouldnt affect anything. But with that wire there I am seeing the 6V saturation (as measured by a multimeter, the Arduino only measures to 5V), but if I disconnect it everything works. Is this some type of oscillation involving the Arduino? Or is the Arduino draining the voltage?

NOTE! The root cause of this problem turned out to be different. I had connected a measuring wire from the op-amp output to the Arduinos analog input. My thinking was that it was high impedance and hence wouldnt affect outcome. I had noticed the measurements topping out after 5V but thought that was simply due to it being unable to report more than value 1023 and that it wouldnt actually affect the behavior of the circuit. This assumption was wrong; due to a protection diode in the Arduino inputs, the extra voltage was drained (the LM358P has a short-circuit voltage of 40-50 mA) causing the drop in the measured voltage (even with a multimeter) at the op-amp output. But the real culprit was the protection diode in the Arduino. Removing this measurement wire resolved the problem. I am leaving the original problem description in place so other people can find this report in case they encounter similar issues.

• Strange behavior. Maybe you have a damaged gate oxide in your FET? – John D Sep 2 '16 at 18:01
• Ok but would that be able to cause such a problem? Because it seems it is the output from the opamp that saturates and it saturates at a level below where the MOSFET would be fully turned on so from this perspective it is OK that the MOSFET doesnt conduct more than it does? – Morty Sep 2 '16 at 18:18
• A damaged gate oxide can cause the gate to go low impedance, possibly taking more current than the op-amp can drive. (Maybe 20mA or so.) So the amp could be trying to turn the FET on harder, but can't due to the damaged gate. ESD can cause that kind of gate damage. If you disconnect the gate from the amp does the amplifier swing up to the rail? – John D Sep 2 '16 at 18:53
• Hi John, good point. I tried removing the connection to the gate, but the voltage directly from the opamp is the same (i.e. still saturated at the level I mentioned). But thanks for the suggestion. – Morty Sep 2 '16 at 19:50
• Recheck all voltages on Op Amp and replace if not meeting specs. – Tony Stewart Sunnyskyguy EE75 Sep 2 '16 at 20:03

I had first imagined that your problem was that the opamp was oscillating and suggested that you try something like this (thanks to Spehro, too):

simulate this circuit – Schematic created using CircuitLab

Per further discussion, where you added that you were supplying the output of the opamp to an MCU input pin on your Arduino, it's also clear that even if you did (or would have had) an oscillation problem (and you would, I'm pretty sure) it is more likely now that your measured limit of around $6V$ was due to a heavily loaded protection diode at your MCU's analog input pin. The protection diode limitations for any given MCU can usually be found under the "Absolute Maximum Ratings" section of the datasheet, where that section will include a line described as something similar to: "diode current at any device terminal." Usually, the value listed there will be around $2mA$ or less.

If you must measure the opamp output voltage, then you will need to consider a different circuit arrangement to condition the opamp output (without disturbing its MOSFET control behavior) and make it suitable for input to the Arduino analog input pin.

• @Morty: I've built a number of these and I've always needed compensation like jonk recommends to get it stable. You can assess relative stability by removing your PWM smoothing cap and feeding a relatively slow (maybe 1kHz) square wave in while you observe the voltage on $R_{load}$ with a scope. More ringing (or outright oscillation) on the step means less stable. If you have flexibility in MOSFET choice, the IRFZ24N has much lower gate capacitance (370pF), unfortunately higher $R_{DSon}$ (70mΩ vs. 17mΩ), but the much larger $R_{load}$ you have will limit current capability before that. – scanny Sep 2 '16 at 19:20
• That will likely still oscillate, because of C3. Delete it and you should be fine. – Spehro Pefhany Sep 2 '16 at 19:57
• Good point. I shouldn't have added it. – jonk Sep 2 '16 at 20:03
• Hi Jonk, thanks for the suggestion. But see my update comment about the Arduino input also, thanks :) I think that is the culprit (but maybe it plays into your theory as well). – Morty Sep 2 '16 at 20:13
• @Morty: Yes. You almost certainly exceeded the maximum current into the protection diode, too. I hope without excessive damage. – jonk Sep 2 '16 at 20:16

I believe your circuit has gone unstable and is oscillating. You have a 1.5 kohm resistor feeding the gate and the gate capacitance will be "fractionally" seen relative to ground at this point and this will add a fair amount of phase shift. You close the loop and you get an oscillator.

Normally you can rely on the FET acting as a 1:1 voltage converter from gate to source but, with such a low value resistor in the source, this might degrade to more like 1:0.7 and this will mean 0.3 X gate-source capacitance is seen to ground at the gate. If it were a perfect 1:1 gate-source voltage converter then there would be no capacitance seen at the gate theoretically.

The specified gate capacitance is 1.9 nF for the IRFZ44 and so the 1.5 kohm resistor will see about 30% of this i.e. ~600 pF. This forms a 3dB low pass filter at about 178 kHz - at this frequency the signal is shifted by 45 degrees and thus reduces the phase margin of the LM358 causing it to sing its little heart out! It's probably oscillating somewhere between 200 kHz and 1 MHz. A more modern op-amp would have a graph of its open-loop phase response and this frequency would be easier to predict.

Try reducing the 1k5 to about 100 ohms or less and see if the situation improves. In fact I would just short out the 1k5 entirely. You could add an integrating capacitor and input resistor as pointed out in another answer but this will significantly reduce the dynamic capability of the circuit to maintain a constant current. It's a lot easier to drop the 1k5 in value.

• Good analysis, didn't think of that since I was assuming that the OP was looking at the output of the amplifier with a scope, but maybe not! – John D Sep 2 '16 at 18:55
• Hi thanks for the suggestion - I removed the 1k5 and replaced it with a wire. The saturation point increased a bit (5-10%) but the voltage I am seeing at the gate is exactly the same as before (almost exactly 6V). :/ – Morty Sep 2 '16 at 20:07
• Update! I am a bit closer to resolving the mystery. I had a wire (not on the drawing) going from the output of the op-amp and to an analog input on the Arduino. I thought the analog inputs were high impedance so it wouldnt affect anything. But with that wire there I am seeing the 6V saturation (as measured by a multimeter, the Arduino only measures to 5V), but if I connect the op-amp output to the Arduino analog in, I immediately see the drop. Is this some type of oscillation involving the Arduino? Or is the Arduino draining the voltage? – Morty Sep 2 '16 at 20:12
• Check the ATmega328 datasheet Absolute Maximum Ratings - most likely the AIN inputs cannot exceed VCC. There are internal PN junctions inside the Atmega328 which are being forward-biased by AIN exceeding the 5V supply. – MarkU Sep 2 '16 at 20:20
• Yes seems to be what happened - and the LM358P has a short-circuit output of around 40-50 mA. So maybe this prevented the damage and gave the impression things were working as long as the op-amp didnt try to output too high a voltage. – Morty Sep 2 '16 at 20:29

This is an example of over-driving your Arduino analog input. A voltage divider should have been provided in the first place (and actual connection to Arduino showed to allow meaningful discussion