Opamp Comparator oscillating GND and VCC

Thread Starter

anishkgt

Joined Mar 21, 2017
549
GND to mains earth ??? well i maybe wrong or this could be something new, i learned from others when i started laying out the PCB that the GND should not be connected to mains earth as there could be leakage current that may damage the circuitry.


Just to be clear here, GND is the PCB is ground pour on the PCB and EP is the one connected to Earth.

spwBRD.JPG
 

AlbertHall

Joined Jun 4, 2014
12,628
If the opamp circuitry has no connection to earth then no current can flow through R36 and R21 as it has nowhere to go and so the circuit will not work.
 

MrAl

Joined Jun 17, 2014
13,716
Hi,

Just to note, comparators usually need at least a little hysteresis to work properly or else the output can jump up and down while the input is changing slowly.
 

Thread Starter

anishkgt

Joined Mar 21, 2017
549
So connecting the GND to mains earth, would it be only of this part of the circuit or the whole pcb ?

And adding a histeresis would a resistor in series with the output of the opamp and the other end to the non-inverting pin on the op-amp.
 

AlbertHall

Joined Jun 4, 2014
12,628
As that part of the circuitry is simply detecting the presence or absence of mains voltage it would be better to use an opto-isolator to do that.
 

Thread Starter

anishkgt

Joined Mar 21, 2017
549
As that part of the circuitry is simply detecting the presence or absence of mains voltage it would be better to use an opto-isolator to do that.
Not detecting the presence of mains but detect the change in voltage during the OFF state. The presence of mains is something that comes with it.

I did think of an opto-isolator early then there would be aome voltage drop when using them like the all the resistors (which I still doubt would work). I read the voltage during the off state is actually from the snubber circuit R18 and C16. Can I increase that voltage in anyway ?
 

MrAl

Joined Jun 17, 2014
13,716
So connecting the GND to mains earth, would it be only of this part of the circuit or the whole pcb ?

And adding a histeresis would a resistor in series with the output of the opamp and the other end to the non-inverting pin on the op-amp.
Hi,

Yes, that's the way to add hysteresis. Usually start with a large value resistor, which gives just a little hysteresis, then decrease the value little by little if needed.
 

Thread Starter

anishkgt

Joined Mar 21, 2017
549
Hi,

Yes, that's the way to add hysteresis. Usually start with a large value resistor, which gives just a little hysteresis, then decrease the value little by little if needed.
Thank you. I am just new to using opamps. The Comparator was something that i had learned recently and put into use. How is the value for the resistor for the Hysteresis determined.
 

MrAl

Joined Jun 17, 2014
13,716
Thank you. I am just new to using opamps. The Comparator was something that i had learned recently and put into use. How is the value for the resistor for the Hysteresis determined.
Hello,

Well it depends how much noise you have or expect to have. It also depends how much the circuit can tolerate in the application.

You can approximate too. Say you have a 10k input resistor, then if you add a 100k feedback resistor you get about 10 percent hysteresis. If you had a 1k input resistor, then if you add the 100k, you would get about 1 percent hysteresis. If you had a 10 ohm input resistor and add 1k feedback resistor that's also about 1 precent.
So it is approximately (for quick idea) the input resistor divided by the feedback resistor, in fractional percent.
So 1k in, 100k feedback gives us:
1k/100k=0.01
which is called one percent.

You should start with a low percentage and see how well that works. It's hard to say what it should be without knowing more about the circuit and where it operates. Use the highest percentage you can get away with though, for best noise immunity.
 

Thread Starter

anishkgt

Joined Mar 21, 2017
549
Thank you for clearing that for me.

I am not sure how to check the noise with an oscilloscope reason being mains supply. But there is no supply at the primary when the load is switched OFF. I touched the probe at one of the terminal and that gave a distorted wave form that would be because the GND aligator clip was not connected not sure where that should be connected.

So the final circuit based on the suggestions looks like this, would this be correct?
cs.JPG
 
Last edited:

MrAl

Joined Jun 17, 2014
13,716
Thank you for clearing that for me.

I am not sure how to check the noise with an oscilloscope reason being mains supply. But there is no supply at the primary when the load is switched OFF. I touched the probe at one of the terminal and that gave a distorted wave form that would be because the GND aligator clip was not connected not sure where that should be connected.

