News:

;) This forum is the property of Proton software developers

Main Menu

Looking for ideas on dynamic level sensor settings

Started by TimB, Aug 15, 2022, 01:07 PM

Previous topic - Next topic

TimB


Hi all

I have a bit of kit that I have limits for a water level. I started out feeding it a PWM to prevent corrosion and reading the ADC values of the inputs, but then had issues with the smoothing circuit and the delays with the charging of the caps. I needed < 10ms and my basic values were > than 10ms. Changing the RC values to speed it up introduced a lot of ripple.

I have now decided to just use a straight 5v through a current limiting resistor and read the values with the ADC, its not going to be used 24/7.

The issues I'm trying to solve are that the threshold I set is currently hard coded. Considering the conductivity of the water will change form dirty to very pure I need to build in some dynamic threshold routines as the threshold changes depending on the liquid.

I have on my list getting to a point that by using other methods that I know my probe is covered in water and getting the level. Then changing the pass to be a % of that.

My issue is that for testing I'm using the 1khz square wave on my scope and detecting the signal. This is part the the volume calibrations I need to do. BUT I started to notice tracking across my probe connection points from moisture. I can see a reduced square wave on the scope. So some signal even when no water is creeping in. Sorry no pictures at this time.

So my question is, is there any algo that can be used to get around the issue, to intelligently adjust for this, as the signal does always get larger when you get a true signal. I was thinking that a data slicer in an RF receiver has the same issue.

Is there an a system that could say look for a greater than X change from the last reading and that is the signal to say water seen. In my head I see that it will work to an extent but it will be messy as you have to have save guards that it does not creep to a point that it will make it none receptive or sluggish, like if say you used a buffer of the last x readings to base your base level off.

Any ideas appreciated. While some will not be usable they accusatively seep into my brain to guide me in the right direction. It may be that this is super common and there are loads of examples out there I have not seen.

Many thanks I HOPE this post was not a TLDR type ;)

Tim










top204

That is also the problem with capacitive and resistive touch sensing, so take a look at a few articles on that. They also use an ADC for touch sensing, so it may give some clues.

The only method I have used in the past is taking readings when the unit is not in use, and as regular as possible, so it has a starting point that will move over time. Then use a conversion procedure to alter a value range in, to a certain, fixed, value range out. See the "Scale.inc" library in the compiler's "Includes" directory. It may give you some extra ideas.

For touch sensing on a toy I was designing, so if the child touched the toy's nose, the toy would play back what the child had spoken too it, but at different speeds and even backwards, I measured the touch sensor ADC when the toy woke up with the watchdog every few minutes, to give a quencience value, then read the ADC for values above that, with a bit of software bandpass filtering and scaling. If the ADC woke up the unit, the child was already touching its nose, so quenciece was not measured.
 
Question...... What does TLDR mean? :-)


TimB


Thanks Les

Yes the Cap touch will be effected the same as mine. I will check the solutions used and your code out. It seems the way I was planning was on the right track.

TLDR means Too Long Did not Read

keytapper

#3
Using Ultra Sound system to measure the level, what that cause?
Probably the sensors should be putted into a 3" PVC pipe, so the water inside would be rather calm.
Remaining  to measure on OP method, I design a procedure that make a kind of filtering:
Symbol TOLERANCE 5000               ' defining a tolerance to avoid peeks samples
Dim AvgReady As bit                 ' signal for the sampling completion
                                    ' rather faster than reading the returned
                                    ' value different from zero
   
Proc FilterValue(invalue As Dword), Dword
  Dim lastRead As Dword             ' The previous data read
  Dim Average As Dword              ' value average calculation
  Dim cnt As Byte                   ' number of samples
  Clear Result
  If Abs(invalue - lastRead) < TOLLERANCE Then
    ' Between tollerance it will sum up
    Average = Average + invalue
    Inc cnt                         ' set for the next round
  lastRead = invalue                ' memorize the current reading
  If cnt > 15 Then                  ' when reached the wanted limits
    Result = Average / 16           ' Result will be set
    Clear cnt                       '  when complete the cycle, clear to zero
    Clear Average                   ' don't forget to start over without old value
