News:

Let's find out together what makes a PIC Tick!

Main Menu

On the fly threshold calculations on ADC water Probes

Started by TimB, Dec 07, 2022, 08:41 AM

Previous topic - Next topic

TimB

Hi all

First of I know I keep bring this topic up but it is still giving me issues

I am monitoring 2 probes that sit in water to test for conductivity to detect the water. I drive a  Ground/Drive pin with 5v through a resistor then try and detect it with an ADC converter through another probe. There is pull down resistor on the detection probes.

The logic is
Probe 1 is in the water 99.9% of the time and I detect the change to no water then to water again eg water drops below the probe and then up past the probe
Probe 2 is out of the water 99.9% of the and I detect the water as it touches the probe.

My issue is that in tests if I hard code the set points in tap water its fine but then its used in very pure water and the levels dip massively.
Example
tap water ADC level change 250 with pure water 80

The other issue is that for various reasons some know and some not the threshold levels change. BUT there is always a big swing from water to no water

What I want is some system to calculate the threshold jump on the fly. Perhaps I keep a running average that is fairly large and if there is a swing of x % from that average the probe is classed as changed and I can apply that to detect the probe change either way

The issue I have though with that is there are situations on power up say where the probes may not be in water and where maybe they will be in water. The code will not know which and previous attempts to automate the threshold have lead to it failing during tests in the field.

Any thoughts on methods to sort this appreciated. Note a 3rd ref probe is not an option

david

Hi Tim,
It's always entertaining to hear of your projects.
As you have found out, the conductivity of water will change considerably so as you propose you will need to look for a percentage or fractional change in the average value rather than a fixed value change.
As for the start up issue - is there no way to let the system know the probe status?
I would still be considering looking at a high frequency AC system working on capacitance change rather than conductivity change.  The dielectric constant of water is about 80x that of air so you would pass little high frequency signal with the probes in the air.  You would only need a few pF to couple HF signal in to a high impedance and if you're generating the clocking signal (Fosc/4?) you can also synchronously detect it to read level if needed.

Cheers,
David

TimB



Thanks Dave

I determine what stage I'm in based on the probes. If you look at the image below, the vessel has 4 probes 2 are the drivers the top and bottom, they are blunt and designed to be in the water near to the detecting probes. The detection probes are pointy and as I hope you can see in the second pic as soon as the probe touches the water capillary action sucks the water up and give a better connection and adds hysteresis

In use water is filling the vessel and when the bottom probe is hit the system knows and the water continues to fill the vessel. When the top probe is hit it then empty's the cylinder. Due to the design I can determine the volume between the probes to 0.03ml repeatedly

If on start up there is no water in the system you have no way of knowing the so, If the vessel was full up to the top with water over both probes it would not know
In practice the probe readings vary. As the water level rises the bottom probe sees greater conductivity.
Due to the design the bottom probe has very good isolation between the drive and the detection, the top on the other hand has the possibility to be wetted that can lead to a path between the probe and its driver

I have 2 drives to improve isolation between the probes

I looked at high frequency AC but to reduce probe wear but that lead to issues as the AC had to be smoothed and the time constant for the RC was over the 100hz detection freq I required

I am interested in the capacitive system if it would be immune to tracking. eg if the probe touches a big(relative) block of water it could differentiate between that and that of small tracking.





probes.png


Probe in water.png 

 

trastikata

Quote from: TimB on Dec 07, 2022, 08:41 AMThe issue I have though with that is there are situations on power up say where the probes may not be in water and where maybe they will be in water. The code will not know which and previous attempts to automate the threshold have lead to it failing during tests in the field.

Hi TimB, question here - a probe can not detect "open" state, that's to say it will still be conducting when there's no water?


TimB


Trastikata

The probes have a residual ADC value through leakage with nothing connected. This might be value of 8 when in pure water on the bottom probe that switches at 30 but also it may be higher (200) due to splashing in the confided area the probe sits in if the water is tap water and that may switch at 250. There is water constantly entering near the probe which I do shield against but unless everything is coated in a superhydrophobic coating even a smear will allow voltage to creep through.

