Ultrasound liquid level sensor

crutschow

Joined Mar 14, 2008
34,450
I don't think there is any accuracy difference between measuring the time-constant and measuring the frequency. So it depends upon which is the simplest and/or most reliable.

You could do continuous time-constant measurements and perform a simple running average if you are worried about false readings or noise.

Will the microprocessor circuit see much of a temperature change?
 

Thread Starter

geoffers

Joined Oct 25, 2010
488
Thanks, the processor could be mounted on the milk heater outer tube which would keep it at a relativly constant temp, I guess that temp change may have quite a effect?
Cheers Geoff
 

Thread Starter

geoffers

Joined Oct 25, 2010
488
Hi again,
Just been fiddling around with it, put a 1Mohm resistor from +V to a cap which is connected to ground the juction is connected to RA5 on my pic (only chosen as it was most conveniant) seems the resistor is acting as a weak pull up , even with a 220nF cap it just rolls through and counts 6, which is how many lines there are between clearing the counter and reading it? Should I try configuring it as a comparator or is there another trick?
Thanks Geoff
 

Thread Starter

geoffers

Joined Oct 25, 2010
488
Sorry, was being a bit simple, forgot to programme in a pause for the cap to discharge!!!!:p With a pause while the output of RA5 is held low it works fine, I now have a capacitance meter (of sorts!:))
Thanks Geoff
 

MrChips

Joined Oct 2, 2009
30,808
I was just going to say 100pF x 1MΩ gives a time-constant of 100μs
so this is doable with a fast processor.

If you need to reduce the value of the resistor you could create an oscillator using CMOS gates a then measure frequency.
 

crutschow

Joined Mar 14, 2008
34,450
Thanks, the processor could be mounted on the milk heater outer tube which would keep it at a relativly constant temp, I guess that temp change may have quite a effect?
Cheers Geoff
A temperature variation could cause the threshold level of the logic inputs to change. It should have less effect on an input configured as a comparator.
 

Thread Starter

geoffers

Joined Oct 25, 2010
488
Hi again,
Just been fiddling about, I was inteanding to try and sort out the comparators this eve and try that, however looking at my circuit I have already used up the pins of porta that the comparators use with my display:mad:! Short of rejigging my pcb and quite a bit of code thats out. I've tried the setup on my speaker wire level capacitor and the resolution isn't quite good enough, as mr chips said with 100pF and 1Mohm I would get 100uS to 5v charge, that fits with what I'm seeing trouble is I think a PIC sees much over 2v as high so I'm getting about 50uS pulses. As I see it I've a few options... Rev up the PIC its running at 4MHz at the mo, it will do 40MHz which should sort things out (I would have a bit of codeing to sort) make my probe out of something else?? with higher capacitance. Or put a bigger resistor in? The resistor is the easiest option, any one a idea what problems that could give me?
Thanks Geoff
 

MrChips

Joined Oct 2, 2009
30,808
I was going to go the other route.
100μs would be equivalent to a frequency of 10kHz.
If you reduced the resistor to 1MΩ that would give 10μs or 100kHz,
Which MCU are you using? Does in have a timer input feature?
It might be better to measure frequency rather than period.
 

Thread Starter

geoffers

Joined Oct 25, 2010
488
Hi,
I'm using a 18f2523, its got a ccp module on it which I've never used, at the moment I'm using a 1Mohm resistor, sorry if I'm being simple(happens quite frequently!), when you say measure the frequency do mean drive the rc as I am at the moment, by switching my pin between input and output, then incrementing a register each time? At the moment I'm running a 4MHz crystal which gives me 1uS instructions, using my current setup, with the 1Mohm resistor the rc period is around 40-50uS with a change of 30pF on my probe that gives me a change of 12-15uS on the rc periond with 4 instructions taking 4uS in my current setup I get not enough resolution. If I measure the frequency I will use another 2 instructions at least, unless I put a 555timer or suchlike in? What I'm driving at is don't I need to either up my osc speed or slow down the RC to get my resolution which ever way I measure it?
Thanks again Geoff
 

Thread Starter

geoffers

