Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Measuring 20-40pF using PIC

Status
Not open for further replies.

Futterama

Member
Hello forum,

I wish to built a capacitive fuel gauge for a small fuel tank. I think the capacitance will be in the 20-40pF range.

How do I measure this capacitance with a PIC?

I have read a bit about using an opamp (LM324) to create a square wave oscillating circuit and I would then use the PIC to measure the frequency.

But will this be possible with a capacity in this range? I mean, the frequency should not end up being too high as I will have trouble measuring this with the PIC.

The idea for the fuel gauge can be found here:

KP0000

My fuel tank is just a lot smaller and can only achieve a surface area of approx. 3 square inches (20cm2) for the variable capacitor.

I hope you can give me some hints :)

Thanks.

Regards,
Futterama
 
Theoretically you can measure even tiny capacitances with a PIC, by charging up the capacitor and measuring the discharge times. You can use different calue resistors, connected to different I/O's to periodically charge and discharge it, then averaging out the results. The longer it takes to discharge the more time you have to measure, for a given operating frequency, this makes your counter count to a higher number, giving you better resolution.

One of my recent little projects was building the PIC based inductance/capacitance meter. Turned out quite well, and its accuracy is on parr with the 200 quid one at my work.

**broken link removed**

other methods include using an oscillator with a sweeping frequency (again, can be done with a pic), and using the unknown capacitance as a filter. By rectifying the output you end up with a voltage proportional to the amplitude. This can them be read by a PIC's ADC to find the maximum peak. From that you can work out its capacitance.

But the 'all digital' method of using counters works out quite well, and my cersion of the meter in the above link works very nicely. You might be able to simplify it because you don't need to measure inductance (remove the switch for a start). As for the code, the source code is there for you to mod. All you shoudl need to do is add some code so that instead of it displaying the absolute capacitance it converts this to a usable unit (fuel left?).

Blueteeth

Another link!
ELM - Digital Capacitance Meter
Its for an AVR micro, but you should be able to work it out. Code is code :D
 
Last edited:
Also, check Microchip. It has several capacitive sensor app. notes, including AN611 for measuring capacitance.

John
 
Thanks, I didn't really consider the charge-discharge approach, but surely this would be the simplest in terms of part count when using a PIC.

Again, thanks, I'll give it a try :)
 
Keep your leads short and well-dressed on this one. 20pf is down where it will be affected by wire capacitance.
 
Blueteeth, I'm a bit confused now, after looking at the schematics in your links.

I found a RC time calculator on the internet, and it seems like I have to use a really large valued resistor to discharge through, something like 10M to get up in the 100µs discharge time which I guess I need to get a fair resolution on the PIC counter.

But what about the leakage current into the PIC's comparator, wouldn't that discharge the small cap in no time?

Also, I'm not familiar with ASM code :-(
 
Last edited:
It does, but it's a fixed rate, like the resistor, so the only variable is the capacitance.

I've actually done this (proximity sensing, anyway) on a PIC with a DIGITAL port pin - you set it to an output, charge the cap, set it to an input, put it in a loop, count up until the pin reads zero. Not great resolution, but good enough for a gas tank.

A bigger issue is the effects of humidity and wires moving around.
 
When I first read your post, I thought you wanted specifically a PIC-based solution. On second thought, there are dedicated sensor detectors, such as the CAV414 series from Analog Microelectronics (CAV414 pdf, CAV414 description, CAV414 datasheets, CAV414 view ::: ALLDATASHEET :::).

They are a bit pricey, but can be quite sensitive down to 2 pF or less. I used one with a sensor in air of about 1 sq. inch.

John

PS: Have you had a chance to try the new transformer and IC chip for your CDI ignition?
 
duffy, I will try your simple solution. Do I need a resistor between the capacitor and the PIC port pin when trying to measure 20pF?

John, your idea is not all bad, but the IC you linked to, has it's limitations, the worst thing is the reference capacitor since I would then need to find one that matches the capacitor in the fuel tank.

And no, I haven't tried it yet, but actually I could start creating the PCB design in Eagle and later create the PCB to test it.
 
Hi again,

