Shop OBEX P1 Docs P2 Docs Learn Events
Measuring capacitor values — Parallax Forums

Measuring capacitor values

Bob GagnonBob Gagnon Posts: 8
edited 2005-09-17 14:10 in Learn with BlocklyProp
I'm trying to figure out how to measure the value of a capacitor using a BS2 and the RCTIME instruction. I have read and understand (I think) the Basic Stamp manual version 2.1. pages 351 thru 356 showing the relationship between RC time constant and RCTIME units. I thought maybe knowing the value of the resistor and the time required to discharge the capacitor using RCTIME I could manipulate the math to find the capacitance; but if it's possible, I can't do it. Is there a way·to use a BS2 to measure capacitance?

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-09-15 21:12
    Yes it is possible, the stamp documents should be enough to get it running. I would start by recreating thier example of 10kΩ and 0.1µF to verify you are getting numbers near thier numbers. You will likely find there is not one resisitor value suitable to measure cacitances from the picofarad to farad range (a 12 order of magnitude difference), so youll have to devise a means for using different valued resistors. The equation you will use is C = -(RCT * 2E-6)/(R*ln(1.4/5)) or C = 1.57E-6 * RCT/R. Where RCT is the time returned by RCTIME. This of course means your dealing with multiplying floating point numbers, coming up with a shortcut or table lookup will be needed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Bob GagnonBob Gagnon Posts: 8
    edited 2005-09-16 17:45
    Thanks for the help Paul, I wanted to experiment with table lookups anyway. This will give me more incentive to do it. I was also thinking about making up a table of capacitance values based on the linear relationship between the RCT, the fixed 10K resistor and the .1mfd; substituting the "unknown C in place of the .1mfd and using the LOOKUP or LOOKDOWN instruction. I can see where one resistor value would not be sufficient for several magnitudes of C values. bobg
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-09-16 18:30
    If you are smart about your choice of resistors, such as choosing decades (10, 100, 1k, 10k, ...), you can reuse the same lookup table and translate the result into a final value. For instance thier example of 10kΩ and 0.1µF produces RCT=635 on a BS2, if you were using a 1kΩ resistor and got RCT=635 your capacitor measured will be 1µF, similarly 100Ω -> 10µF, 100kΩ -> 10nF, 1MΩ -> 1nF and so forth.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2005-09-17 02:18
    The math you need to work out this kind of problem will most easily use the Stampese operators */ or **.

    Suppose you hook up an RCTIME circuit with a known accurate 0.1 microfarad capacitor and a nice stable resistor, and suppose the RCTIME value that comes out is 1234. This lets you calculate the constant in the following. We write 0.1 microfarad as 100 nanofarad, because the Stamp doesn't like to deal with fractions.

    100 = constant * 1234.

    The constant lumps together the resistor and the other constants, and solving, constant = 100/1234 = 0.081. In Stamp math, the ** operator approximates fractions by using an implicit denominator of 2^16.
    0.081 = 5311/65536.
    capacitance = RCtimeReading * 0.081 ' but the Stamp has to use 5311/65536 not 0.081

    Here is the routine you use on the Stamp:
    DO
       RCTIME 0,1,result
       Cdut =  5311 ** result    ' calibration determines the multiplier for **
       DEBUG DEC Cdut, " nanofarads",CR
       PAUSE 1000
      LOOP
    



    The result will be good for values from 0.01 to 1 uf with that resistor. No lookup table. Ranging can use another resistor as Paul noted. You can hook up a several reference resistors to the pin, and ground them (or not) to another Stamp pin to perform autoranging. You have to do one calibration for each resistor, but note that it is a one-point calibration for each.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-09-17 04:45
    Nice explanation, thanks Tracy.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Bob GagnonBob Gagnon Posts: 8
    edited 2005-09-17 14:10
    Good stuff...thanks a lot to both of you. bob g.
Sign In or Register to comment.