'    Set AvgReady                   ' optional a flag to tell the data are ready
  End If
EndProc
Obviously, the size of the variables to be tailored for the necessity.
There could be an additional delay to call the procedure, so the average would be kind of smoothed average.
This procedure will give a result after 16 calls, whenever no out-of-tolerance reading are detected. In between samples the returned value remain set to zero.
Ignorance comes with a cost

david

Hi Tim,
Just backing up a bit - when you say you used PWM this was AC coupled PWM and not PWM direct from a PIC?
I think any net DC between two closely spaced probes will eventually result in plating and crystal dendrites.
Can you not synchronously detect the level of the PWM or was this what you were doing?  It shouldn't need much filtering unless the values are changing considerably between samples because you're not trying to filter the PWM carrier rate as you would in say a PWM DAC.
For filtering - if you want to hold a roll off frequency but increase the filtering you must use a second or third order filter.  A single RC pole has to reduce its cut off frequency if you want more filtering effect because it's fixed at -6dB/octave.  A second or third order filter will provide -12and -18dB/octave filtering which is far more effective than shifting a single pole down.  Passive is ok but active filters give a sharper knee close to the cut off frequency.

As for an algo  - you have more experience than most on this one but it sounds like a cross between a high score tracker and a filter.

Perhaps something like this-
sample=ADCIn1
value=oldvalue*31    '(2^n-1)
value=value+sample
value=value/32       '(2^n)
oldvalue=value

The term value will provide a tracking average with the time constant set by the use of 31 and 32.  If you use 255 and 256 the filtering will be extremely long.  So perhaps comparing a % of the sample value to the filtered output would give you tracking comparator action similar to an analog data slicer.

This really is the project that keeps on giving.....

Best regards,
David

shantanu@india

#5
I've seen the best tank level controller based on 3 stainless steel probes.. one reference at the lowest level, one middle and one high.The pump starts when the water level falls below the middle probe and stops when the level touches the high probe. Works all seasons with muddy/clear/hard/soft all kinds of water. Absolutely no maintenance for years.For continuous analog output the basic concept can remain the same.
In many cases, ratiometric measurement is better than absolute method.
Regards
Shantanu

TimB

#6
Thanks every one for the suggestions all very useful

shantanu, the probe system is what I'm using. The issues are the size of my set up, I do not have the luxury of a large probe seperation. I'm short on pins I think but next revision the reference is a must
Looking at the scope (images this time) it can be seen that there is a curve at the top of the signal I'm using from my scope to test for level while on the bench. This may be due to the resistance. The ADC in the pic will pick up a full voltage as its low on impedance if its left to sit. 

I think I can use the resistance or current capability of tracked water to my advantage. I will keep the grnd line of my probes low until its time to test. Then drive it high, wait a few us and perform the AD|C test. If I add a small cap in the line to ground, a very low resistance signal will take longer to charge the cap and if I get my timing right of the ADC read I can tell from the reading the resistance.

Or I could just put an R to ground to make an R/R divider.

That in combination with the type of systems Les talked about should make it reliable

Strong signal.pngTracking signal.png 




shantanu@india

Even if your probes have a fixed geometry, the bulk impedence of water(R+1/2*3.14*1000*C) is dependent on various factors.'R' might not change to a great extent but 'C' is dependent on pH.
You might try different excitation frequencies at 100Hz steps and plot the ADC values to assess the contribution of 'C' in the water impedence.
Regards
Shantanu

TimB


shantanu

Yes the water conductivity will change from the dirty tap water I'm using now to the very low conductivity of the very pure WFI in real use. The system has to adapt and I need to come up with a way to still get reliable results

I know that I can read the conductivity across WFI, The issue is that the conductivity is very high > 5 mOhm. If you set the threshold to a level to notice it then you can also notice the tracking as one probe is around 10-15mm from the other associated probe. This is what the adaptive algo has to work with. Constantly changing levels and tracking issues.

Tim


shantanu@india