I just found the Maxim MAX988 which is a "High-Speed, Micropower, Low-Voltage,
SOT23, Rail-to-Rail I/O Comparator". I has an Input Bias Current of 1pA, so I'll try to connect that to the capacitor and let it discharge into the input and that should take enough time for the PIC to get a good reading.

I ordered 2 samples, I'll test it when they arrive, until that, I'll play around using the PIC input port.
 
The resistor goes in parallel with the capacitor (sensor). 10meg is a good choice, but most of the discharge current is leakage on the port pin so the RC time constant is lower. The resistor just gives it a more specific cut-off point, it tends to dither otherwise.
 
duffy, I just tried your suggestion, but I get very different results from every reading, so I can't really use this approach.

I have just found what I was looking for. I connected a LM358 in the Squarewave Oscillator mode and I get a frequency of 20kHz using 2 aluminum plates of 1" x 3" seperated with 3 layers of paper (0.6mm) as capacitor. This is great, the frequency is stable on the scope, now I just have to create the PIC program to measure the frequency.
 
What numbers were you getting? Sure your counter wasn't looping? You can reduce the size of that resistor if it was, and that will also give you more stable readings.

If your pic has an interrupt pin, you can trigger it off the LM358 and start a count at a precise point. If it has a capture/compare pin, you can use that to get even more precision and less processor overhead. Otherwise you are stuck polling it.
 
Hi again,

Good to see the idea's flowing :D

Just thought I'd mention that the digital LC meter project obviously isn't my design, I just built it :D

About capacitive sensing...'capacitive touch sensor solutions', for this app, have both advantages and disadvantages as far as I can see. The advantages are, the techniques are well documented, they explain exactly how these algorithms work, including self calibration and cancelling out constant parasitic capacitances (which will probably be higher than your actual sensor). However, perhaps I'm just worrying about nothing but aren't touch sensors purely relative? NOT absolute?

I realise the application is for a fuel tank, so its not like you want to see '32pf' on your meter, you need to convert this to real-life data, ie: how much fuel you have. But, touch sensor algorithms allow for drift in capacitances, only sensing sudden changes. They have dynamic thresholds for proximity and/or touch, which means you only really get a 'yes/no' out of them, not a nice number which is linear to the input capacitance.

That said of course, there's more then one alogrithm for measuring capacitance. Ultimately when I mentioned 'charging/discharging', all you are really doing is using the capacitance as part of an oscillator. Comparing it to a 'known' capacitance to callibrate it, and to cancel out varitions in other components (which can be damn accurate). method). It can either be purely in in software, or, if you need your micro to be doing other things, the 'CCP' module, which is on many PIC's these days.

Sorrry, I'm not trying to confuse you here, just perhaps attempting to give you more food for thought. Nothing beats experimenting :)

Blueteeth
 
However, perhaps I'm just worrying about nothing but aren't touch sensors purely relative? NOT absolute?

You can get absolute values out of it. Try it with your cap meter - make a round metal plate, say a half-inch in diameter, with a coplanar ring around it. Put a thin insulator over it (very thin) hook the plate and ring to each of the cap meter's leads, put the meter on the lowest setting. Say it's 10pf, it will probably double when you touch it. Reasonably consistant readings if you don't move anything, fairly good signal to noise ratio.

Still, seems kinda dicey, doesn't it? Gasoline only has a dielectric constant of 2, so if it's 20pf it will go to 40pf submerged. Water has a dielectric of 88, so it might not take much condensation on those cold aluminum plates to throw the thing.
 
Last edited:
Ahh duffy, I meant the algorithms for touch sensors, not the capacitive sensor itself. I'm sure its 'fairly' stable, although this whole thead is a bit out of my league..analogue scares me.

Great point on the dielectric...I really didn't think of that. I assume the OP has tried to increase the surface area of the sensor as much as possible? As I said, I'm really out of my league, the only caps I've made myself were for a TEA UV laser, and those had to be flat. so...

Blueteeth
 
Increasing the surface area will improve signal to noise, but I'm afraid it won't affect the effects of condensation on them 'lunamum plates.

Hope the application isn't critical. Watch OP says it's for a gasoline-powered heart-and-lung machine.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top