So the final circuit based on the suggestions looks like this, would this be correct?
View attachment 150697
Hi

Oh so R38 is your hysteresis feedback resistor then?

That looks a little too small, but you can try it and increase if you do not get the resutls you want.
Sometimes measuring with a scope will interfere with the circuit so you just have to try different values for R38 until you get something that works.
If we knew exactly how your input varied we could do a little better i think.

But yes, the diode will drop as much as 0.5v which will swamp out the 0.2v measurement, if that is what you have to measure. For that you would probably need what is called a "precision" rectifier, which is an op amp combined with one or more diodes to get a rectified signal that can be low like 0.1v for example.

You can look up "precision rectifier" on the web. You might be able to get away with the simpler version that only uses one diode, or you can go to the more elaborate type with more than one diode.
The input is AC maybe 10mv to 3v, and the output is a rectified AC wave with amplitude that matches the input AC peak. You still need to filter it of course with maybe an RC filter as you already have.

Sound like something you can do?

BTW, if you only have to detect the positive excursions of the input AC wave you might use a circuit that just detects the positive peaks. An op amp amplifier might work for this. The inptu a sine wave, but since the op amp does not respond to the negative peaks it will only pass the positive peaks. That output could then be filtered, then use a comparator to detect the level. This is almost the same as a half wave precision rectifier.

If your software can handle pulses (or you can change it to that) then you can just use a comparator to detect the AC input. The output will be pulsing though so the software would have to be able to interpret that signal. This may or may not be possible depending on how much control you have over the software design.

I am still not sure what exactly you want to detect though. Is it anything over 0.2vac or something else?
 
Last edited:

Thread Starter

anishkgt

Joined Mar 21, 2017
549
That was something i had in mind at first but then persuaded by the internet and people to go this way. I've also come across one that LT has with the LT1078. That opamp is a bit too costly. Should i stick with that or are there anything cheaper.

I was thinking of using the half-wave precision rectifier rather than the full-wave. Would it have any interference with its a dual package or should i go with two single packages ?

Then what about the mains voltage when it the LOAD would be on ? which was someting i had trouble solving.
 

MrAl

Joined Jun 17, 2014
13,716
That was something i had in mind at first but then persuaded by the internet and people to go this way. I've also come across one that LT has with the LT1078. That opamp is a bit too costly. Should i stick with that or are there anything cheaper.

I was thinking of using the half-wave precision rectifier rather than the full-wave. Would it have any interference with its a dual package or should i go with two single packages ?
Hello,

I would think a dual package would have low enough crosstalk so that the signals remain independent. I dont think you need an expensive op amp for this. Is this a production item or a one off project?

You may want to go back and read my previous post again however as i added to it while you were replying to it so there is more content there now :)
 

Thread Starter

anishkgt

Joined Mar 21, 2017
549
thank that does make sense, was used to following datasheets and moreover new to opamps lead me to not think. :) So wouldn't it affect the CMRR or anything else sensitive to the opamp ? and is it ok to have just an RC filter before this and nothing else to protect the opamp ?

I am still not sure what exactly you want to detect though. Is it anything over 0.2vac or something else?
I wish to detect the voltage change from 1.2vac to .2vac, all these when the LOAD is OFF. nothing over 1.2vac but lower it.
 

MrAl

Joined Jun 17, 2014
13,716
thank that does make sense, was used to following datasheets and moreover new to opamps lead me to not think. :) So wouldn't it affect the CMRR or anything else sensitive to the opamp ? and is it ok to have just an RC filter before this and nothing else to protect the opamp ?



I wish to detect the voltage change from 1.2vac to .2vac, all these when the LOAD is OFF. nothing over 1.2vac but lower it.
Hi,

Ok thanks.

Of course the op amp can be over voltaged if you apply a voltage higher than the input can take, or lower if the op amp does not have an internal protection diode, but you could supply your own Schottkey protection diode to clamp negative excursions and that will take care of that.

The diode is best placed downstream of the op amp. Give me a minute to draw a diagram. Oh wait, your diagram has D8 which can be a Schottkey diode to clamp negative inputs. So the new circuit would have that diode too.

Also, why so many different grounds?
 
Top