Tim,
Can you explain the geometry of the probes? Are they two parallel plates dipped in a container like a battery?
Regards
Shantanu

TimB


Here is a few images of the top probe and a 3d sketch showing the relative distance

Probes 1.png
Probes 2.png
probes 3.png 

shantanu@india

I suppose the probe materials are SS/Aluminum wires to prevent rusting.
Can you make the lower probe a ring through which the upper probe passes like a vertical rod down to the bottom of the chamber? This would give symmetry to the system.The effective electrical conduction area would increase which might improve the performance.
Regards
Shantanu

TimB

#12
The distance between the top probe and the v+ do not change so no need to add a ring. The water entering the unit is from the top and directed down so the probe +V position is away from it. It clings to the wall so a ring would mean 100% there would be a track up towards the detection probe

There is a bottom probe and that has its own +V line

BTW its a very precise system or needs to be. The top probe is threaded so very fine accurate settings can be done. Were looking at 0.02ml accuracy


probes 4.png




shantanu@india

0.02ml? :o
Thats almost pharmaceutical standards.
Have you thought of buoyancy principle where a float is pushed up by water and force is detected by a load cell?
I have used calorimetric flowmeters where the probe tip is maintained at a precise temperature and the flowing fluid tries to cool it down and the amount of energy required to maintain the temperature gives a measure of the flow rate. Of course, here there is no flow.
Regards
Shantanu

TimB


The accuracy is easy. Small dia tube that the start and final detection probes are placed in. Other factors than the probe play a bigger part like the amount sticking to walls when detecting the bottom probe due to snaking. BTW there is a limit to how small your probe can sit in. I have it on the limit.

Floats to get that accuracy are effected by surface tension. They will not work in that dia tube, If the volume of the detection tube increases, the resolution reduces.

I have never found a flow meter of any design that is accurate enough to get 01%. I have tested a few including thermal flow types. I was thinking of building my own based on another system, but for now its not needed if the volume and probes works.

I just need to sort out the detection algo. I think the reference probe is the best solution. It resolves nearly every issue.

JonW

 Can you not just a simple diode peak detector to track the level or am I totally misunderstanding this. 

shantanu@india

Just thinking aloud....is the filling mechanism controlled by feedback from your liquid level detector? To achieve 0.02 ml accuracy in filling is not a matter of joke.
Regards
Shantanu

TimB


The fill is not controlled, It flows in at around 0.4ml a second. There are in reality a lot of factors that effect the accuracy. The 0.02ml is what I can get in ideal lab conditions. My scales are to 0.01grams and check them every time with a 500grm F1 ref weight. I fill the vessel with 100.00 +/- 0.01 then screw in the probe until the voltage is seen.

The tube with the probe in, is 12mm Dia. The maths says that with an R of 6, it is = 0.01ml per 0.1mm in hight

One thing to add is that as the pointy probe touches the water the water pulls up around the probe due to surface tension. So it introduces a hysteresis. As soon as the probe touches the water a good "connection" is made. It takes a lowering of the water by around 1mm for it to lose its grip.

If you filled the vessel very slowly from the bottom then you would get the accuracy . If its fast then the meniscus bulges and it may hit sooner. In my case the water is coming in from the top stuck to the wall of the tube.

Note I do not need 0.02 ml accuracy 0.1 will do.

Its a pain in the A to test and adjust so built a syringe pump with a stepper motor driving an Acme screw, to do it all. I built it a while ago, digging it out now to code the prog to run it.

Calibrate the system by filling a cup on the scales. It may take 6793 steps to get the 100ml. Its simple then to connect it to the test vessel, find the bottom probe point and then step 6793 times and I have my 100ml. Adjust the top probe down until it touches the water, then a few test cycles to ensure repeatability.

I just remembered I do have some code I stated on already. I will have to dig it out.






TimB


JONW

To have a peak detector I need to set what the peak is that represents the real water detection

JonW

Ah I get how it all works now.  Surely any averaging routine will eventually equalise over time.  What about 2thinner top probes and set them at slightly different heights so you can track out moisture and also have a level detection?