Measuring capacitor values
Bob Gagnon
Posts: 8
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
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:
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10