Summary of Making a digital capacitance meter using PIC16F628A
This article details a digital capacitance meter project using the PIC16F628A microcontroller to measure values from 1 nF to 99 μF. The device operates by timing how long a capacitor takes to charge through a series resistor until it reaches half the supply voltage, detected via an internal analog comparator.
Parts used in the Digital Capacitance Meter:
- PIC16F628A microcontroller
- Analog Comparator 2 module
- TIMER2 module
- 2.2K resistors (for voltage divider)
- 330Ω resistor
- 22K resistor
- Cx (unknown capacitor)
Capacitors are one of the most common passive electrical components that are extensively used in all kinds of electronic circuits. In this project, we will discuss a technique of building a digital capacitance meter using a PIC microcontroller. This project can measure capacitance values from 1 nF to 99 μF, with a resolution of 1 nF. The technique is based on measuring the time elapsed when a capacitor is charged to a known voltage through a series resistor. The microcontroller used in this project is PIC16F628A.
Theory
This capacitance meter is based on the principle of charging a capacitor through a series resistor. In a series RC circuit, as shown in the figure below, the voltage across the capacitor increases exponentially as it charges. Lets assume that initially the capacitor was fully discharged. When Vin is applied across the RC circuit, the capacitor starts charging and consequently, the voltage (Vc) across it increases from 0 towards Vin in an exponential way, as shown in the right side of the figure. The equation provided in the figure describes how the voltage across the capacitor changes with time. If we know the time that is required for the capacitor to charge up to a known voltage then we can solve this equation for C, knowing the value of R.
The idea of measuring the time elapsed when the capacitor is charged from 0 to a known voltage can be implemented with any microcontroller. Here, we are using the PIC16F628A microcontroller, which has two built-in analog comparators. In this project, we are using the Analog Comparator 2 and TIMER2 modules to determine the time required by the capacitor to charge from 0V to 0.5Vin. The positive and negative inputs of the Analog Comparator 2 are externally accessible through RA2 and RA1 pins of PIC16F628A, respectively. In the figure shown below, two 2.2K resistors creates a voltage divider that sets the positive input (RA2) of the comparator to half of the voltage applied to RA0 pin. The negative input (RA1) of the comparator goes to the positive end of the capacitor through a 330Ω resistor. The resistor is used to discharge the capacitor prior to its measurement by setting RA1 low. When a voltage is applied to the RA0 pin, the capacitor (Cx), initially fully discharged, is charged through a 22K resistor. When the RA0 pin is just set high (say around 5V), the output of the comparator is high as the positive input of the comparator is at higher voltage (about 2.5V) than the negative input, which is close to 0V as the capacitor is fully discharged. Now the capacitor starts charging through the series resistor (22K) and when the voltage across it exceeds half of the voltage at RA0 pin, the comparator output is flipped to low. The comparator interrupt flag (CMIF) is set whenever there is a change in the output value of the comparator. The Timer2 module is used to compute the time elapsed between when RA0 is set high and the comparator output goes low. This is the time required by the capacitor to charge from 0V to half of the supply voltage.
For more detail: Making a digital capacitance meter using PIC16F628A
- What is the measurement range of this capacitance meter?
The project can measure capacitance values from 1 nF to 99 μF. - How does the technique determine capacitance values?
It measures the time elapsed when a capacitor charges to a known voltage through a series resistor. - Which microcontroller is used in this project?
The PIC16F628A microcontroller is used for this implementation. - What specific modules are utilized to determine charging time?
The Analog Comparator 2 and TIMER2 modules are used to compute the time required. - To what voltage level does the capacitor charge before detection?
The system detects when the capacitor charges from 0V to half of the supply voltage. - Which pins provide external access to the Analog Comparator inputs?
The positive and negative inputs are accessible through RA2 and RA1 pins respectively. - What function does the 330Ω resistor serve?
This resistor discharges the capacitor prior to its measurement. - How is the charging process initiated in the circuit?
A voltage is applied to the RA0 pin to start charging the capacitor through the 22K resistor.