Using a fixed ADC value it WILL at some time track enough to make it think there is a water when there is not and vias versa

If I could have a fool proof system not using an ADC I would use it. The good point with an ADC is that you can set the threshold dynamically. This is what I'm trying to do

Tim

trastikata

I see. You said a third reference probe is not an option, how about an external sensor (light or ultrasonic) for rough estimation?

david

Hello Tim,
Obviously you have spent many months pondering and testing this system so know all about the quirks of the water behaviour.

With regards to the AC system - if the signal that has passed through the "water capacitor" is synchronously detected (you have the clock source) then the ripple should be small and amount to only the difference in successive readings - not unlike a sample and hold circuit.   If using say a 1MHz signal you can apply further filtering starting at 500kHz and even a first order filter would give you 60dB rejection of the carrier at 500Hz and allow 100Hz sampling rate. Crystal sets produce wideband audio off a MHz carrier..... 
What I don't know is how much of a capacitor you can form - plate area, geometry etc but I do know the dielectric change will be very dramatic between air and water and you should only need a couple of pF to couple HF into a high resistance.

Cheers,
David

ken_k

Hi Tim
You always seem to have challenging projects. I have a couple questions.
What are the probes made of?
Are you certain there are no galvanic issues with water and DC?
Does the inside surface of this device remain clean?
AC drive with insulated electrodes and synchronous detection are common place.
As an experiment maybe you could drive a probe with AC from your RF signal generator via a small high frequency isolating transformer and have a look at probe current with your oscilloscope?

ken_k

Hi Tim
This is something I never thought of doing.
https://www.analog.com/en/analog-dialogue/articles/liquid-level-sensing-using-cdcs.html
It is an interesting idea even it is of no value to you.
 
Regards Ken

TimB

Thanks all

With regards to capacitive. I have in the past built capacitive probes based of 2 long PCBs submerged in the water then used a Cap to digital converter like in the last post. Yes it does notice small water level changes but it is not stable. You can see a change but then it drifts. So much in fact that it way overrides any real movement.

So now I know what you are meaning by AC capacitance then sorry no that will not work. I was hoping that a freq could be set up that was effected by the body of the water. Almost like the probe was vibrating and dampened when it hits the water.

The Probes are stainless steel. The only other metal parts are stainless eg screws that act as the GrndDriver Also they have not been in the system very long so will not be an issue yet even if it were.

I have the ability to swap the polarity of the probes as the 4 are driven directly from Pic pins so I could drive the pointy probes with the 5V and detect with the other ones.

At this time I drive the bottom pin for 50ms then read the ADC, Then I turn the drive off to BProbeDrive and Turn on the TProbeDrive for 50ms then sample etc. This is to prevent cross tracking between the Bprobe and the TProbe.

At this time the vessel is a binary system eg I know when I have 100ml but not the flow between. There are many ways to skin this cat, I could add a flow meter to the system. The flow meter is not accurate enough and suffers from bio growth issues that effects the measurement. But with definitive probe conformation of my 100ml I could compensate for it and the flow meter will give me important feed back.

I would still need to solve the probe issue..

Another feed back I have is I detect the flow of bubbles and I suppose if I see bubbles/water flow past I can say Yes my Bprobe will be under water

I need to develop an algo to handle it all A state machine to determine what system to use to set the threshold

ken_k

Hi Tim
You certainly have a tough one!
I was impressed with the idea in the paper of using reference capacitive electrodes to compensate for changes in the water or for self calibration.

I will now mention an idea that may have no merit at all, the refractive index of air is 1.0003 (vacuum is 1) water is 1.333, glass is 1.5. If a laser was passed through a suitable container could the sideways deflection of the beam indicate water? BTW this is just a thought in reality the water container would have to be larger for this to work and air bubbles would upset operation.