Joined Oct 25, 2010
488
Hi again,
I've been doing a bit more fiddling, I wonder if perhaps I need to make a 'better' probe? I get reasonable readings with my pic meter if I substitute cereamic capacitors for my bits of speaker wire! I'm wondering if I might be better to use either enamelled copper wire or mig welding wire inside a old teflon liner? I think the teflon would help give a more accurate level as the milk wouldn't cling to it as it does to the outside of the speaker wire? Any one else tried anything similar, do apretiate all the input I'm getting on this.
Thanks Geoff
 

Thread Starter

geoffers

Joined Oct 25, 2010
488
Hi all,
Still at it, thought I would update! I've modified my probe, its now stainless steel tig welding rod! One rod is inside the milk tube, the other as close as I could get it outside the milk tube, but inside the water jacket, I've now got capacitance going from around 100pF up to nearly 1nF when the tubes full, with a 1Mohm resistor this gives me good resolution. Next step is to sort out the control for the pump and soleniods, I've got some TIP121's I was thinking they would be ok to run my 2W soleniods, but I think I might pop a relay in for good measure.
Thanks to Mr Chips and Crutchlow for their help, Geoff
 

Thread Starter

geoffers

Joined Oct 25, 2010
488
Hi all,
I'm still tinkering around with this, does anyone know how much drift there is on the threshold voltage of a PIC input? I think I'm going to have to change to a comparator input. I've got the tube filling and emptying but its not very consistant! Another thing that might be giving me trouble could be noise from the pump? I've pleanty of decoupling capacitors throughout my boards (100nF) Could it be a good idea to put a bigger one on the pump? Any idea of aprox value? I've found some lcd displays that use the I2C bus which would free up the comparators, what do folks think, will using comparators make a big difference to accuracy?
Thanks Geoff
 

Thread Starter

geoffers

Joined Oct 25, 2010
488
Hi All,
I'm still messing about with this, after a brief tussle with the I2C display I now have freed up my comparator pins, I was just going through the data sheet and found the following ;
A maximum source impedance of 10 k​
Ω is
recommended for the analog sources. Any external
component connected to an analog input pin, such as
a capacitor or a Zener diode, should have very little leakage current.

Will this give me any problems measuring the capacitance of my tube? The resistor in my setup is 1Mohm at the moment.

Thanks Geoff

 

ErnieM

Joined Apr 24, 2011
8,377
I just noticed your thread. A while back I actually worked on one of these using a capacitive sensor. We (or I mean "he," my boss who liked putting more parts into any circuit) used a 555 in astable mode to change capacitance into frequency. This was long before anyone thought of direct cap measurements with the A2D and we may not have had one on that PIC anyway. "He" did the circuit, I did the PIC programming (horribly cobbled together assembly) and it ultimately worked.

Could you post your schematic (of the probe end), and a description of your current sensor physically?
 

Thread Starter

geoffers

Joined Oct 25, 2010
488
Hi Ernie,
As you probably saw a 555 was my first idea for this, I'm going to try what I've made now, partly thanks to your help on the I2C display! The setup I'm trying couldn't be simpler at the moment(fear it may have to get more complex). I've a 1Mohm resistor from +5v to ra0, my 'capacitance probe' between ra0 and ground. ra0 is now configred as a comparator refrenced to the internal ref module on the 18f2523, set at 0.75 of +5v.

My 'probe' is now two bits of aluminium foil tape down the outside of some 40mm waste pipe, this is surrounded by some heatshrink to keep it dry, connection is by two bits of ally tig welding wire(I was hoping this would keep any electrolisis outside where I could remove it?!), that waste pipe is in turn, inside a bit of 4" pipe which forms a water jacket, which is heated by a low power water heater. The idea being the inner tube will fill with milk which will be warmed ready for the calf to drink!
Cheers Geoff
 

Thread Starter

geoffers

Joined Oct 25, 2010
488
Hi all,
Still plugging away at this, feels a little like I've gone backwards? The set up I mentioned in my earlier post seems less accurate than my first attempt without the comparator.

I've done a quick google search and pinched this from Roman Blacks website (I hope he doesn't mind:eek:)

capmeter_3.gif


Do folks think using this would give me better accuracy and stability? He uses the CCP module, but I was wondering if I could save inputs by using the CMCON bit 6 or 7 to start and stop my timer? It reads in the data sheet like I can have external and internal output at the same time?

If I can't get it to work reliably I may have to go back to my first plan of ultrasound? This just seems nice and simple.

Cheers Geoff
 
Top