# PIC based high-resolution cap meter

Discussion in 'Microcontrollers' started by Mr RB, Jun 27, 2011.

1. ### Mr RBWell-Known Member

Joined:
Jul 22, 2008
Messages:
4,716
Likes:
194
Location:
Out there
"Scale" is scaling from time measurement units to picofarads. It depends on your time unit size, and your charge/discharge impedances (resistor values).

The 100 enlarges the number from 9 million to 900 million, giving much more accurate math when the next process is a division.

The simple way to approach it is to assume that the time period from the oscillator is proportionate to the capacitance. Basically you measure and add multiple period samples to increase the accuracy, then you multiply the number with a constant to give a very large number (but that still fits within a 32bit signed or unsligned long variable), then you divide by the scaling factor (which converts from time units to picofarads).

In your case the scaling factor will be found the easiest by measuring some 1% tolerance caps and doing it empirically rather than trying to calc it and still needing to tweak it empirically later.

Thanks for the nice words about my hobby site, yes I do miss the hobby projects and have a few fun ideas going in the background but unfortunately have too little time at the moment to complete them and write up the page. I'll make some time sooner or later.

Last edited: Jun 22, 2012
2. ### vpepNew Member

Joined:
May 22, 2012
Messages:
2
Likes:
0
Quick question before taking the plunge!
Everyone except me already figured it out i guess, but whats the lcd controller type?
HD44780?

3. ### Mr RBWell-Known Member

Joined:
Jul 22, 2008
Messages:
4,716
Likes:
194
Location:
Out there
Yep or compatible. Pretty much any 12pin (or 14pin which has +2 backlight LED pins) LCD should work.

I keep an eye out for (older style) non-backlit LCDs as they only use 4 or 5mA and give great battery life.

Joined:
Jan 12, 1997
Messages:
-
Likes:
0

5. ### vpepNew Member

Joined:
May 22, 2012
Messages:
2
Likes:
0

Ok ive assembled parts for an order. Appreciate your quick help Mr RB

6. ### upand_at_themMember

Joined:
Apr 23, 2005
Messages:
609
Likes:
8
Location:
Pennsylvania, U.S.
I'm assuming no modifcations need to be made to use the hex file with a 16F648A. Yes?

7. ### Mr RBWell-Known Member

Joined:
Jul 22, 2008
Messages:
4,716
Likes:
194
Location:
Out there
Hi, I have not tried that but I think it would work, as the config settings etc should all be the same between the original 16F628A and the 16F648A.

Please let me know how it goes.

8. ### upand_at_themMember

Joined:
Apr 23, 2005
Messages:
609
Likes:
8
Location:
Pennsylvania, U.S.
I don't have any 16x2 LCDs. Any chance you can generate hex files for 8x2 or 16x1 LCDs?

Last edited: Aug 23, 2012
9. ### Mr RBWell-Known Member

Joined:
Jul 22, 2008
Messages:
4,716
Likes:
194
Location:
Out there
No, it's not worth the work as the two lines displa different things I would need to rewrite some code. The 16x2 LCD version has gone though polishing and testing so I would not care to rip the code apart and make changes in it, to end up with a reduced functionality (ie less display) and possible bugs.

The best advice would be to get a 16x2 display from somewhere, they are VERY standard now as the most common display type sourced at parts outlets.

10. ### thinkerNew Member

Joined:
Aug 31, 2012
Messages:
6
Likes:
0
Poor accuracy of C meter

Hello Mr.RB

I build meter with 0.05% smd resistors ,condenser 270p 1%(although there is no need 1%), but results is no good. Condenser 150nF 0.625% meter show 146.411 nF(too small value), 47nF 0.625% meter show 46.224nF(too small value) ,1nF 1% meter show 1.063 nF(too high a value), 2nF 1% meter show 2.070 nF(too high a value) . This is not good accuracy.Somewhere there is a problem.Be a processor problem? View attachment 66820 Mine is 16F628A .Thanks for the reply.

11. ### thinkerNew Member

Joined:
Aug 31, 2012
Messages:
6
Likes:
0
------

Last edited: Aug 31, 2012
12. ### Mr RBWell-Known Member

Joined:
Jul 22, 2008
Messages:
4,716
Likes:
194
Location:
Out there
It's not a processor problem as the math uses 32bit and is accurate to quite a few decimal places even though it has different "ranges".

The most likely thing is the tolerance of your caps, even though caps are marked as 1% this is +/-1% which is a 2% range. You should check 10 or more of each value cap even when they are 1% caps, as if you only check 2 or 3 you might get a couple of low or high ones.

Also please understand that for the small cap values the leads are contributing to the capacitance, and when you zero the meter the leads may be in a different position to when the cap is clipped onto the leads. This can often make small caps read higher.