The stainless steel electrodes seem satisfactory, a simple test may be to attach a cell to a DMM
and read the DC resistance for say 1/2 hour and then reverse the polarity on the test leads and see if the DC resistance changes.

I used to work on an angle sensor that had 3 electrodes in a sealed container such that tilting the glass device made the fluid level rise on one electrode and go down on the other the middle electrode was fed with a low frequency square wave via a capacitor, the output electrodes went to the measuring circuit, the AC was only to prevent the undesirable effects of DC, the unit measured degrees, minutes and seconds so it was quite accurate.

I know you said no extra electrodes the paper on capacitive sensors made me think if you drove AC in one pin and had a submerged reference pin it could be use for auto calibrate and reference. Maybe polluted water could be automatically accommodated.

Sorry about my ramblings.

Regards Ken

TimB

Hi Ken

I think I used that demo board for that Cap to adc device and I even made a PCB to match my requirements complete with references (image below). The issue was the drifting while static. What has to be appreciated is I am measuring sub mm water level changes. The drift meant I could not keep to that level of accuracy.

I already use IR slot detectors that can very easily detect water / no water changes. IN the way I use them them IR is actually better transmitted through the water. I monitor the flow of bubbles using it and am getting > 0.1ml accuracy. However slot detectors are limited in the width. One goes up to 8mm and that leaves a 6mm ID tube that may work, less than 6mm id tube and capillary action and surface tension means they do not reflect the level of the larger vessel they are connected to.
Also the slot aperture is 0.5mm and that may not be small enough. The ones I use in the my 4mm OD glass tubes are ~ 0.25mm and as the bubble is moving I do not need great resolution. Its more timing...

I originally drove my drive pin with a square wave from a HWPM pin on the pic. But to remove the ripple meant the cap big enough took > 10ms to notice changes. I need < 10ms. I found that straight driving was as good and I can reduce the duty to < 50% to prevent to much issues with corrosion. Also the equipment may only be used Once a year. So corrosion is no a concern to me.

I left the system running and logged the ADC levels to see the picture and figure out time to change threshold level requirements. Earlier on I had the system ruuning for a few hours then noted the B probe was reading 245 in the water and 0 no water but normally was running 470 in the water. I had the threshold set at 250 as on another day it was 100+ no water. With pure water the In water level may only be 80.

I will have to build a truth table with all the scenarios then say in X state use this algo to work out the threshold and in this state us Y system.
The main thing will be to get an average then set the threshold to say 30% swing from that and hope I get the state right.

Cap PCB.png

TimB

I looked at the log and it is very enlightening and confusing.

Top series is Bottom probe. Bottom series is top probe

The very low dip is the B probe not seeing water. The top probe should not really change as the logs are 1 hz and should not record the level change as it is too quick.


ADC Chart.png

ken_k

Wow! Tim you must have spent many hundreds of hours on this project.
Regarding the data I have some trouble making sense of it.

Re reading this post I see you have 4 probes in this water. Have you considered reading between all the available combinations to try and get some additional maybe meaningful data?
Using FET switching maybe using something like a CD4066. Maybe a read from BProbeD to TProbe may be useful, the polarity could be reversed for every second read.
All unused probes could be disconnected. Maybe drive 3 and read one. Maybe additional data may help? Different probe loads could be switched in and out.

Does the water have another reference to ground?

Rambling again!

Regards
Ken

TimB


Looking at the graph has helped me a lot

I can see there is a big spike down near the end of the fill. I figured out what it was, it is the water level hitting the TProbeD. I forgot to disable the drive properly, I just sent the line low, This caused a short between the BProbeD and TProbeD reducing the voltage to the Bprobe. It got very near to my 250 threshold (and did cross it in some cases). I have amended the code to make it an input now.

Also the current vessel does not have water feed guidance so the water entering smears everywhere on its path down. Next version has a groove to make it track away from the probes.

I hope with all the amendments I make with a State machine to work out the best threshold recalc algo I may get near to it being useable

Tim