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. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    194
    Location:
    Out there
    OK, sorry for the delay Wjhos but I finally worked out what you meant. :)

    Originally the capmeter code was only JUST squeezed into a 2k PIC, so I left out the nicety of leading zero correction. It was a trade-off to still be able to fit all that 32bit math code into a tiny cheap PIC.

    So in the original HEX file it shows; " . 1pF" and " .-3pF" instead of "0.01pF" and "-0.03pF".

    However there are probably other fussy (OCD?) people like yourself that really hate imperfect leading zeros. ;) So I found a way to squeeze the leading zero correction into the code.

    I have re-programmed my own Capmeter and it seems to be all working perfect, and since this was only a minor display tweak I have not bothered with keeping the old HEX file, so the one on the web page is now the new improved HEX.

    And thanks for the suggestion. :)

    New HEX file is here;
    http://romanblack.com/onesec/CapMeter.htm
     
  2. wjhos

    wjhos New Member

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

    I read your answer, and it is exactly what i ment. As you asked for some fotos, i was making them just before reading the answer. I have attached them and they show the problem, which can now be solved using the new hex file, which i will download and flash shortly. Sorry, the fotos are not that sharp, but i used a simple camera. I can also post the PCB layout (which is in Sprint 5.0 format)

    thanks for your esponse
     

    Attached Files:

  3. wjhos

    wjhos New Member

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

    For some reason, the download hex file does not work. I do not remember how i did it the first time, but i think i had to copy/paste the file to wordpad. I did that now too, but when i load the file to my Pickit2, it is not completely the same. In the meter it does nothing at all. Can you provide the file as a downloadable file that can be directly imported to a programmer. It seems now it is a hypertext file ?.

    regards
     
  4. dave

    Dave New Member

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


     
  5. wjhos

    wjhos New Member

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

    It works, thanks
     
  6. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    194
    Location:
    Out there
    Thanks for posting the photos that looks like a nice neat tool you have built there! :)

    And I like your old grainy reflector supertwist LCD, they have great visibility and with no backlight they only use a couple of mA. Those old LCDs are getting hard to find now, all the LCDs now have backlights and use 20-40mA. :(

    Re the HEX file, the link I provided above is to the project web page. The link directly to the HEX file is here;
    http://www.romanblack.com/onesec/CapMeter.hex

    Re your PCB layout, sure if you like you can post it here. It may be of interest to people who want to build their own PCB. :)
     
  7. PrinterMAN

    PrinterMAN New Member

    Joined:
    May 21, 2013
    Messages:
    3
    Likes:
    0
    Location:
    UAE
    thank you for the very useful info , best regards
     
  8. wjhos

    wjhos New Member

    Joined:
    Jun 24, 2012
    Messages:
    5
    Likes:
    0
    After finishing the capmeter, i tested a mylar cap, 10uF, which had been on my workbench for a very long time. It appeared to be still charged to some extend, so it blew the input of the capmeter and i had to install a new PIC. Therefore i added a 4.7v zener across the input and a 100 ohm series resistance to give some protection. The meter seems to work properly, altough the initial displayed cap value has gone up to about 390 pF. ( was 325 pF )
    Does it realy influence the accuracy of the meter ? And is there maybe a better and more elegant way to protect the input against accidentaly charged capacitors ?
    I attached the layout of my PCB, without the protection components. It is in Sprint format. A free viewer can be found at abacom.de
     

    Attached Files:

    Last edited: Jun 13, 2013
  9. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    194
    Location:
    Out there
    How long had the cap been on the bench "charged"? That sounds pretty unusual, it's more likely the PIC was damaged due to a wiring short etc.

    The PIC input pin is already protected to some extent by its internal pin diodes, these are good for 20mA continuous and a couple hundred mA for short term one-off events. I don;t think a 10uF cap charged at 5v has enough energy to blow the PIC pin diodes. Maybe if your 10uF cap had been charged to a higher voltage it could do it.

    You can add a zener if you like, and the increased initial capacitance is just because the zener adds a bit of capacitance, as you measured about 65pF. That should zero out normally when you press the zero button.

    The 100 ohm resistor in series with the RA0 pin is also fine and should not really affect the operation of the meter, and you could even to go 330 ohms there for more safety.

    Personally I'm in the habit of shorting cap leads to discharge them before measuring IF they have been in a breadboard etc and may have some charge left in the cap.

    And if your 10uF Mylar cap was a high voltage type, that you know had been connected to a high voltage, that's a perfect example of WHY why you short out cap leads before measuring, even if the capmeter does have added protection! ;)
     
  10. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
    How about a TVS diode (or "transorb")? They are low leakage, low capacitance and can withstand fairly large transients for a short time.

    You'd still need to discharge large capacitors, but a 5V TVS diode might offer better characteristics than a regular zener.
     
  11. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    194
    Location:
    Out there
    Sure a transorb would be better still for protection. But I would worry a bit about it behaving differently at different frequencies, especially if it's a 5v limiting device in a 5v oscillator.

    The idea of the cap meter is that it's pretty good at measuring small caps right down to fractions of a pF so it would be a shame if a "safety" modification somehow upsets the performance. A resistor on that RA0 pin is the simplest safety mod and least likely to affect the performance.

    Regarding the safety a lot of people have built these on their own PCB or from the internet kit and PIC failures are very rare.
     
    • Like Like x 1
  12. PaulCo

    PaulCo New Member

    Joined:
    Aug 6, 2007
    Messages:
    5
    Likes:
    0
    need a bit of help in programming the pic please

    need a bit of help in programming the pic please.
    i am using mikroelektronika's EasyPic 4 board..
    PIC16F628A chip with 16Mhz Crystal..
    everything the same as your version..
    your new version of hex..
     

    Attached Files:

  13. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    194
    Location:
    Out there
    Hi PaulCo, your configs are not correct. I just loaded the Capmeter.hex into my MikroFlash programmer, and the configs read correctly;

    osc = hs
    wtchdog = off
    power up timer = on *
    master clear = off
    brownout = off
    low voltage program (LVP) = off *
    data ee protect = off

    Yours is different in 2 * places.

    I think it could be the EasyPIC 4 hardware forcing the PIC into LVP mode by holding the PORTB pin high.

    Try this;
    1. on the EasyPIC4 set the PORTB pullup jumper (right hand side of pcb) to PULL DOWN (that stops LVP being activated)
    2. open a new PICFlash on screen
    3. select PIC 16F628A
    4. file -> load HEX -> Capmeter.hex (configs should be correct to match mine)
    5. click "Write" button to program the PIC
    6. check the configs are still shown correct, and there were no error messages
    7. yay! success. :)
     
  14. PaulCo

    PaulCo New Member

    Joined:
    Aug 6, 2007
    Messages:
    5
    Likes:
    0
    for some reason just cannot get it going (still working on it)..

    for some reason just cannot get it going (still working on it)..
    so i made a different version with same components and it worked, just not as precise as your one..
    so means that the components can be ruled out.. this makes me think it's PIC16F628(A)
    ordered some PIC16F628 & 270p 1%
    will let you know how i get on..
     
    Last edited: Jul 1, 2013
  15. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    194
    Location:
    Out there
    Is it on breadboard? Do you have a photo? That will help a lot to see if there is an issue with the construction.

    I don't think the 628 or 628A will make that much difference to operation, but of course you have to set the programmer (mikroFlash) to suit the actual IC you are using. :)
     
  16. PaulCo

    PaulCo New Member

    Joined:
    Aug 6, 2007
    Messages:
    5
    Likes:
    0
    woohoo got it
    persistence paid off
    see pic for settings
    thank you for your time..
    Capture.PNG
     
  17. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    194
    Location:
    Out there
    Almost! MCLR (Master CLear Reset) needs to be OFF. The project does not use a Reset button. :)
     
    Last edited: Jul 2, 2013
  18. PaulCo

    PaulCo New Member

    Joined:
    Aug 6, 2007
    Messages:
    5
    Likes:
    0
    DOUHH !! LOL .. :)
    for some mad reason when using the easypic4 board it only works when it is on.
    maybe because it's wired in with pull-up resistor, not to sure..but when i push reset button it actually resets it to normal start-up (works in resetting it). as i see on circuit ra5 is not used..
    so now i know i've seem it working i'm gonna make up breadboard (not solder version - push in version), without reset circuit.
    ((MCLR (Master CLear Reset) needs to be OFF))
    this should in theory still work, if so i'll make up solder version..
     
    Last edited: Jul 3, 2013
  19. throbscottle

    throbscottle Well-Known Member

    Joined:
    Feb 1, 2012
    Messages:
    1,787
    Likes:
    113
    Location:
    Nuneaton, Warwickshire, UK
    Thanks MrRB - going to build one of these to sort out my smd board pulls and other dubious caps!
     
  20. throbscottle

    throbscottle Well-Known Member

    Joined:
    Feb 1, 2012
    Messages:
    1,787
    Likes:
    113
    Location:
    Nuneaton, Warwickshire, UK
    Is there any advantage in using a resistor pack for the 3x 1K5 resistors? A few 2% ones around, but I assume the relative tolerance of the resistors is better than that. I got a 0.1% for the 10K.
     
  21. PaulCo

    PaulCo New Member

    Joined:
    Aug 6, 2007
    Messages:
    5
    Likes:
    0
    Almost! MCLR (Master CLear Reset) needs to be OFF. The project does not use a Reset button.

    found out it was because the mclr jumper was on, when i changed to i/o then it worked when programmed with mclr off..
    excellent thank you..
    this will be a great addition to my gear..
     

Share This Page