Author Topic: Earth ground referenced comparator  (Read 10076 times)

0 Members and 1 Guest are viewing this topic.

Offline okwTopic starter

  • Frequent Contributor
  • **
  • Posts: 370
  • Country: no
Earth ground referenced comparator
« on: December 23, 2021, 08:27:27 pm »
Hello!
I have made a water level sensor circuit which senses contact with water between a probe and a earth grounded (3rd pin of 110/220V outlet) metal tank. This is my reference to the comparator. I connected the earth ground to the non-inverting input of the comparator, but made the mistake of not joining the earth ground and signal ground. Should I join these two with an inductor (or something) to create a common reference? Any insurances the comparator or other chips won't die if there is a earth ground problem (for example a heating element with leakage to earth ground - water between the heating element poles and ground could introduce microscopic currents to earth ground, without breaking the ELCB)? I included hysteresis, so the auto-fill pump won't engage on and off too much in the threshold area. Does this look correct?
(I also made the error of connecting earth ground instead of signal ground to comparator GND (pin 4), but this will be corrected).

In short:
-Should both IC2 and T be grounded by signal ground (not earth ground)?
-Should earth ground and signal ground be joined by an inductor, if yes, which value?
-Any other modifications, to increase redundancy/stability/etc.?
« Last Edit: December 23, 2021, 09:28:57 pm by okw »
 

Offline Kim Christensen

  • Super Contributor
  • ***
  • Posts: 1819
  • Country: ca
Re: Earth ground referenced comparator
« Reply #1 on: December 23, 2021, 08:54:28 pm »
Redo your schematic... Maybe use a while background instead? What you posted is virtually unreadable.
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 6550
  • Country: de
Re: Earth ground referenced comparator
« Reply #2 on: December 23, 2021, 09:08:34 pm »
^^^ This.

The "Dark Theme" is not very good.

Also, try to be specific about what you mean by "Earth", "Ground" and "Ground Earth".
 

Offline okwTopic starter

  • Frequent Contributor
  • **
  • Posts: 370
  • Country: no
Re: Earth ground referenced comparator
« Reply #3 on: December 23, 2021, 09:31:04 pm »
I can't really see how it's unreadable, unless you're on a phone/tablet. Pressing the link opens the schematic in full size and it quite readable. However I included a white background.
Dark theme is a blessing for the eyes after many hours.

Earth ground is the 3rd pin of a 110/220V. Signal ground and ground would the GND pins of most chips I use (LM358, NE555, etc.) for this project.
I modified the original post with more consistent use of earth/signal ground.
 

Offline viperidae

  • Frequent Contributor
  • **
  • Posts: 308
  • Country: nz
Re: Earth ground referenced comparator
« Reply #4 on: December 23, 2021, 09:39:31 pm »
Unless I'm missing something, this doesn't do anything?
The input signal is first rectified by the diode, then AC coupled with a capacitor. The input can only apply a positive voltage to one side of the capacitor and the other side is pulled high. Current is only going to flow for a brief period when the input goes higher than your supply rail.
That would result in the opamp inverting input going from 5v to above 5v then back down to 5v.
 

Offline Kim Christensen

  • Super Contributor
  • ***
  • Posts: 1819
  • Country: ca
Re: Earth ground referenced comparator
« Reply #5 on: December 23, 2021, 09:58:38 pm »
I would eliminate D2 and C3 as mentioned by viperidae.
Next, you do not have to worry about "different grounds" if you power the entire circuit with an isolated power supply like a wallwart which is what you should be doing anyway.
 

Offline okwTopic starter

  • Frequent Contributor
  • **
  • Posts: 370
  • Country: no
Re: Earth ground referenced comparator
« Reply #6 on: December 23, 2021, 11:10:18 pm »
I would eliminate D2 and C3 as mentioned by viperidae.
Next, you do not have to worry about "different grounds" if you power the entire circuit with an isolated power supply like a wallwart which is what you should be doing anyway.

I can't use a wall wart. Since it will be a drop in replacement of an exiting pcb, I have hard specs. Pins: 250V power (line + neutral + earth GND), sensor probe in, pump power out (L), heating element power out (L).
Pump turns on and heating off when water level is too low. And vice versa.

