AN3248
Capacitance measurement
Doc ID 17758 Rev 1
13/19
5 Capacitance
measurement
The ability to connect the COMP2 output to the input capture channels of the timers allows
the capacitance value to be measured. The principle is based on measuring the charge time
of a resistor-capacitor (RC) network as follows:
●
the charge time is measured
●
the charge resistor (R) is already known
●
the unknown capacitance (C) can be computed
Figure 10
shows the hardware connection of the RC network to an STM32L15xxx device.
Figure 10.
RC network connection for capacitance measurement
The capacitance measurement procedure consists of charging and discharging the
capacitor through the resistor. The charge/discharge function follows an exponential curve.
The charge function is given by
Example 1
.
Example 1
where:
●
V
DD
is the positive supply voltage
●
t is the time
●
T is the RC constant
Charging and discharging the RC network is ensured by the timer output compare channel
(TIMx OC) configured in PWM mode. The timer channel is connected to the resistor.
The input voltage is connected to the COMP2 non-inverting input while the threshold is
connected to the COMP2 inverting input. When the input voltage crosses the threshold, the
COMP2 output switches to high level and a capture event occurs saving the counter value.
Figure 11
shows the capacitance measurement.
#
2
4HRESHOLD
4)-X/#
34-,XXX
)NPUTVOLTAGE
#/-0
4)-X)#
AI
Input voltage
V
DD
1
t
T
⁄
–
(
)
exp
–
(
)
=