Background
Capacitors are one of the three fundamental, passive components that are used in nearly every electronic device out there. When a voltage is applied to a capacitor, it will store a charge proportional to the applied voltage. This proportion is called the capacitance. These factors are all connected by the simple relationship Q = C V. (Q is the charge, C the capacitance, and V the voltage.) When the applied voltage is removed, the charge doesn't disappear immediately, but rather decays gradually by running a current through whatever resistance is present between the capacitor's two leads.
While it's not a linear change, it's still a simple description, and we can exploit this characteristic to find the value of the capacitance, C. Assuming we know the resistance, all we need is to apply a voltage and time how long it takes for the voltage to decay to another known value.
Formulating the Capacitance Meter
The idea behind the instrument we are going to build is simple: we charge up a capacitor, then start the timer at the moment we start discharging. We stop the timer when the capacitor has discharged to a known point, then plug in the values into the formula.
Formula needed to calculate C from the MSP430 C is in μF if t is in μs and R in Ω. Alternatively, C is in nF if t is in μs and R is in kΩ |
The formula is easy to find. When we invert the Discharging Capacitor Equation, we find that our measured value of C depends on the time for discharge, the resistance, and the fraction of the starting voltage to the ending voltage. We can use Comparator_A+ to trigger the timer when we reach our chosen reference. For this tutorial, we'll discharge the capacitor until it reaches 1/4 Vcc, so that we use f = 4. This value is convenient, and minimizes any external components.
In the next tutorial, I'll show you how to set up the peripherals and suggest a few ways that you can read the obtained result with the MSP430. You may wonder how accurate this setup will be. The short answer is that it will be as accurate as you know the value of the resistor; if you use a 5% resistor, you'll be able to measure C to 5%. A 1% resistor tolerance will give you close to 1% for C, but at that point some of the other factors become more important. If you are interested, take a look at this description I've written on finding the error in the measurement.