# Problems while using op-amp as a comparator on a single supply

Here's my circuit: .

Application: The circuit is for ground fault detection. When a fault current of 20mA flows through the primary of the current transformer (1:660), it generates a current of ~30uA in the secondary. This current drops across the 10k resistor to give ~5-6mV. This is amplified and given to a comparator to generate a $(V_{CC}-1.5)V$ which will be given as an input to arduino. The arduino will then turn off the relays which will cut off the mains power.

My problem is as follows: I am using a voltage divider network to generate $\pm2.5V$ for powering the LM358. The first part which is the inverting amplifier works correctly and I get a 0.5V output at pin 1 for a 5mV input. Now I want the second op-amp to generate a high voltage whenever the input to it is $\ge 0.5V$. So I am using the second op-amp in comparator mode. I use a 20k trim pot to generate 0.45V reference for the inverting terminal of the second op-amp. Since the trim pot is connected to +2.5V rail in the circuit, it acts parallel to the voltage divider network (which powers the op-amp) and there is no longer a equal $V_{CC}/2$ drop across the two resistors. Now that the rails are no longer $\pm2.5V$, the op-amp fails to function correctly. Can anyone help me out with this? I know I could go for a dedicated dual power supply but I am trying to operate using a single supply only.

• Is there a reason for not connecting the non-inverting input of the left op-amp to 2.5 V and the trim-pot to 2.5 V instead of gnd? And then just feed the op-amps with 5 and 0 V, instead of 2.5 V and -2.5V – Harry Svensson May 28 '18 at 7:36
• @HarrySvensson Hi, I did that early on but I just wanted the op-amp output to be AC only. Providing the non-inverting 2.5V will add a dc bias to my signal which I am avoiding and regarding the trim pot, I have connected one of the terminals of the trim pot to +2.5V and other to the ground. – Gary H May 28 '18 at 8:10
• @Sparky256 Hi, I agree that LM358 is very old for modern designs but I have read the datasheet and it was mentioned that it can work on a dual power supply of as low as +/- 1.5V Here's the link. Am I reading it incorrectly? – Gary H May 28 '18 at 8:12
• Ignore @Sparky256 , the LM358 is OK with a single 5v supply, as long as you work at the bottom end of it. The input common mode is from ground to 1.5v below the top rail. Use a much bigger value trimpot to generate your offset. Use smaller resistors if you must use a divider. Better yet, generate -1.4v, +3.6v rails from your 5v by replacing the lower splitter resistor with a pair of silicon diodes. It should not be difficult to design a single rail +5v that does all you want, removing all 'rail splitter' issues. – Neil_UK May 28 '18 at 8:13
• If you design for single 5v rail, no splitters, no problem. A higher value trimpot affects the splitters less. Lower value splitter resistors get affected less. Replacing lower resistor with a pair of diodes results in splitter with much lower dynamic impedance, so gets affected much much less. Diodes 'always' (not exactly true (at most 'practical' currents (say 10uA to 10mA))) have (about) 0.7v across them. And it centres the active range within the input common mode range(VCM). Taking the inputs outside their VCM is a good way of stopping the IC working. – Neil_UK May 28 '18 at 9:11

As you're using an AC input, a much less complicated configuration would be this.

I'm not claiming that your signal levels and gains are necessarily ideal, but am just reproducing them, to illustrate the change in design for single rail operation.

simulate this circuit – Schematic created using CircuitLab

R1 and R2 establish a voltage of about 1.66v on OA1, 1/3rd of rail to deal with the 0-3.5v VCM range. In this inverting configuration, their impedance doesn't really matter as they go to the +ve input, they could be in the 10k or even 100k range. (However (and I later realised I'd done this more or less automatically) I've sized them so they have a parallel resistance of 1k. This is what you'd use if you had a non-inverting configuration, as then they'd form the divider bottom resistor with a 1k resistance down to the virtual ground.)

Given the relatively large +500mV signal you're looking for, you could simply put pot R5 from rail to rail. However, its adjustment range can be reduced like this with R6 and R7. You could choose R5, 6, 7 values to give 1.5v at the bottom of R5 and 2.5v at the top, using a 1k pot, 1.5k for R7 and 2.5k for R6 (or 2.4k or 2.7k, there's a wide adjustment range after all). Or you could choose a tighter, or looser, range around your trip point of 1.66v+500mV.

The resistor string R1,2 will track the resistor string R5,6,7, so the stability in the face of temperature and rail voltage fluctuations will be quite reasonable.

• Thanks for the answer Neil, I used 1k/560 for R1/R2 so that reference for OA1 is 1.798V. OA1 output is 1.79V+0.77v(ac). I adjust my trim pot so there is 1.6V (lower than 1.8V) at inverting of OA2. In case of no input, my comparator output is 3.3V and when I adjust my trim pot to above 1.8, the output becomes zero. Things change when there is an input of 1.79V+0.77v(ac) (from the inverting stage) to the comparator. Now when I adjust my trim pot to 2.7V (above 2.57V), the output is 0.36V+0.56v(ac) and when I put it to 2.4V (below 2.57V), the output is 1V+1.2v(ac). Why does this happen? – Gary H May 28 '18 at 11:17
• @GaryH 2.4v/2.7v Vth behaviour? With 2.7v threshold, the output is predominantly low, which is expected. Why the AC? Not sure. Does your input go above 2.7v? How are you measuring? If with a meter on AC, there could be parts above the 2.7v. If with a scope, post a picture of th waveform. Same for 2.4v. As input crosses threshold for only short pulses, the DC average, as measured by a meter, may well be 1v (short time at 3.3v, long time at 0v) with the AC reading being 1.2v. So all sounds expected if using a DMM. The Arduino will have to interpret the high pulses appropriately. – Neil_UK May 29 '18 at 5:18
• @GaryH You may need a low pass filter to cope with any stray peaks on your mains input waveform. You will certainly need a scope to make progress on understanding and improving the circuit. As you're working with mains (very low frequency) waveforms, you can find software that turns your PC sound card into a scope, I think some can be had for free. – Neil_UK May 29 '18 at 5:21
• @GaryH It's worth mentioning that your circuit doesn't work as you expect. The load on the current transformer isn't 10k, it's dominated by the 1k input impedance of your virtual ground amplifier stage. If you want the voltage across 10k to be amplified by 100x, you need to either a) increase the impedances in your amplifier or b) switch to a high input impedance non-inverting configuration. 100k feedback with 1.5k//3k = 1k to 'ground' would give you a gain of 101. – Neil_UK May 29 '18 at 7:18
• @GaryH What is time spec for how fast this must operate when the ground fault current starts? The longer you have, the better filter you can use to prevent mains spikes from incorrectly triggering the output. Your 2.7v threshold measurement suggested to me that you may have that sort of thing going on. Of course, without a scope to see what's happening, it's all a bit hit and miss. – Neil_UK May 29 '18 at 7:20