I'll remove D2 and C3.
Any suggestions of how to make this circuit work with hysteresis? And which values to tweak to adjust the hysteresis?
 

Offline Kim Christensen

  • Super Contributor
  • ***
  • Posts: 1819
  • Country: ca
Re: Earth ground referenced comparator
« Reply #7 on: December 23, 2021, 11:41:59 pm »
Quote
I can't use a wall wart. Since it will be a drop in replacement of an exiting pcb, I have hard specs.

Well, then you should put a small transformer on the PCB that steps down the 250VAC and also provides galvanic isolation. The secondary voltage will depend on what type of relay (mechanical or solid state) you choose to switch the power for the pump and heater.
« Last Edit: December 23, 2021, 11:44:37 pm by Kim Christensen »
 

Offline okwTopic starter

  • Frequent Contributor
  • **
  • Posts: 370
  • Country: no
Re: Earth ground referenced comparator
« Reply #8 on: December 23, 2021, 11:53:13 pm »
It's already in place :) Along with triacs and relay for pump and heating elements, a 555 timer for timeout unless the tank fills within a specified amount of time.
I didn't post the full schematic, as some of it is proprietary. It has a transformer isolated 5V supply.
 

Offline okwTopic starter

  • Frequent Contributor
  • **
  • Posts: 370
  • Country: no
Re: Earth ground referenced comparator
« Reply #9 on: January 14, 2022, 05:48:58 pm »
I've updated the schematics and included everything, except the pump and heater relay circuits (as they are quite easy).

Any help to get this working?
 

Offline Kim Christensen

  • Super Contributor
  • ***
  • Posts: 1819
  • Country: ca
Re: Earth ground referenced comparator
« Reply #10 on: January 14, 2022, 07:05:22 pm »
How much hysteresis are you expecting from the LM358 circuit? You'll only have around 61mV of hysteresis because the output (pin 1) of the Lm358 is connected directly to the base of T2 limiting the voltage swing there to 0.7V. Plus, the LM358 will be in current limiting mode when pin 1 goes "high". You really should have a resistor in series with T2's base to limit the current and allow LM358 pin1 a wider swing:
 

Offline okwTopic starter

  • Frequent Contributor
  • **
  • Posts: 370
  • Country: no
Re: Earth ground referenced comparator
« Reply #11 on: January 14, 2022, 07:12:21 pm »
I'm not sure how to calculate each resistor value, so it based it on a design I found online, but for a slightly different application.
About the swing, I'm not sure how much is needed, I have to experiment with it. What would you say is good values for starting off? Then which values should I tweak?
 

Offline Kim Christensen

  • Super Contributor
  • ***
  • Posts: 1819
  • Country: ca
Re: Earth ground referenced comparator
« Reply #12 on: January 14, 2022, 07:41:44 pm »
You need to know how much "noise" (voltage instability) there will be on the LEVEL_SENSOR/5.3C input in a worst case scenario. Then you'd make sure that your hysteresis is greater than that by a reasonable margin. Also, you wouldn't want to make the hysteresis so high that it doesn't switch reliably. Once you know the hysteresis required and the output swing of the LM358 while driving T2 via the 8.2K, then you can choose R8's value to set the hysteresis.

 

Offline okwTopic starter

  • Frequent Contributor
  • **
  • Posts: 370
  • Country: no
Re: Earth ground referenced comparator
« Reply #13 on: January 14, 2022, 07:51:01 pm »
Excellent. Thanks.
And the schematic I supplied + 8.2k base resistor should work fine?
About connecting earth_gnd and signal_gnd. What inductor should I use?
 

Offline fourfathom

  • Super Contributor
  • ***
  • Posts: 2042
  • Country: us
