Single Slope Method: In this method, a constant current source is used to charge the capacitor. The time taken to charge the capacitor to a known voltage can be used to measure capacitance.
In the above circuit, the microcontroller first keeps the switch SW (could be a general purpose input/output or an external field effect transistor) closed, thus holding the capacitor in a discharged state. Then the microcontroller releases the switch. The constant current source charges the capacitor, and the voltage across the capacitor ramps up linearly. When the voltage across the capacitor crosses VREF, the comparator output goes high. The microcontroller uses the Timer/Counter to measure this time duration and then calculates C using below equation.
I = Current from the constant current source
V = Reference voltage of the comparator
t = Time taken to charge the capacitor to VREF
The accuracy of capacitance measurement with this method depends on the accuracy of the constant current source and reference voltage of the comparator.
Sigma Delta Modulator Method: In this method, a Sigma Delta modulator converts the capacitance into a digital bit stream where the density of the bit stream is directly proportional to the capacitance.
IDACMOD is a current source that charges a modulation capacitor CMOD. When the voltage across CMOD goes above VREF, output of the comparator goes low and turns off IDACMOD.
Cx is the capacitance to be measured. SW1 and SW2 along with Cx form a switch capacitor cell. SW1 and SW2 are driven out of phase by a clock source. When SW2 is turned ON, some charge is transferred from CMOD to Cx. When SW1 is turned on, Cx is discharged. Thus Cx, SW1 and SW2 together act as a resistor discharging CMOD. As CMOD is discharged, the voltage drops and when the voltage drops below the hysteresis of the comparator, output of the comparator goes high and turns on IDACMOD which starts the charging cycle. IDACCOMP is a fixed current source that can be used to increase the dynamic range of measurement.