View Full Version : Measuring capacitor values
09-16-2005, 04:44 AM
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?
09-16-2005, 05:12 AM
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.
09-17-2005, 01:45 AM
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
09-17-2005, 02:30 AM
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.
09-17-2005, 10:18 AM
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:
Cdut = 5311 ** result ' calibration determines the multiplier for **
DEBUG DEC Cdut, " nanofarads",CR
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.
09-17-2005, 12:45 PM
Nice explanation, thanks Tracy.
09-17-2005, 10:10 PM
Good stuff...thanks a lot to both of you. bob g.