Re: Earth ground referenced comparator
« Reply #14 on: January 14, 2022, 08:22:55 pm »
Comments:
  • the 555 output connected to "TIMEOUT" is a totem-pole design, and will force the LM358 "+" input either high or low.  I assume the intent is to force the output ON or OFF, but instead it's going to prevent the comparator from working as you intend. Perhaps drive a transistor with the 555 output pin (through a base resistor) and connect the collector to the 358 (+) pin.  You will have to deal with the logic inversion caused by the transistor.
  • Once you fix this, your comparator will have hysteresis, provided by R8.
  • The LM358 output is connected directly to the transistor base.  I suppose this will work, but the output isn't exactly designed for this.  It will drive perhaps 50 mA into the base.  The 358 output capable of continuous short-circuit, but that's a lot of current into the transistor base (I can't find a spec for the absolute maximum base current for a 2N3904).  You should add a resistor between the 358 and the transistor.
  • The LM358 is an opamp, not a comparator.  It will work as one, though, but with issues that probably won't matter in this design.
  • I would really put some input protection on the LEVEL_SENSOR and EARTH_GND inputs.  Diode clamps, series resistors, and noise-filtering capacitors are likely essential.
  • Your original dark-mode schematic was virtually unreadable to me on my huge monitor.  This may be because I have red/green color vision issues (for me it's extremely hard to see small red traces on a black background).  A pretty large percentage of men have this type of color vision problem.  Go for high-contrast colors.
We'll search out every place a sick, twisted, solitary misfit might run to! -- I'll start with Radio Shack.
 

Offline okwTopic starter

  • Frequent Contributor
  • **
  • Posts: 370
  • Country: no
Re: Earth ground referenced comparator
« Reply #15 on: January 14, 2022, 08:37:22 pm »
Comments:
  • the 555 output connected to "TIMEOUT" is a totem-pole design, and will force the LM358 "+" input either high or low.  I assume the intent is to force the output ON or OFF, but instead it's going to prevent the comparator from working as you intend. Perhaps drive a transistor with the 555 output pin (through a base resistor) and connect the collector to the 358 (+) pin.  You will have to deal with the logic inversion caused by the transistor.
  • Once you fix this, your comparator will have hysteresis, provided by R8.
  • The LM358 output is connected directly to the transistor base.  I suppose this will work, but the output isn't exactly designed for this.  It will drive perhaps 50 mA into the base.  The 358 output capable of continuous short-circuit, but that's a lot of current into the transistor base (I can't find a spec for the absolute maximum base current for a 2N3904).  You should add a resistor between the 358 and the transistor.
  • The LM358 is an opamp, not a comparator.  It will work as one, though, but with issues that probably won't matter in this design.
  • I would really put some input protection on the LEVEL_SENSOR and EARTH_GND inputs.  Diode clamps, series resistors, and noise-filtering capacitors are likely essential.
  • Your original dark-mode schematic was virtually unreadable to me on my huge monitor.  This may be because I have red/green color vision issues (for me it's extremely hard to see small red traces on a black background).  A pretty large percentage of men have this type of color vision problem.  Go for high-contrast colors.

Thanks for the feedback.
Oh yeah, I see it now. The timeout is there to ensure the pump wont be engaged forever (in the event of empty water reservoir tank, bent hose, seized pump, etc).
However, even if it worked it would be counterproductive, as this would automatically turn off the pump after the timeout period, which would turn on the heating element. That would burn the heating element (if the water tank is empty).
I need to work on the logic.
I have a lot of opamps/comparators. Which standard one would you recommend for this kind of application?

I originally had diodes and caps, but obviously wrong. How would I go about protecting the inputs?

Dark mode: I didn't know. Then I don't have problems with my eyes. It's so delightful with the dark theme. The white background really tires my eyes.
 

Offline fourfathom

  • Super Contributor
  • ***
  • Posts: 2042
  • Country: us
Re: Earth ground referenced comparator
« Reply #16 on: January 14, 2022, 09:21:35 pm »
I have a lot of opamps/comparators. Which standard one would you recommend for this kind of application?

The LM393 is the "generic comparator" equivalent to the LM358 "generic opamp".

But the more I consider it, I see some advantages to using the 358.  The 393 has an open-collector output so you would need a pull-up resistor at the output (which would supply the transistor base current).  The comparator output would then shut *off* the transistor, so you would have to rearrange your hysteresis and logic levels.

But the 358 and the 393 have identical input stages, so that's not a problem.  The 393 is faster as a comparator, but that's not going to matter in your case.  The 358 class AB output (drives both high and low) might be an advantage in your design.

One caveat:  the 358/393 inputs aren't designed to work all the way up to the positive supply rail (look at the specs).  You might want to have your sensor pull-up resistor connect to +3V (you can use a resistor divider on the +5 rail), or use a true "rail to rail" part.

And it might be time to back up a bit and reconsider the entire circuit.  Why is the transistor there in the first place?  You can drive the LVC inverters directly from the 358 output (or from the 393 comparator, with a pull-up resistor).  You can take the positive feedback (hysteresis) from the second inverter.  Of course you could replace everything following the comparator with a $1 8-pin PIC-style ucontroller.  Actually, you could even pull the comparator function into the PIC using the internal ADC.  But I assume you don't want to go that route

I've got to run now, but if nobody has shown you a good input protection circuit I will draw one up tonight or tomorrow.
« Last Edit: January 14, 2022, 09:51:11 pm by fourfathom »
We'll search out every place a sick, twisted, solitary misfit might run to! -- I'll start with Radio Shack.
 

Offline okwTopic starter

  • Frequent Contributor
  • **
  • Posts: 370
  • Country: no
Re: Earth ground referenced comparator
« Reply #17 on: January 15, 2022, 02:25:07 pm »
I backed up and reconsidered the circuit. I got rid of the transistor, as you pointed out. Added a voltage divider for 3V pull up for the level signal.
I also made the 555 timer control the pump/heating, instead of the Schmitt trigger. I also swapped the two output signals from the Schmitt triggers (since I removed the NPN).
I utilized the second opamp to control the timeout buzzer (active). Not sure if this will make the buzzer beep at random times in during the transitions low/ok water level?

I'm I on the right track?
 

Offline fourfathom

  • Super Contributor
  • ***
  • Posts: 2042
  • Country: us
Re: Earth ground referenced comparator
« Reply #18 on: January 15, 2022, 03:43:18 pm »
I think you are making progress.  Some more comments:
  • As was mentioned, the LM358 inputs aren't specified to accept inputs near the positive supply.  You are driving LM358 IC1B with AUTO_FILL_OFF which is a 0/5V logic level.  The other IC1B input signal is PUMP_ENGAGED.  If you are using a bipolar 555 this output may (or may not) be within acceptable range, but id you use a CMOS version of the 555 it will definitely be out of range.  More important, even if there weren't input range issues, what will be the output of the 358 when both inputs are high or low?  It's undefined and could be anything.  You really need a logic gate for this function.  Looking at the circuit, whenever AUTO_FILL_OFF is low the 555 output PUMP_ENGAGED will be held in reset. What is the logic you are trying to have here?  Perhaps you could change that inverter package to a quad NAND or NOR, and use those gated for your inverters and logic? 
  • Your comparator bias resistors look good.  You generally want to match the resistance into each input to compensate for input current, but on your case with wide voltage swings and big resistance changes on the sensor input this probably doesn't matter.  What are the characteristics of your sensor?  You are now feeding it from a much lower resistance (405K vs 1M previously).
  • Is your circuit completely isolated from any other connections to other equipment grounds, mains ground, or neutral (if you have one)?  It looks like it is, assuming your 240VAV/5V power module is fully isolated (and I supposed it has to be).  This is an important requirement for your circuit, and if so I don't think you need those EARTH_GROUND inductors -- I'm don't see the circumstances where they make a difference.  Perhaps someone else will want to comment on this?  (please???)
  • You still need protection on that LEVEL_SENSOR input.  I am attaching a possible circuit.
  • Sorry to harp about the schematic format, but the nets and text are still difficult to see or read.  A light green-on-white just doesn't have enough contrast.
We'll search out every place a sick, twisted, solitary misfit might run to! -- I'll start with Radio Shack.
 
The following users thanked this post: okw

Offline okwTopic starter

  • Frequent Contributor
  • **
  • Posts: 370
  • Country: no
Re: Earth ground referenced comparator
« Reply #19 on: January 15, 2022, 04:43:03 pm »
As was mentioned, the LM358 inputs aren't specified to accept inputs near the positive supply.  You are driving LM358 IC1B with AUTO_FILL_OFF which is a 0/5V logic level.  The other IC1B input signal is PUMP_ENGAGED.  If you are using a bipolar 555 this output may (or may not) be within acceptable range, but id you use a CMOS version of the 555 it will definitely be out of range.  More important, even if there weren't input range issues, what will be the output of the 358 when both inputs are high or low?  It's undefined and could be anything.  You really need a logic gate for this function.  Looking at the circuit, whenever AUTO_FILL_OFF is low the 555 output PUMP_ENGAGED will be held in reset. What is the logic you are trying to have here?  Perhaps you could change that inverter package to a quad NAND or NOR, and use those gated for your inverters and logic? 
My idea was to reset the 555 every time the level sensor sensed ok water level (even a brief second) to not issue a false alarm. But I suppose trigger pin going high (which happens when level is ok) will do the same thing.
I added the schmitt trigger to get a clean square wave from the opamp. Is it even needed?

Your comparator bias resistors look good.  You generally want to match the resistance into each input to compensate for input current, but on your case with wide voltage swings and big resistance changes on the sensor input this probably doesn't matter.  What are the characteristics of your sensor?  You are now feeding it from a much lower resistance (405K vs 1M previously).
0R. The sensor is a simple metal rod halfway into the tank (standard design for all these). Once the water level touches the rod, pump should stop.

Is your circuit completely isolated from any other connections to other equipment grounds, mains ground, or neutral (if you have one)?  It looks like it is, assuming your 240VAV/5V power module is fully isolated (and I supposed it has to be).  This is an important requirement for your circuit, and if so I don't think you need those EARTH_GROUND inductors -- I'm don't see the circumstances where they make a difference.  Perhaps someone else will want to comment on this?  (please???)
We have both IT (isolated ground / Isolée Terre) and TN (Terra Neutral) power distribution systems, depending on the age of the residence. Neutreal+Line+GND. In IT we measure approx 115V between L or N to GND. On TN we measure the full 230V between L or N to GND. The circuit should also work other places in the world (I'm not so familiar with other systems).
I'm using one of these cheap 5V 700mA modules from Aliexpress, I think it's a transformer isolated mains supply, possibly flyback topology:
https://www.aliexpress.com/item/4000588876625.html
Would "upgrading" to one of these be better?
https://www.ebay.com/itm/122230400197
Allthough the inside looks quite similar:
https://lygte-info.dk/review/Power%20Mains%20to%205V%200.6A%20Hi-Link%20HLK-PM01%20UK.html
I wanna keep cost down, but not at the expense of safety or compatibility with distribution systems.

You still need protection on that LEVEL_SENSOR input.  I am attaching a possible circuit.
Thanks, I've added this now.
« Last Edit: January 16, 2022, 03:05:11 am by okw »
 

Offline Terry Bites

  • Super Contributor
  • ***
  • Posts: 2672
  • Country: gb
  • Recovering Electrical Engineer
Re: Earth ground referenced comparator
« Reply #20 on: January 15, 2022, 05:19:34 pm »
The input common mode range for the comparator is Vcc-2. ie 3V max. Pin 2 pulled up to +5V. You'd be better to tie it to somwhere below 2.5V, 200mV under your upper threshold.
 

Offline fourfathom

  • Super Contributor
  • ***
  • Posts: 2042
  • Country: us
Re: Earth ground referenced comparator
« Reply #21 on: January 15, 2022, 06:44:33 pm »
The input common mode range for the comparator is Vcc-2. ie 3V max. Pin 2 pulled up to +5V. You'd be better to tie it to somwhere below 2.5V, 200mV under your upper threshold.

We've addressed this since the original posted circuit.  I haven't checked the divider voltages though but that's obviously trivial.
[I just checked]
The + input is at 2.5V +/- a small hysteresis (around 0.2V).
The - input is at 3V or less.
The first spec I saw for the LM358 showed that (Vcc - 2V) would be a safe upper limit on the inputs.  Have you seen a different spec?
We'll search out every place a sick, twisted, solitary misfit might run to! -- I'll start with Radio Shack.
 

Offline okwTopic starter

  • Frequent Contributor
  • **
  • Posts: 370
  • Country: no
Re: Earth ground referenced comparator
« Reply #22 on: January 16, 2022, 03:07:15 am »
I replaced the Schmitt with a quad NOR. I think that took care of both inverting and timeout alarm, with one gate to spare?
 

Offline fourfathom

  • Super Contributor
  • ***
  • Posts: 2042
  • Country: us
Re: Earth ground referenced comparator
« Reply #23 on: January 16, 2022, 03:56:56 am »
Your positive feedback (hysteresis) for the comparator should be taken from the comparator output, not the following inverter.  Sorry, I should have caught that in your previous version.  I had mentioned changing the feedback point when discussing other comparator options, but with the 358 now giving you a wide swing just take the feedback from the 358 output.  As it is now you have negative feedback and probably unstable at that.

You confused me with your 74AC02.  As you note, these are NOR gates, but your symbols are NAND.  Your logic diagram is also confusing (and probably wrong) since you show states with AUTO_FILL_ON and AUTO_FILL_OFF both being high or low.  As you note these two signals are complementary and will never have the same state.  And just looking at the two NOR inputs your state table is wrong.  NOR output is high only when both inputs are low.  All other input cases give a low output.  The NOR has only four states.

Re. transistor T1, when driving the gate from a regular CMOS logic gate you don't need R7.  It doesn't hurt but it's not required.  R6 is still needed, but with a 50mA load you want around 5mA into the base (the transistor spec sheet shows saturation curves for different base/collector current ratios).  Perhaps use 820 Ohms for R6.  The NOR gate can comfortably drive that.

Please tell us about your moisture sensor.  How much current can it "switch" and what is the leakage in the "dry" state?  Is this something like a spike in the ground?  Or is it some hard-on / hard-off sensor?  And you mentioned a heater -- do we need to know about this and how it will be controlled by your circuit?

I have by no means completely reviewed your design, so there may be more issues to come. 


« Last Edit: January 16, 2022, 03:58:32 am by fourfathom »
We'll search out every place a sick, twisted, solitary misfit might run to! -- I'll start with Radio Shack.
 

Offline okwTopic starter

  • Frequent Contributor
  • **
  • Posts: 370
  • Country: no
Re: Earth ground referenced comparator
« Reply #24 on: January 16, 2022, 04:19:33 am »
You confused me with your 74AC02.  As you note, these are NOR gates, but your symbols are NAND.  Your logic diagram is also confusing (and probably wrong) since you show states with AUTO_FILL_ON and AUTO_FILL_OFF both being high or low.  As you note these two signals are complementary and will never have the same state.  And just looking at the two NOR inputs your state table is wrong.  NOR output is high only when both inputs are low.  All other input cases give a low output.  The NOR has only four states.
In Eagle, the standard 74-library AND and OR almost look the same (only distinguished by the double lines going through the D). Very confusing.
Both ON/OFF being in the same state is "don't care = x". It will never happen. So the only four outcomes is marked 0 or 1 in the TIMEOUT_ALARM column. And i'm only interested in the 1 (which is timeout). With the NOR gate, I achieve that, right? ​

Re. transistor T1, when driving the gate from a regular CMOS logic gate you don't need R7.  It doesn't hurt but it's not required.  R6 is still needed, but with a 50mA load you want around 5mA into the base (the transistor spec sheet shows saturation curves for different base/collector current ratios).  Perhaps use 820 Ohms for R6.  The NOR gate can comfortably drive that.
Thanks. R7 removed.

Please tell us about your moisture sensor.  How much current can it "switch" and what is the leakage in the "dry" state?  Is this something like a spike in the ground?  Or is it some hard-on / hard-off sensor?  And you mentioned a heater -- do we need to know about this and how it will be controlled by your circuit?
It is simply a metal rod going from the top of the tank and down halfway into the tank (tank should never fill more than half), and the tank is grounded to mains earth.So I'm basically measuring the resistance between mains earth and the rod, with the water providing resistance when it hits the proper fill level.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf