EEVblog Electronics Community Forum

Electronics => Projects, Designs, and Technical Stuff => Topic started by: okw on December 23, 2021, 08:27:27 pm

Title: Earth ground referenced comparator
Post by: okw 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.?
Title: Re: Earth ground referenced comparator
Post by: Kim Christensen on December 23, 2021, 08:54:28 pm
Redo your schematic... Maybe use a while background instead? What you posted is virtually unreadable.
Title: Re: Earth ground referenced comparator
Post by: Benta 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".
Title: Re: Earth ground referenced comparator
Post by: okw 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.
Title: Re: Earth ground referenced comparator
Post by: viperidae 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.
Title: Re: Earth ground referenced comparator
Post by: Kim Christensen 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.
Title: Re: Earth ground referenced comparator
Post by: okw 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?
Title: Re: Earth ground referenced comparator
Post by: Kim Christensen 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.
Title: Re: Earth ground referenced comparator
Post by: okw 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.
Title: Re: Earth ground referenced comparator
Post by: okw 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?
Title: Re: Earth ground referenced comparator
Post by: Kim Christensen 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:
Title: Re: Earth ground referenced comparator
Post by: okw 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?
Title: Re: Earth ground referenced comparator
Post by: Kim Christensen 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.

Title: Re: Earth ground referenced comparator
Post by: okw 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?
Title: Re: Earth ground referenced comparator
Post by: fourfathom on January 14, 2022, 08:22:55 pm
Comments:
Title: Re: Earth ground referenced comparator
Post by: okw 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.
Title: Re: Earth ground referenced comparator
Post by: fourfathom 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.
Title: Re: Earth ground referenced comparator
Post by: okw 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?
Title: Re: Earth ground referenced comparator
Post by: fourfathom on January 15, 2022, 03:43:18 pm
I think you are making progress.  Some more comments:
Title: Re: Earth ground referenced comparator
Post by: okw 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 (https://www.aliexpress.com/item/4000588876625.html)
Would "upgrading" to one of these be better?
https://www.ebay.com/itm/122230400197 (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 (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.
Title: Re: Earth ground referenced comparator
Post by: Terry Bites 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.
Title: Re: Earth ground referenced comparator
Post by: fourfathom 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?
Title: Re: Earth ground referenced comparator
Post by: okw 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?
Title: Re: Earth ground referenced comparator
Post by: fourfathom 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. 


Title: Re: Earth ground referenced comparator
Post by: okw 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.
Title: Re: Earth ground referenced comparator
Post by: fourfathom on January 16, 2022, 04:36:00 am
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? ​

OK, I see the four legal states in the middle of your table.  Why do you show the four others that are impossible?  Trust me, that only confuses things.

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.

OK that's pretty simple.  Have you got resistance measurements at the proper fill level?  Pure (distilled) fresh water is actually a good insulator.  What do you know about the water you are working with?
Title: Re: Earth ground referenced comparator
Post by: fourfathom on January 16, 2022, 04:39:45 am
Hey, would anyone else like to weigh in here?  I don't want to steer okw wrong, or over-complicate things.  Trust me, I can take a little necessary criticism!
Title: Re: Earth ground referenced comparator
Post by: okw on January 16, 2022, 12:34:07 pm
OK that's pretty simple.  Have you got resistance measurements at the proper fill level?  Pure (distilled) fresh water is actually a good insulator.  What do you know about the water you are working with?
I measured the it at 3.5 - 4M. But that's with the same water sitting in the tank for a few weeks/months (stainless steel tank with a few copper pipes). It will probably be a bit higher when fresh water flows in. The intake is on the bottom, the outlet is on the top, so a lot of "old" water (with ions) will still be left and create a resistance. The fresh water will only slightly dilute the tank water. Newer tanks are stainless steel (negligible ion deposits), older models are copper (contributes with quite a lot of Cu2+ ions).
I also measured fresh water in a 1 liter jar, 7-9M. So it will definitely detect something, if my opamp resistors are tweaked good enough.
In Norway we have quite soft water (little ions) compared to other places in the world, so if I get the detector to work here, I'm sure it would work anywhere.
Title: Re: Earth ground referenced comparator
Post by: fourfathom on January 16, 2022, 04:19:35 pm
It would be nice to get an upper limit on the "water detected" sensor resistance.  If we assume it's 10M then with the bias resistors in your circuit the comparator (-) input shifts from 2.976V (dry) to 2.851V (wet).  Call this 100mV.  That's not a lot of swing and you are going to want 1% resistors to set the comparator voltages.  You will also probably want to increase the value of the bias resistors at the (+) input tp more closely match the resistance at the two inputs.  You also need to reduce the amount of hysteresis -- what you have is now about 0.2 Volts.  Perhaps increase R8 to 5M or so?

One way to increase the wet/dry voltage change is to increase the resistance of your sensor bias divider resistors, or add a third resistor as I had shown (scratched out) in my last circuit.  But this comes at the expense of more sensitivity to the comparator input offset voltage and input offset current.  I checked the existing circuit against the 358 specs and the effect of these factors was only about +/- 7mV, but when you increase the input resistances this effect also increases.  There are comparators available with much lower offset specs should this be an issue.

So this is in a water tank?  When it is filling there will be ripples, so the detector will initially see an oscillating high-resistance wet/dry/wet/dry condition until the level has risen enough for more immersion.  Wil this be a problem for your design?  I have experience with water tanks (I have lived in rural areas with wells), and the level detectors used for pump control are usually two-wire mechanical switches with perhaps 1/2 foot of mechanical hysteresis.  You really don't want to have high-frequency pump cycling.
Title: Re: Earth ground referenced comparator
Post by: okw on January 16, 2022, 10:49:23 pm
It's quite difficult to measure, as the readings jump up and down as i move the dmm probes in the water. Perhaps concentration of ions isn't uniform?
Yes, the high frequency pump cycling must be avoided at all costs. Wouldn't a wide hysteresis swing take care of that?
It has to be the current level probe design. This is a closed heated tank (<1.7bar and 130'C).

Besides tweaking the values. Would the latest circuit be sufficient and a good design for this? So I can go ahead and layout and produce a prototype. It's only a few bucks, but I don't wanna waste time and money, if something is wrong.
Title: Re: Earth ground referenced comparator
Post by: Kim Christensen on January 16, 2022, 11:05:00 pm
It's quite difficult to measure, as the readings jump up and down as i move the dmm probes in the water. Perhaps concentration of ions isn't uniform?

You need to measure it using the actual rod in the tank as it fills with water. DMM probes will be completely different.
Title: Re: Earth ground referenced comparator
Post by: fourfathom on January 17, 2022, 03:12:40 am
Can you run two wires to a pair of probes held apart a small distance by insulators?  One of the probes can be grounded.  That way you won't have to work with the resistance from the probe to the tank wall, but just between the two parallel probes which should be more repeatable.

As for hysteresis, you need a linear (or at least usefully monotonic) variation in sensor resistance as it becomes immersed.  I suspect you do have that and it would be very useful to know how the resistance varies as a function of immersion depth.  If halfway was (say) 10M and fully-immersed were 5M then we could work out an appropriate hysteresis range.  Again, using a parallel sensor arrangement might make the values more repeatable.

Title: Re: Earth ground referenced comparator
Post by: okw on January 17, 2022, 05:13:05 pm
Can you run two wires to a pair of probes held apart a small distance by insulators?  One of the probes can be grounded.  That way you won't have to work with the resistance from the probe to the tank wall, but just between the two parallel probes which should be more repeatable.

As for hysteresis, you need a linear (or at least usefully monotonic) variation in sensor resistance as it becomes immersed.  I suspect you do have that and it would be very useful to know how the resistance varies as a function of immersion depth.  If halfway was (say) 10M and fully-immersed were 5M then we could work out an appropriate hysteresis range.  Again, using a parallel sensor arrangement might make the values more repeatable.

I need to keep it exactly as is (tank is completely closed (except a few inlets and outlets). Earth grounded copper tank and a probe (insulated from the the mounting point of course).

I could of course hook up a data logger with a voltage divider and see how resistance varies during the water low/normal area.
Title: Re: Earth ground referenced comparator
Post by: fourfathom on January 17, 2022, 06:08:47 pm
I need to keep it exactly as is (tank is completely closed (except a few inlets and outlets). Earth grounded copper tank and a probe (insulated from the the mounting point of course).

I could of course hook up a data logger with a voltage divider and see how resistance varies during the water low/normal area.

It would be extremely helpful to get this resistance vs level data.  With that we can optimize the sensor interface and the amount of hysteresis.

You have mentioned using this design in more than one place.  Will the tank dimensions be the same?  This will most likely affect the probe-to-tank resistance.
Title: Re: Earth ground referenced comparator
Post by: okw on January 17, 2022, 06:24:10 pm
It would be extremely helpful to get this resistance vs level data.  With that we can optimize the sensor interface and the amount of hysteresis.
I'll try to see how fast I can get to this.

You have mentioned using this design in more than one place.  Will the tank dimensions be the same?  This will most likely affect the probe-to-tank resistance.
Yes, same dimensions and geometry.
Title: Re: Earth ground referenced comparator
Post by: fourfathom on January 17, 2022, 06:34:31 pm
Yes, same dimensions and geometry.
Great news!  This helps a lot. 
The only other variable will be the water conductivity which will determine the full-immersion resistance, and the effective hysteresis vs level change.  Perhaps the variation will be minor...
Title: Re: Earth ground referenced comparator
Post by: okw on January 17, 2022, 07:32:07 pm
Is there an easy way to add a delay on both ON and OFF? I've seen this same principle (one with LM324 and another with both LM324 + LM358), but they didn't engage the pump until 2-3 seconds after plugging in. Maybe there is possible to add some rise/fall delay on the output? In addition to the hysteresis?

By the way, will the lm358 (and the rest) with the current protection survive if the heating element cracks and starts leaking AC current via water to ground? This happens very often (reason no1 for heating elements die, reason no2 is of course burnt heating wire). The GFCI should trip, but many older setups don't have it, or not tripping at low enough currents.
Title: Re: Earth ground referenced comparator
Post by: fourfathom on January 17, 2022, 07:53:58 pm
Is there an easy way to add a delay on both ON and OFF? I've seen this same principle (one with LM324 and another with both LM324 + LM358), but they didn't engage the pump until 2-3 seconds after plugging in. Maybe there is possible to add some rise/fall delay on the output? In addition to the hysteresis?

By the way, will the lm358 (and the rest) with the current protection survive if the heating element cracks and starts leaking AC current via water to ground? This happens very often (reason no1 for heating elements die, reason no2 is of course burnt heating wire). The GFCI should trip, but many older setups don't have it, or not tripping at low enough currents.

As long as you don't need much timing precision a delay could be as simple as putting a series resistor then a capacitor to ground at the comparator output.  You are using cmos NOR gates so the RC values should be reasonable.  I think you will want to use schmitt-trigger-input NOR gates in that case, but these are available.  You will probably need  to add a diode and maybe a resistor to ensure proper power-up and power-down behavior. (Are you sure you don't want to use an 8-pin PIC for all this?  It would get rid of most of your components and cost less.)

240VAC leaking into the water?  That's nasty.  If the tank is your ground reference then the only real problem is on the sensor input.  The protection circuit I showed you can handle moderate transients, but with high-voltage and current more than (say) 10 mA then first the diodes will blow, followed by the 358.  Or more likely, the input protection diodes will pump up the +5V voltage to a couple hundred volts and zap every active device on the board.  Once we get a better handle on the sensor resistance range we can probably modify the input circuit slightly to make it fairly bulletproof in the broken-heater scenario -- probably by putting a series resistor in line before the diodes and perhaps using higher-current diodes and some sort of clamp (Zener or equivalent).

So how are you switching power to the pump and heater?  This is important when we are so concerned about grounding and isolation and power-faults.  All you've shown us is what looks like an alarm-type beeper.
Title: Re: Earth ground referenced comparator
Post by: okw on January 17, 2022, 08:34:56 pm
A PIC would be easier and cheaper, but I'm treating this as a project for learning - and I've learned a lot so far. I do software dev all day, so it's fun doing this all old-school.

This is my relay and triac circuit. Not everything is calculated yet.
Title: Re: Earth ground referenced comparator
Post by: fourfathom on January 17, 2022, 09:08:22 pm
OK, we can look at the protection circuitry once we have better sensor resistance data. 

About your relay and triac, I'm glad to see the optoisolators!  But take a look at OK2 pin 6.  You need to connect the opto collector instead.  You might want to put a bypass cap on pin 6 but check the device specs -- I believe the base is usually left floating.  For that matter, the entire OK2 driver circuit looks "interesting".  Why so complex?  Why the reverse-diode across the opto input?  You are only going to get less than 0.4 mA of opto drive current through Q1, and that's probably not enough.  Why not just drive the opto via a resistor from your logic?

And Q2 needs some protection from the relay-off flyback spike.  There are various ways to do this, all pretty simple.

I haven't reviewed the design in total, these items just jumped out at me.
Title: Re: Earth ground referenced comparator
Post by: okw on January 17, 2022, 09:56:09 pm
Of course, my bad. Pin 5, not pin 6. And I added a 100nF between pin 4 and 6. Seems it would add some noise immunity.
The protection diode should be on the relay, not triac optocoupler. A hasty mistake.
But yeah, the complex input was probably too much. I removed everything and driving it through a resistor now.
Title: Re: Earth ground referenced comparator
Post by: Kim Christensen on January 18, 2022, 12:18:59 am
I don't see the point of OK1 since the relay coil is also connected to the +5V line. Just drive Q2 directly via R13. Yea, and a diode across K1's coil (Cathode to +5V) is a good idea.
R12 makes no sense to me. Connect the emitter of Q1 to ground, or just drive the OK2 directly like you did with OK1.
Title: Re: Earth ground referenced comparator
Post by: fourfathom on January 18, 2022, 12:35:09 am
I don't see the point of OK1 since the relay coil is also connected to the +5V line. Just drive Q2 directly via R13. Yea, and a diode across K1's coil (Cathode to +5V) is a good idea.
R12 makes no sense to me. Connect the emitter of Q1 to ground, or just drive the OK2 directly like you did with OK1.

Yes.  I agree with all of this.  I think okw is now driving opto OK2 directly as you suggest. 

And yes, the opto for the K1 circuit seems redundant -- the relay will provide the necessary isolation.  Since you need the transistor Q2 to handle the 71 mA relay current, just drive the transistor from the logic.  The 1K base resistor should probably be dropped down to perhaps 560 Ohms though. I think the cmos logic can source that 7 mA base current.
Title: Re: Earth ground referenced comparator
Post by: okw on January 18, 2022, 12:55:35 am
The relay optocoupler was there to provide AC noise protection, especially since it's switching high loads (1400w heating element). This is resistive so it probably won't introduce so much noise(?). But the relay will switch only at the transition pump off - heating on. When heating is on, an external thermostat (in series with the relay) will switch on/off separately.
Title: Re: Earth ground referenced comparator
Post by: okw on January 20, 2022, 12:37:11 am
Any input on this?
Title: Re: Earth ground referenced comparator
Post by: fourfathom on January 20, 2022, 01:42:12 am
Any input on this?

Not really. 

I just don't know how much noise is transferred into the relay coil when the contacts are switching high voltage / power, so the following is all guesswork:  If it's just a current spike I would think that the flyback protection would suffice (and perhaps a second diode to ground if the spike went negative).  If it's a common-mode surge that somehow forces ground-current than you're going to need more than an opto since the relay and drive transistor are still connected to +5 and ground -- but your power supply isolation should prevent that.
Title: Re: Earth ground referenced comparator
Post by: okw on June 05, 2023, 11:52:58 am
Finally I had time to realize this into a PCB.
Sadly the 555 timer doesn't start countdown unless the 555 trigger (signal !AUTO_FILL_ON) goes high again.
But !AUTO_FILL_ON is dependent on water level sensor and will stay low until water level is satisfactory.
I see some designs adding a pull up and a capacitor to make it an edge-trigger, but I can't manipulate the !AUTO_FILL_ON as this is part of the NOR gate to compare !AUTO_FILL_ON and PUMP_ENGAGE.
When both are low (pump is running but water level is still low after ~60 sec), it gives a buzzer alarm + pump stops.
Any idea how to fix the 555 circuit?
Title: Re: Earth ground referenced comparator
Post by: Kim Christensen on June 05, 2023, 03:33:51 pm
Since this is an old thread, was this the circuit you built? Or were there additional changes?

(https://www.eevblog.com/forum/projects/earth-ground-referenced-comparator/?action=dlattach;attach=1381630)
Title: Re: Earth ground referenced comparator
Post by: okw on June 05, 2023, 05:06:30 pm
Somewhat modified, but yes more or less.
Except R8 is connected to the IC1A output (instead of between the NOR gates).
Also, I put a resistor R10 between IC1A output and IC4D input, and a capacitor (not assembled) between this resistor / IC4D input and ground.
R10 is now 0R, but was advised 8.2k for wider hysteresis band, have to experiment how much I need.
All opamp/NOR gate inputs has been properly grounded / etc. for more stable operation.

I didn't modify the 555 timer in the attachment, this is the PCB i received.
Title: Re: Earth ground referenced comparator
Post by: Kim Christensen on June 05, 2023, 10:19:55 pm
Finally I had time to realize this into a PCB.
Sadly the 555 timer doesn't start countdown unless the 555 trigger (signal !AUTO_FILL_ON) goes high again.
But !AUTO_FILL_ON is dependent on water level sensor and will stay low until water level is satisfactory.
I see some designs adding a pull up and a capacitor to make it an edge-trigger, but I can't manipulate the !AUTO_FILL_ON as this is part of the NOR gate to compare !AUTO_FILL_ON and PUMP_ENGAGE.
When both are low (pump is running but water level is still low after ~60 sec), it gives a buzzer alarm + pump stops.
Any idea how to fix the 555 circuit?
I've edited your diagram because the Net-Names were not helping me follow the circuit. I'll have to look at this again a bit later, but my edits may help others:
Title: Re: Earth ground referenced comparator
Post by: okw on June 05, 2023, 10:39:05 pm
It's easier to follow in Eagle, than on a separate image :)
R24 is not mounted, just a backup solution if timeout and alarm isn't needed (and 555 timer isn't mounted).
Title: Re: Earth ground referenced comparator
Post by: okw on June 12, 2023, 12:57:34 pm
Finally I had time to realize this into a PCB.
Sadly the 555 timer doesn't start countdown unless the 555 trigger (signal !AUTO_FILL_ON) goes high again.
But !AUTO_FILL_ON is dependent on water level sensor and will stay low until water level is satisfactory.
I see some designs adding a pull up and a capacitor to make it an edge-trigger, but I can't manipulate the !AUTO_FILL_ON as this is part of the NOR gate to compare !AUTO_FILL_ON and PUMP_ENGAGE.
When both are low (pump is running but water level is still low after ~60 sec), it gives a buzzer alarm + pump stops.
Any idea how to fix the 555 circuit?
I've edited your diagram because the Net-Names were not helping me follow the circuit. I'll have to look at this again a bit later, but my edits may help others:

Did you have a chance to check it out?
Title: Re: Earth ground referenced comparator
Post by: Kim Christensen on June 12, 2023, 10:47:30 pm
Finally I had time to realize this into a PCB.
Sadly the 555 timer doesn't start countdown unless the 555 trigger (signal !AUTO_FILL_ON) goes high again.
But !AUTO_FILL_ON is dependent on water level sensor and will stay low until water level is satisfactory.
I see some designs adding a pull up and a capacitor to make it an edge-trigger, but I can't manipulate the !AUTO_FILL_ON as this is part of the NOR gate to compare !AUTO_FILL_ON and PUMP_ENGAGE.
When both are low (pump is running but water level is still low after ~60 sec), it gives a buzzer alarm + pump stops.
Any idea how to fix the 555 circuit?

I think this would be the easiest way to fix the problem. Does the PCB layout prevent you from inserting at small capacitor between the "!AUTO_FILL_ON" wiring and pin 2 of the 555 by cutting the trace, and also adding a pullup between pins 2 & 4 of the 555? Or you could bend pin 2 of the 555 up before soldering it to the PCB... It wouldn't be very pretty though.

It's too bad that the power pins on a 555 are opposite that of a PIC12F675 (Or similar 8 pin MCU) because it would be trivial to program one to replace the 555. Hmmmm... Is the PCB set up for a through-hole 555? If so, you could mount a PIC12F675 from the solder side and then the power pins would be the correct polarity. But this would require MCU programming, which might be an issue if you don't have the tools/skills for that.


Title: Re: Earth ground referenced comparator
Post by: okw on June 12, 2023, 11:28:56 pm
I think this would be the easiest way to fix the problem. Does the PCB layout prevent you from inserting at small capacitor between the "!AUTO_FILL_ON" wiring and pin 2 of the 555 by cutting the trace, and also adding a pullup between pins 2 & 4 of the 555? Or you could bend pin 2 of the 555 up before soldering it to the PCB... It wouldn't be very pretty though.

It's too bad that the power pins on a 555 are opposite that of a PIC12F675 (Or similar 8 pin MCU) because it would be trivial to program one to replace the 555. Hmmmm... Is the PCB set up for a through-hole 555? If so, you could mount a PIC12F675 from the solder side and then the power pins would be the correct polarity. But this would require MCU programming, which might be an issue if you don't have the tools/skills for that.

Yes, I can do both the cap and pullup. So I'll try that tomorrow and see how it goes.

Actually, I'm avoiding MCUs this time as I've programmed my fair share. I flet it was time to go old-school and learn a bit new (old) stuff.
Title: Re: Earth ground referenced comparator
Post by: okw on May 03, 2024, 11:12:49 am
A follow up on this. I finally managed to redesign and test the circuit. I decided to temporarily remove the 555 time-out alarm as the trigger needs to be toggled to start counting, not just stay low. And it's not a critical feature now. I could have removed the 7402 inverter and pulled the optocoupler (PUMP_ENGAGE) and relay signal (!AUTO_FILL_ON) directly after R9, but I left the inverter in place, as I hope to get the timer working later.
However, I see 426mV on the optocoupler when it should be 0V. On high, I see 1.15V which is the forward voltage of the LED, so all good. I'm not sure if this will cause any issues with the optocoupler.
I removed R19, and the optocoupler input is 0mV. What's the trick here? If there is a simple mod for the existing PCB it would be good.
And a more fundamental redesign for my next revision?
Also does the relay transistor need a pull-down?
Title: Re: Earth ground referenced comparator
Post by: Kim Christensen on May 03, 2024, 03:39:46 pm
However, I see 426mV on the optocoupler when it should be 0V.

I assume you mean 426mV across pins 1&2 of the optocoupler. If so, this shouldn't be a problem since 426mV is not enough to light the LED in the opto and turn its TRIAC on.

Quote
On high, I see 1.15V which is the forward voltage of the LED, so all good. I'm not sure if this will cause any issues with the optocoupler.
I removed R19, and the optocoupler input is 0mV. What's the trick here? If there is a simple mod for the existing PCB it would be good.

The reason for the 426mV across pins 1&2 of the optocoupler is because R19/Q1 is loading the output of IC2B (pin4) when it goes high.
This means pin-4 only goes up to 4.574V (5V - 426mV assuming a 5v supply)

Like I said, it's not really a problem, but if you changed Q1 to a MOSFET and eliminated R20 this "problem" would go away.
Another option would be to increase R19 to 1.2k (assuming a worst case beta for Q1 of 20) which would reduce the current draw from IC2B. (pin4). This would reduce the voltage to something lower than 426mV.

Quote
Also does the relay transistor need a pull-down?

If the output of IC2B (pin4) doesn't go lower than apx 700mV when it's low, then Q1 will not turn off. R19 & R20 can form a divider so that the voltage on Q1's base is less than 350mV when pin-4 goes low.
Title: Re: Earth ground referenced comparator
Post by: okw on May 03, 2024, 04:26:34 pm
Thanks :)

If the output of IC2B (pin4) doesn't go lower than apx 700mV when it's low, then Q1 will not turn off. R19 & R20 can form a divider so that the voltage on Q1's base is less than 350mV when pin-4 goes low.

If I replace Q1 with either 2N7002LT or BSS138LT1G, what should I be considering? I guess 1k base resistor is OK? And drop R20 (or 100k)?

Is MOC3083 (zero-cross) and Z0103MN a suitable choice for a 240V 48W vibration pump (on max 1-2 min worst case, usually 3-10 sec every 30 min)?
Regarding the values for snubber (R25/C2), gate bleeder (R21) and backlash (R23), I just used what was in the datasheet, but that was for resistive loads. Any enhancements here?
The datasheet says R25 (39R) should be increased to 360R with highly inductive loads. I don't know if mine is highly or slightly.
Title: Re: Earth ground referenced comparator
Post by: Kim Christensen on May 03, 2024, 07:45:29 pm
If I replace Q1 with either 2N7002LT or BSS138LT1G, what should I be considering? I guess 1k base resistor is OK? And drop R20 (or 100k)?

The BSS138LT1G is a better choice due to it's lower gate voltage turn-on requirements. You can safely leave R19 at 560 \$\Omega\$  and eliminate R20.

I'll leave the TRIAC questions for others to answer...
Title: Re: Earth ground referenced comparator
Post by: okw on May 06, 2024, 01:16:52 pm
You still need protection on that LEVEL_SENSOR input.  I am attaching a possible circuit.

I have a question. I've played around with the circuit you attached. I put a potentiometer in place of the inverting input pull-up and removed the feedback resistor. Found out at 17.1k pull-up on the inverting input it switched when water level was perfect. So I'll put in a 18k resistor (no need for perfection). Then a potentiometer in place of the feedback resistor and 1M seems to give an OK hysteresis. I also added a 100k/10uF RC delay on the output (after the feedback resistor).
Anything to consider when having such a gap (18k/1M) on the divider?

I also put a 1206 0R resistor in series before the 1k you drew up, and a 32V zener to ground. And a 1206 0R resistor between earth ground and logic ground. Are those reasonable for added input protection?
Given the worst case scenario (rupturing heating element, momentarily 240V into the water (earth ground) before the 20-25mA ground fault circuit breaker kicks in.