Construction might also be an issue! If you have a photo of your setup that will help, so we can see the stray capacitances that might be making the small caps read high. As far as general tuning goes you can put a 200 or 500 ohm trimpot in series with the 10.00k resistor, then tweak this to set the calibration.

And finally I would not expect the cap meter to be of a really high accuracy, especially over a very large range of cap sizes. It should be better than 1% accuracy over most sizes.

13. ### thinkerNew Member

Joined:
Aug 31, 2012
Messages:
6
Likes:
0
-------

Last edited: Sep 2, 2012

Joined:
Aug 31, 2012
Messages:
6
Likes:
0
15. ### Mr RBWell-Known Member

Joined:
Jul 22, 2008
Messages:
4,716
Likes:
194
Location:
Out there
I don't open people's personal ZIP files due to security issues. If you have a photo please post the photo in a standard viewable format (JPG etc).

• Like x 1

Joined:
Aug 31, 2012
Messages:
6
Likes:
0
17. ### Mr RBWell-Known Member

Joined:
Jul 22, 2008
Messages:
4,716
Likes:
194
Location:
Out there
Thanks for posting the pictures, your layout looks ok.

You really should add a 0.1uF or 0.22uF decoupling cap directly under the PIC, between the power pins. Your circuit only has a electro cap for 5v Vdd, and it is far away from the PIC.

The only measurement problem I can see is the two wires to the cap under test, as I said before this can have some effect when measuring small caps because of the wire position and the wire capacitance. It is good to keep those wires short, and when measuring small caps to zero the device when the wires are in the same position as measuring the small cap.

Re the non-linearity you seem to have measured, I cannot see why it is happening as suspect it is just the tolerances of your cap values. The frequency of oscillation is dependant on cap under test and on all the circuit resistances. We have to assume the circuit resistances are constant even when you change caps, so the only thing being measured is the cap itself. The freq of the oscillator is measured by averaging a very large number of cycles against a xtal, so it is very accurate, as is the software math that is done using 32bit values.

If you are seeing a non-linearity the only issues would be the capacitance tolerances of the caps you are testing, (and most cap values are all over the place, even in the same batch). Another issue might be the ESR of the cap under test, but the ESR of a cap will be quite small compared to the total circuit resistances used in the RC oscillator.

Last edited: Sep 2, 2012

Joined:
Aug 31, 2012
Messages:
6
Likes:
0
19. ### Mr RBWell-Known Member

Joined:
Jul 22, 2008
Messages:
4,716
Likes:
194
Location:
Out there
You can't simulate it that easily. The PIC output uses push-pull FET drivers, and will pull down harder (lower NFET Rdson) than it pushes up (with a higher PFET Rdson).

I tuned the circuit with an actual PIC16F628A, and chose the software calibration to suit the real world result.

In any case, if you think the software calibration I used is a couple of percent out, all you need to do it "tweak" the value of the 10k resistor up or down (with a small calibration trimpot if you like) until you are happy it is the best calibration.

I'm not going to keep answering questions on the accuracy of the capmeter as the software I released is adjusted already to better than 1% accuracy in my actual-hardware testing. And if people want better accuracy than that, you can adjust the value of the 10k resistor as mentioned above.

20. ### wjhosNew Member

Joined:
Jun 24, 2012
Messages:
5
Likes:
0
Hello,

Having searched the internet, i came upon this meter and built it.
Using an old remote control unit for a slide projector,i managed to put the meter in this 85x62x22mm box. A smal PCB was made and everything, including an LCD with a 33x10mm viewing area, battery etc. was mounted in the box.
The unit worked from the start. There are however some remarks.
When zeroed, the display gives a decimal point, then a blank and then 1,2, or another small cap value. It seems the decimal point position is fixed.
When in AutoCal, the minus sign jumps between front and back of the decimal point, depending on the actual value.
I know these are not fundamental issues, but being a perfectionist, i would like to correct these anomalies. Is this somthing you could do, because with only the hex listing this is not an easy if not impossible task.
For the rest, the meter is very good and fast, as i have checked with a variaty of accurate capacitors. Especialy the differential feature is nice, but could probably be extended to the higher cap ranges.

thanks

21. ### Mr RBWell-Known Member

Joined:
Jul 22, 2008
Messages:
4,716
Likes:
194
Location:
Out there
Hi Wjhos. I'd love to see photos of your build.

OK, regarding the "small cap value" after zeroing, that is because of the very high resolution of the meter. As the leads move (even with no cap connected) it creates fractional changes in pF and since the capmeter shows resolution of 0.01pF there will be a few counts showing. Same result if you put your fingertip near a lead, the capmeter will detect it.

I can help better after seeing your photos, but it helps if all the leads inside the box are glued down so they don't move. Also any flyleads to the cap under test should be short (<3 inches, and <2 inches is better).