1. 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.
    Dismiss Notice

PIC based high-resolution cap meter

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

  1. Mosaic

    Mosaic Well-Known Member

    Joined:
    Jun 3, 2010
    Messages:
    2,568
    Likes:
    128
    Location:
    Caribbean
    How would one approach measuring Capacitor ESR?
     
  2. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Made a new video fixed a ton of bugs:

     
    Last edited by a moderator: Sep 10, 2013
  3. sahu

    sahu Member

    Joined:
    Oct 18, 2009
    Messages:
    468
    Likes:
    3


    very nice project . how can modified it for reading up to 4700mfd ? & also reading for resister ?
     
  4. dave

    Dave New Member

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


     
  5. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    192
    Location:
    Out there

    Atom, why do your own version when mine is fully finished and tested and the PIC hex file is included? There were a few clever firmware tricks I used to ensure very high resolution and math precision, and it was not easy to fit it all in a 2k PIC. It has also had quite a bit of testing against good frequency meters and other cap meters. Why try to duplicate tricky hard work when it's already been done for you? :eek:

    Sahu, most multimeters read large capacitor values, it is the small caps that can be hard to read. Also large caps are very clearly marked so is never doubt as to what their value is. :)
     
    Last edited: Jun 30, 2011
  6. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Roman, dont be offended in any way... i simply dont own any 16F628's and i wanted to see if i can do it also. Its not a clone of your work at all. I can draw you a schematic if you want. my code is also small.

    Its less than 4k which is good for most PIC18F series. Also i might make it USB so you get the value in a nice windows application
     

    Attached Files:

  7. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,765
    Likes:
    132
    Location:
    morristown,tn
    ONLINE
    Here one I been playing with Resistance and Capacitance Meter from a appnote

    I changed it to use a LCD working on a way to read inductors
     

    Attached Files:

  8. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
  9. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    192
    Location:
    Out there
    I'm not offended! The reason I put hobby work up on my web page is so people can enjoy it and benefit from it. :)

    It's great that my little cap meter is of interest to people and might even inspire them to build their own, and it would be fun to see people's designs and look at the pros and cons of each design.

    It was just based on your earlier posts I thought you were using my design of the comparator oscillator and accumulated consecutive periods etc, and it just seemed to me that if you were going to copy 90% of my design then why not just use the firmware too as it was carefully tested. :)

    Burt, I tried making an inductor meter using the RL comparator oscillator but there are significant problems. Most inductors require a minimum current for their core magnetics to start to work properly, so my attempts using 5mA for the inductor oscillator proved pretty bad.

    Most inductor meters use an LC resonance oscillator, which works well but unfortunately requires a square root in the L calculation as freq (or period) is proportional to square root of LC. BillMarsden on the other forum was making an RL oscillator for period inductance measuring but using a FET to get enough current to work the inductor. There's an interesting thread there.

    Of course the PIC can do a square root etc but it really starts to cause some problems if there is a very wide range of inductance value. As my RC cap meter is linear it copes well with the huge measuring range of 0.01pF to 50uF (that's 5 billion to one!) but with an LC meter and square root it needs to a much smaller limited range and then needs hardware range switching etc.
     
    Last edited: Jul 2, 2011
    • Like Like x 1
  10. sahu

    sahu Member

    Joined:
    Oct 18, 2009
    Messages:
    468
    Likes:
    3
    no sir , my doubt for weakness for old large value caps.
     
  11. hugo

    hugo New Member

    Joined:
    Aug 9, 2003
    Messages:
    18
    Likes:
    0
    Hi Roman,

    You've forgot to mention what is the RC oscillator frequency : " The oscillation period (freq) is set entirely by RT and CT. "

    Is the duty cycle 50% ?

    Thank you !
     
  12. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    192
    Location:
    Out there
    Hi Hugo, I did say on my web page near the bottom under the heading "Testing";
    "When it powers up the display will read the total value of the internal 270pF cap plus some extra capacitance from PCB tracks etc. Mine reads about 320pF. The oscillator will be running about 220 kHz."

    Then as more capacitance is added the frequency will drop accordingly.

    Yes the duty cycle is very close to 50%.
     
  13. hugo

    hugo New Member

    Joined:
    Aug 9, 2003
    Messages:
    18
    Likes:
    0
    That helps but I was expecting a mathematical formula, something like this : T= K*RT*CT ; K = constant ;

    is it by any chance T = 1.4*RT*CT ?
     
    Last edited: Jul 22, 2011
  14. Mike - K8LH

    Mike - K8LH Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    3,636
    Likes:
    108
    Location:
    Michigan, USA
    For those few guys who have tried this circuit on another device other than the '628A, may I ask which comparator configuration you used, please?

    TIA. Regards, Mike
     
  15. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    192
    Location:
    Out there
    Hugo, the constant depends on the amplitude the comparator switches between. In my original version the comparator resistors set the switching points at 1/3 Vcc and 2/3 Vcc so it is the time RC takes to charge and discharge between those 2 points. It was easiest to measure known 1% caps against the period and manually enter the constant in the source code. I've since found some 0.5% caps and they test good too so my constant must be pretty close! If you are using my hex file and wanted to "trim" the constant you can do that in hardware; either trim the 10k resistor or trim the 1.5k on the comparator output (between RA3 and RA2).
    Both those resistors have an effect on the frequency of the oscillator (for a given cap).

    Mike, I didn't try on a PIC other than 16F628A but the comparator setup was the one that allows all 3 pins of the comparator as external pins (I think there's only one mode like that?), then the external pin for comparator output was tied through a resistor into the CCP capture input, to capture the period. You could use an external comparator if needed.
     
    Last edited: Jul 23, 2011
  16. crystallattice

    crystallattice New Member

    Joined:
    Aug 2, 2011
    Messages:
    3
    Likes:
    0
    Hi Roman,

    Thanks for sharing your project and other very interesting ideas. How exactly does the cap meter work? Your explanation on your website is confusing me a bit. Some psuedo code might help....

    I have done a frequency meter in the past but would like to understand your method of doing things, if it is indeed any different from what I did.

    "The PIC measures the RC oscillation period by using the PIC's internal hardware capture (CCP1). The PIC xtal is 16MHz so the PIC timer runs at 4MHz.

    It adds consecutive captured periods until there is a total accumulated time greater than 2 million counts (>0.5 second). The only error can be the edge error for the first and last capture, so the error is limited to 1 part in 2 million at each end, a total possible error of 1 PPM (1 Part Per Million).

    Now it has a precise captured total of periods the average period is determined by dividing the total period with the number of periods captured. As the total is always just over 2 million it is scaled up to 2 billion before the division, to give a lot of accurate decimal digits after the division."
     
  17. crystallattice

    crystallattice New Member

    Joined:
    Aug 2, 2011
    Messages:
    3
    Likes:
    0
    While I'm at it I might as well post more details on the application. I made a simple capacitance water level sensor using water as dilectric and one bare and one insulated wire. Tha change in capacitance changed osc frequency of 555 which was fed into pic CCP. problem was that PIC had to run at very high frequency (about 40Mhz) to be able to get nice resolution and probe also soon ran out of range. Thus the overall project worked but resolution was not that great.

    I'm thinking that you might have a better way of indirectly measuring the capacitance which might benefit my application. I can't recall all the details of the project as it was completed a few years ago but the capacitance of the probe was very small (20pf range if I remember correctly) and the change was also not that much. The idea is to implement the "new" design in a 12F675 or 12F683 with internal osc if possible. The less external components the better...

    Regards
     
  18. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    192
    Location:
    Out there
    Hi Crystallattice, the Cap meter is not a frequency meter really but a "period meter". This is because a larger cap causes a larger period, reasonably linearly. So all you do is measure the oscillation period, and scale it by a single scaling factor and you have a reading in capacitance.

    I thought it was already explained pretty good on my web page. :)

    The same principle should work ok for your capacitance probe, ie measure period, scale to capacitance (or directly to water level if that is linear to its capacitance). It sounds like an interesting project, you should start a thread on the water level meter project so people who are interested in doing the same water level project or who have experience in that specific area can get help from the thread or contribute to it etc. :)
     
  19. crystallattice

    crystallattice New Member

    Joined:
    Aug 2, 2011
    Messages:
    3
    Likes:
    0
    Thanks Roman, but you are still leaving me in the dark...

    In my original design I used the CCP to capture internal tics from tmr1(running at 10MHz). The CCP was fired on every 16th edge of the 555 osc output, this ensures that there are enough tics as the signal was quite fast at some point (KHz range). This was allowed to happen for exactly 1 second and all the tmr1 overflows were also counted. Combining the overflow count and the current CCP count you can get a very nice indication of the period of the 555 signal. So yes, I measured the period of the signal instead of the "frequency" per se.

    The way you explain it, or rather the way I (mis?)understand it, is you are doing something similar but not sure what you mean by the 2 million cycles thing? Please explain the following:

    "It adds consecutive captured periods until there is a total accumulated time greater than 2 million counts (>0.5 second). The only error can be the edge error for the first and last capture, so the error is limited to 1 part in 2 million at each end, a total possible error of 1 PPM (1 Part Per Million).
    "

    The biggest problem I had with my probe was the small change in capacitance over the length of the probe - 2000mm or rather the inability to measure it. Redesigning the probe with better materials would probably yield a larger delta C but given the time and resources that was never materialised - know of any good source of very thin (or very thinly coated) PTFE/teflon coated wire?

    I must really scratch and find my documentation to see what values I got but it was the main cause I did not develop the project further, the other was that the project was the end of my studies for which I got a distinction and was fairly happy with that!

    Looked at other methods of measuring capacitance on the PIC and it would seem the "frequency conversion" method is the most "accurate" for my application although there are better solutions than to use a 555 - like what you did.

    I will probably share the code in the future, but will try and see if I can't market it locally first to try and make a few bucks.... it seems the new trend is to design something and start a company! Not that I think something like this will ever get that big, but no harm done in trying to pay for my time...

    Regards
     
  20. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    192
    Location:
    Out there
    It sounds like you know what you are doing with the softwarer side. :)

    Maybe you're right a probe redesign might be the best option? Sorry I don't have a lot of experience with capacitance probe water level detectors.
     
  21. nhjeep4x4

    nhjeep4x4 New Member

    Joined:
    Aug 20, 2008
    Messages:
    1
    Likes:
    0
    Hi Roman,

    GREAT project! I've been looking for a schematic for one of these! Perfect timing! I'll post when I get it up and running.
    Thanks for sharing your work!

    ~ Jon G.
     

Share This Page