AN1014

AN1014
Measuring Small Changes in Capacitive Sensors
Author:
Kumen Blake and Steven Bible
Microchip Technology Inc.
INTRODUCTION
Target Audience
This application note is intended for hardware and
firmware design engineers that need to detect small
changes in capacitance.
Goals
• Detect small capacitance changes
(e.g., 0.001 pF)
• Estimate capacitances (i.e., 10 pF to 1 nF)
• Use minimal number of external components
• Create simple firmware solution
• Show design trade-offs and alternative circuits
SWITCHED CAPACITOR SOLUTION
This section describes a circuit that is appropriate for
measuring small changes in capacitance (e.g.,
0.001 pF) for relatively small capacitors (i.e., 10 pF to
10 nF).
Switched Capacitor Preliminaries
Figure 1 shows the general situation when a grounded,
switched (sensing) capacitor (CSEN) transfers energy
from a voltage source (VS) to an output integrating
(storage) capacitor (CINT). Each time one of the
switches closes, charge is transferred to, or from, CSEN
to equalize the voltages. The period of a complete
switching cycle is TSW.
φ2
IS
φ1
VSEN
VS
φ1
CSEN
IINT
VINT
φ2
CINT
Description
This application note shows a switched capacitor circuit
that uses a PICmicro® microcontroller, and minimal
external passive components, to measure small
changes in capacitance. The values are very repeatable under constant environmental conditions.
The design is measured to verify the theory and design
choices. Some design alternatives and modifications
are explored. Information on the circuit board and
firmware used in the measurements is included.
References to documents that treat these subjects in
more depth and breadth have been included in the
“References” section.
FIGURE 1:
Diagram of a Grounded,
Switched Capacitor.
CINT is chosen to be much larger than CSEN, so VINT
can be considered to be approximately constant during
any one switching cycle. The charges transferred per
time (QS/TSW and QINT/TSW) can be approximated, on
the average, as currents flowing between two voltages
(VS and VINT). Thus, the switches and CSEN can be
modeled as a series resistance (RSEN in Equation 1
and Figure 2):
EQUATION 1:
T SW
R SEN ≈ -----------C SEN
Since:
IS
IINT
=
QS / TSW
≈
(VS – VSEN) CSEN / TSW
=
QINT / TSW
≈
(VSEN – VINT) CSEN / TSW
When switches close:
(VS – VSEN)
© 2005 Microchip Technology Inc.
≈
(VSEN – VINT)
DS01014A-page 1
AN1014
IS
VS
The circuit has two measurement steps:
RSEN IINT
VINT
CINT
FIGURE 2:
Equivalent Model for the
Grounded, Switched Capacitor.
• First Measurement Step (Switching)
- CSEN is used as a switched capacitor
resistor, which causes the voltage, VINT, to
exponentially approach VDD (starting at 0V)
• Second Measurement Step (Calibration)
- RCAL is grounded, causing VINT = VSEN to
exponentially approach 0V
FIRST MEASUREMENT STEP (SWITCHING)
Hardware
CIRCUIT
Figure 3 shows the circuit used to measure a
capacitive sensor. The PICmicro® microcontroller
provides the timing, internal voltage reference and
comparator to measure R-C step response times.
VDD
5.0V
C1
100 nF
EQUATION 3:
U1
PIC16F684
P1
Comparator
P2
VREF
P3
P4
FIGURE 3:
The simplified model of the first measurement step is
described in Equation 3 and Figure 4. CSEN is used as
a switched capacitor resistor, and CINT is the
integrating capacitor. Pin P3 is put in a high-impedance
state so that RCAL doesn’t affect the measurements.
The voltage across CINT (VINT) starts at 0V (after a
preliminary discharge time) and exponentially
approaches VDD. The comparator detects when VINT
reaches an upper reference voltage (VRH), and the
microcontroller measures the number of switching
periods (k1 periods of length TSW) needed to reach that
point.
V
VP1
INT
= 0V,
≈ V DD ( 1 – e
VP2
VSEN
VP3
RCAL
3 kΩ
VP4
+
VINT
–
-t/ τ 1
t<0
),
ln ( V
⁄ (V
– V ))
DD
DD
RH
k 1 ≈ --------------------------------------------------------------C SEN ⁄ C INT
CSEN
Where:
CINT
1.0 μF
CSEN
<<
CINT
RSEN
=
TSW / CSEN
τ1
=
RSENCINT
TSW
=
Switching Period
VDD
5.0V
Capacitor Sensor Circuit.
The voltages in the diagram are related as follows:
EQUATION 2:
V SEN = VP1 = V P2
V
INT
= V
SEN
–V
P1 = RC4
P2 = RC1
P3 = RC3
P4 = RC2
DS01014A-page 2
Comparator
P4
The pin assignments used on the PCB in Appendix B:
“Circuit Board” are as follows:
•
•
•
•
t≥0
VREF
FIGURE 4:
VINT
RSEN
CINT
1.0 μF
Equivalent Model for VINT.
The PICmicro® microcontroller produces a switch clock
(CKSW) with period TSW. This clock signal alternately
selects between two cycles: the charging cycle and the
sharing cycle. The resistor, RCAL, is left floating, so it
doesn’t affect this measurement. Table 1 gives the pin
states for the two cycles during a typical switching
© 2005 Microchip Technology Inc.
AN1014
period (TSW). Figure 5 shows typical waveforms for the
first measurement cycle (see Figure 3 for the voltages
shown). VP4 shows an R-C step response because
RCAL interacts with the I/O port pin capacitance at P4.
TABLE 1:
PIN STATES
Pin States
Cycles
Charging Cycle
Sharing Cycle
Note 1:
2:
3:
4:
P1
P2
P3
P4
1
input
hi-Z
hi-Z
hi-Z
input
hi-Z
0
The Charge Cycle charges CSEN to the voltage
VDD.
The Share Cycle shares the charge between
CSEN and CINT, which slowly increases VINT.
P2 is high impedance, and is always connected
to the comparator.
Not shown are transition states between the
cycles; see Table 3.
Charging Cycle
Sharing Cycle
“switching count”). The time needed for VINT to reach
VRH is k1TSW. As will be shown later, k1 is a measure of
the ratio CSEN / CINT.
Figure 6 and Figure 7 illustrate the sequence
discussed above. Notice how the integrator voltage
(VINT) looks like a series of stair steps due to the digital
control provided by the microcontroller. When CINT is
very large (compared to CSEN), these steps are very
small, and the waveform is well approximated by an
R-C step response. VSEN = VDD during the first part of
the switching cycle (charging CSEN), and VSEN = VINT
during the second part of switching cycle (sharing
charge with CINT).
CINT is set much lower in these figures than it would be
for a practical circuit in order to make the switch
response easier to see. The parameters used to
produce these figures are:
•
•
•
•
CINT = 1.0 nF
CSEN = 100 pF
TSW = 5.0 μs
VDD = 5.0V
CKSW
VDD
VSEN
VINT (V)
TSW
0V
VDD
VP3
6.0
5.5
5.0
4.5
4.0
3.5
3.0
2.5
2.0
1.5
1.0
0.5
0.0
VDD
VRH = 3.594V
k1 = 14
Actual Waveform
R-C Approximation
0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80
0V
VP4
1st Measurement Step
REQ = 50 kΩ
Time (μs)
FIGURE 6:
First Measurement Step
Example – VINT Voltage.
0V
VINT
0V
R-C
Approx.
to VINT
FIGURE 5:
Timing.
VDD
0V
First Measurement Step
Many switching periods (TSW) are needed to increase
VINT until it reaches the higher reference voltage (VRH).
The microcontroller counts the number of switching
periods (TSW) needed for VINT to increase from VRL to
VRH; the result is placed in the counter k1 (the
© 2005 Microchip Technology Inc.
VSEN (V)
VDD
6.0
5.5
5.0
4.5
4.0
3.5
3.0
2.5
2.0
1.5
1.0
0.5
0.0
1st Measurement Step
VRH = 3.594V
k1 = 14
0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80
Time (μs)
FIGURE 7:
First Measurement Step
Example – VSEN Voltage.
DS01014A-page 3
AN1014
The parasitic input capacitances (CPAR) at each of the
microcontroller input pins, P1–P3, are in parallel with
CSEN. The parasitic capacitance at pin P4 (also CPAR)
produces a current in the same direction as CSEN, and
sees the same voltage change during switching as the
other parasitic capacitances, so it can also be
considered to be in parallel with CSEN. Thus, for greater
accuracy for small CSEN, it can be replaced by the sum
(CSEN + 4CPAR) in all of the equations for the first
measurement step. RCAL is chosen so that the time
constant, RCALCPAR, is much shorter than the switching period, TSW. The equation for k1 becomes:
EQUATION 4:
ln ( V DD ⁄ ( V DD – V RH ) )
k 1 ≈ -------------------------------------------------------( C SEN + 4C PAR ) ⁄ C INT
EQUATION 5:
INT
=
Comparator
VREF
FIGURE 8:
Calibration Cycle
Note 1:
2:
P1
P2
P3
P4
hi-Z
input
0
0
The Calibration Cycle discharges CINT and
CSEN, through RCAL to ground, until it reaches
the voltage VRL.
P2 is high impedance, and is always connected
to the comparator.
Figure 9 illustrates the measurement step discussed
above. CINT is set much lower in this figure than it
would be for a practical circuit in order to make the
waveform easier to interpret. The parameters used to
produce this figure are:
CINT = 1.0 nF
CSEN = 100 pF
TCLK = 0.5 μs
VDD = 5.0V
5.0
4.5
4.0
3.5
3.0
2.5
2.0
1.5
1.0
0.5
0.0
2nd Measurement Step
VRL = 1.250V
k2 = 8
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
= V
= V
,
t<0
SEN
RH
-t/τ2
= V RH e
, t≥0
R CAL ( C INT + C SEN ) ln ( VRH ⁄ VRL )
k ≈ -----------------------------------------------------------------------------------------------2
T
CLK
Where:
τ2
Cycles
VINT = VSEN (V)
The model of the second measurement step is
described in Equation 5 and Figure 8. RCAL, CINT and
CSEN are all grounded (connected in parallel), and no
energy is transferred to these parts. The voltage, VINT,
starts at a high value (VRH) and decays exponentially
towards ground. The comparator detects when VINT
has reached a low value (VRL). The microcontroller
measures the time elapsed (k2 instruction periods of
length, TCLK).
PIN STATES
Pin States
•
•
•
•
SECOND MEASUREMENT STEP
(CALIBRATION)
V
TABLE 2:
RCAL(CINT + CSEN)
VINT = VSEN
RCAL
3 kΩ
0.1%
CINT
1.0 μF
CSEN
Time (μs)
FIGURE 9:
Second Measurement Step
Example – VINT = VSEN Voltage.
The parasitic input capacitances (CPAR) at each of the
microcontroller input pins, P1–P3, are in parallel with
CSEN. The parasitic capacitance at pin P4 is shorted to
ground. Thus, for greater accuracy for small CSEN, it
can be replaced in all of the equations for the second
measurement step by the sum (CSEN + 3CPAR). The
equation for k2 becomes:
EQUATION 6:
R CAL ( C INT + C SEN + 3C PAR ) ln ( VRH ⁄ V RL )
k 2 ≈ ------------------------------------------------------------------------------------------------------------T CLK
Model for VINT.
The PICmicro microcontroller counts the number of its
internal instruction cycles (CLK, with period, TCLK)
needed for VINT to decrease from VRH to VRL. This
result is placed in the counter, k2 (the “calibration
count”). The time needed is k2TCLK. As will be shown
later, k2 is a measure of the sum CINT + CSEN; it is used
to correct for errors in CINT (process variation, temperature drift, aging, etc.). Table 2 gives the pin states for
this measurement step.
DS01014A-page 4
© 2005 Microchip Technology Inc.
AN1014
The resolution for CSEN and CINT can be made higher
by increasing CINT and RCAL. RCAL needs to be small
enough so that the parasitic capacitance at pin P3 of U1
can settle in time, (i.e., 10RCALCPAR < TSW/2).
Equation 7 shows approximations to the normalized
resolution for these capacitances (ΔCINT/CINT and
ΔCSEN/CSEN) as a function of a change in the number
of counts (Δk1 and Δk2). Figure 10 and Figure 11 show
the same results in graphic form for a design optimized
for CSEN near 180 pF (and CPAR ≈ 7.7 pF). Notice that
the Δk1 increment is -1 in Figure 10; this means CSEN
decreases when k1 increases.
1.E-02
10-2
Normalized CSEN Resolution
As a general rule, the higher the counts k1 and k2 are,
the greater the resolution of the measured CINT and
CSEN. Larger CINT produces larger k2 counts and better
resolution. Smaller CSEN produces larger k1 counts
and greater resolution; this is opposite the behavior of
R-C decay timing methods [7], and is a significant
advantage for this method. When CSEN becomes
smaller than 4CPAR, however, its resolution becomes
worse.
ΔCSEN / CSEN
CPAR ≈ 7.7 pF
1.E-03
10-3
1.E-04
10-4
10-5
1.E-05
1p
1.E-12
Δk1 = –1,
Δk2 = 0
10p
1.E-11
100p
1.E-10
CSEN (F)
Δk1 = 0,
Δk2 = 1
1n
1.E-09
10n
1.E-08
FIGURE 10:
Example – Normalized CSEN
Resolution (ΔCSEN/CSEN) vs. Δk1 and Δk2.
-2
1.E-02
10
'
CINT / CINT
CPAR |7.7 pF
Normalized CINT Resolution
Measurement Resolution
-3
1.E-03
10
'
k1 = 0,
'
k2 = 1
1.E-04
10-4
EQUATION 7:
ΔC INT Δk 1 C SEN + 4C PAR
---------------- ≈ --------- • ------------------------------------ ,
C INT
C INT
k1
ΔC INT Δk 2
---------------- ≈ --------- ,
C INT
k2
Δk 2 = 0
Δk 1 = 0
-5
10
1.E-05
1p
1.E-12
10p
1.E-11
100p
1.E-10
CSEN (F)
1n
1.E-09
10n
1.E-08
FIGURE 11:
Example – Normalized CINT
Resolution (ΔCINT/CINT) vs. Δk1 and Δk2.
ΔC SEN Δk 1 C SEN + 4C PAR
----------------- ≈ --------- • ------------------------------------ ,
C SEN
k1
C SEN
Δk 2 = 0
ΔC SEN Δk 2 C SEN + 4C PAR
----------------- ≈ --------- • ------------------------------------ ,
C SEN
k2
C SEN
Δk 1 = 0
© 2005 Microchip Technology Inc.
'
k1 = 1,
k2 = 0
'
DS01014A-page 5
AN1014
FIRMWARE
The firmware discussed in this section is designed for
the circuit in Appendix B: “Circuit Board”, and is
implemented with the code shown in Appendix C:
“Firmware”.
Detailed Algorithm
Table 3 shows the algorithm in detail, including the
microcontroller’s pin states. State 3 and State 4 are the
first measurement step (the two parts to the switching
TABLE 3:
The microcontroller pin assignments in Appendix B:
“Circuit Board” are:
•
•
•
•
P1 = RC4
P2 = RC1
P3 = RC3
P4 = RC2
ALGORITHM
Circuit State
1.
cycle), and State 5 is the second measurement step.
The initialization, calculation, output and sleep states
are needed for complete functionality.
Initialize
Pin States
P1
P2
P3
P4
—
—
—
—
Action
Initialize PICmicro® microcontroller
Configure hardware settings
Initialize counts (k1 and k2) to zero (Note 3), (Note 4)
2.
Discharge
3.
Charge
0
Discharge CINT and CSEN to 0V
0
input
0
hi-Z
input
hi-Z
hi-Z Quick Transition (avoid crowbar current)
1
input
hi-Z
hi-Z Charge CSEN to VDD
Allow time for capacitors to discharge to 0V
Allow time for CSEN to charge
Increment k1
4.
Share Charge
hi-Z
input
hi-Z
hi-Z
input
hi-Z
hi-Z Quick Transition (avoid crowbar current)
0
Share charge between CSEN and CINT
Allow time for CINT and CSEN to share charges
IF (VP2 < VRH) THEN (GOTO State 3) (Note 1)
5.
Calibrate
hi-Z
input
0
0
Calibrate (CINT + CSEN) value using RCAL
6.
Calculate
(Note 5)
0
input
0
0
Calculate capacitances
(increment k2 at each TCLK period) UNTIL (VP2 < VRL) (Note 2)
(discharge CINT and CSEN to 0V)
Calculate AR = CSEN/CINT from k1 and circuit values
Calculate AS = CINT + CSEN from k2 and circuit values
Calculate CINT and CSEN
7.
Output
0
input
0
0
Output results (k1, k2, CINT and CSEN)
(discharge CINT and CSEN to 0V)
8.
Sleep
0
input
0
0
Put circuit into Sleep mode
(continue to discharge CINT and CSEN to 0V)
Power Down
Stay in sleep for fixed amount of time (e.g., 1 minute)
Power Up
GOTO State 1
Note 1:
2:
3:
4:
5:
VRH is the upper VREF value used by the comparator (0.6875VDD = 3.438V).
VRL is the lower VREF value used by the comparator (0.25VDD = 1.25V).
k1 is the “share charge cycles” counter; it increments once for each time states 3 and 4 are executed (TSW = 6.5).
k2 is the “calibrate cycles” counter; it increments once for each PICmicro instruction cycle (TCLK = 0.5 μs).
The firmware in Appendix C: “Firmware” does not include the calculation of CINT and CSEN. It outputs k1 and k2 via the
SPI bus, and leaves the conversion to capacitance to another routine written by the user.
DS01014A-page 6
© 2005 Microchip Technology Inc.
AN1014
Flow Chart
Figure 12 shows the flow chart for the firmware in
Appendix C: “Firmware”, which is an abbreviated
version of the algorithm in Table 3.
Main
Initialize Variables
B
Configure comparator reference
to VRH = 0.6875VDD
A
Configure comparator reference
to VRL = 0.25VDD
Configure comparator module
Connect RCAL to ground
Discharge all capacitors
(ground all I/O pins)
Start Timer1
Long Delay
Is
VINT > VRL
?
Charge CSEN
(to VDD)
Yes
No
Increment Capacitance Count
(k1)
Share Charge
(between CSEN and CINT)
Stop Timer1
Send Timer1 Count
(k2) out via SPI
Is
VINT > VRH
?
No
B
Yes
Send Capacitance Count
(k1) out via SPI
A
FIGURE 12:
Flow Chart.
© 2005 Microchip Technology Inc.
DS01014A-page 7
AN1014
Capacitance Extraction Equations
The extraction equations in this section are not
implemented in the firmware shown in Appendix C:
“Firmware”. It is up to the user to write a routine that
accepts k1 and k2, then calculates CINT and CSEN.
The extraction equations for CINT and CSEN are:
EQUATION 8:
Assumption:
CINT >> CSEN + 4CPAR
Pre-calculated Constants:
V DD
B 1 = ln ⎛ ---------------------------⎞
⎝ V DD – V RH⎠
T CLK
B 2 = -------------------------------------------------RCAL ln ( V RH ⁄ VRL )
These measurements were made with the board
discussed in Appendix B: “Circuit Board”.
Measured Circuit Parameters
The measured circuit parameters are:
• CINT = 1.082 μF
• CPAR = 7.7 pF
• RCAL = 3.013 kΩ (by the HP3457A)
Appendix A: “Measured Results” gives a complete
list of measured k1, k2 and CSEN values.
Oscilloscope Plots
VSEN was measured with an oscilloscope; the results
are plotted in Figure 13. A closer look at the calibration
step (R-C decay) is shown in Figure 14.
Extraction Equations:
AR = B1 / k1
AS = B2 k2
A S + C PAR
C INT ≈ -------------------------1 + AR
≈ AS,
(Simplified formula)
C SEN ≈ A R CINT – 4C PAR
The accuracy of these extractions depend on:
• The measurement resolution (k1 and k2)
• Estimating the correct value for CPAR
• Keeping CSEN in the recommended range of
values
FIGURE 13:
CSEN = 220 pF.
VSEN Time Response with
The main difficulty in implementing this algorithm is
caused by the division needed to calculate AR. The
references [9-12] discuss general division routines.
Reference [13] discusses one approach to using piecewise linear approximation tables in microcontrollers.
MEASURED RESULTS
Setup
Measurements were made with the following nominal
circuit design parameters:
•
•
•
•
•
•
•
•
CINT = 1.0 μF
CSEN = 10 pF to 10 nF
RCAL = 3.01 kΩ
TSW = 5.0 μs
TCLK = 0.5 μs
VDD = 5.0V
VRL = 1.250V
VRH = 3.438V
DS01014A-page 8
FIGURE 14:
VSEN Time Response Detail
with CSEN = 220 pF.
Measurement Resolution
Figure 15 shows how well the extracted values of CSEN
(including the correction for CPAR) match the values
produced by the HP4285A Precision LCR Meter. CPAR
was estimated to be 7.6 pF.
© 2005 Microchip Technology Inc.
AN1014
1n
1.E-09
• Increase accuracy
- Increase TSW for better settling of VSEN and
VP3
- Improve VREF accuracy by measuring the
levels, VRL and VRH, with an ADC internal to
the microcontroller
100p
1.E-10
Other Circuits
100n
1.E-07
Extracted CSEN (F)
10n
1.E-08
10p
1.E-11
10p
1.E-11
100p
1.E-10
1n
1.E-09
10n
1.E-08
CSEN (F)
FIGURE 15:
Capacitances.
Extracted Sensor
Tests on the bench verified the excellent resolution of
this method. The results were very consistent over a
short period of time.
Comparing measurements over a long period of time
gave results that were not as consistent. It appears that
drift with temperature and capacitor dielectric
absorption may cause the inconsistencies.
Measurement Accuracy
The measurement accuracy is not as good as that
produced by other circuits. The errors seen on the
bench were on the order of ±10 pF and ±10%.
The parasitic capacitance value (about 7.7 pF)
significantly affected extracted CSEN values when the
latter was smaller (more than 10% error below 300 pF).
The remaining error, at low CSEN values, that can be
seen in Figure 15 are caused by leakage currents at
the microcontroller pins. The smaller CSEN is, the
greater this effect is.
Because the physical mechanisms that degrade the
measurement accuracy vary significantly with process,
temperature, time and other environmental variables, it
is difficult to correct these errors.
DESIGN ALTERNATIVES
Possible Modifications
A list of modifications to the design follows:
• Increase resolution (increase k1 and k2)
- Decrease TCLK
- Increase CINT
- Increase RCAL
• Simplify the circuit and firmware
- Use simpler extraction equations (e.g., ignore
CPAR)
- Remove RCAL and the second measurement
step (use the nominal value of CINT in the
extractions)
© 2005 Microchip Technology Inc.
One common approach using a microcontroller is to
measure the R-C step response time [7]. Its resolution
is roughly constant, so it works well for larger
capacitances. Its resolution for small capacitances is
poor.
Another common approach is to use the capacitor to
set an oscillator’s frequency. 555 timer oscillators are
quite common [8]. They suffer from parasitic
capacitance to ground, and the fact that 555 timers
from different manufacturers can be quite different.
State variable oscillators using op amps are also used
for applications demanding higher precision [3, 6].
They are more parasitic insensitive, but use many more
external components.
The application note, AN990 [4], gives an overview of
analog sensor conditioning circuits. It includes
additional circuits for capacitive sensors.
SUMMARY
This application note gives hardware and firmware
design engineers a circuit that detects small changes in
capacitance (small values). This circuit gives
consistent results over a short time frame, especially
when the environment is not rapidly changing.
The design is simple and low cost; it only needs a
PICmicro microcontroller and very few passive
components. It uses the microcontroller to implement a
switched capacitor circuit that gives more resolution to
small capacitances.
Measurements of an actual circuit illustrate the
operation of this circuit, and its resolution.
A discussion of alternate circuits help the designer
select the best circuit for an application. Suggested
design modifications help the designer choose a more
appropriate design point.
Information on the circuit board and firmware used in
the measurements is included in the appendicies.
DS01014A-page 9
AN1014
REFERENCES
Math Routines
General Sensors
[9] AN526, “PIC16C5X / PIC16CXXX Math Utility
Routines”, Amar Palacherla, Microchip Technology Inc., 1997.
[1] “The OMEGA® Made in the USA Handbook™”,
Vol. 1, OMEGA Engineering, Inc., 2002.
[2] “The OMEGA® Made in the USA Handbook™”,
Vol. 2, OMEGA Engineering, Inc., 2002.
[3] AN866, “Designing Operational Amplifier Oscillator
Circuits For Sensor Applications”, Jim Lepkowski;
Microchip Technology Inc., DS00866, 2003.
[4] AN990, “Analog Sensor Conditioning Circuits – An
Overview”, Kumen Blake, Microchip Technology
Inc., DS00990, 2005.
[5] AN512, “Implementing Ohmmeter/Temperature
Sensor”, Doug Cox; Microchip Technology Inc.,
DS00512, 1997.
[6] AN895 “Oscillator Circuits For RTD Temperature
Sensors”, Ezana Haile and Jim Lepkowski;
Microchip Technology Inc., DS00895, 2004.
Capacitive Sensors
[7] AN611, “Resistance and Capacitance Meter Using
a PIC16C622”, Rodger Richey; Microchip
Technology Inc., DS00611, 1997.
PIC®
[8] “Measure Relative Humidity With a
MCU”,
Ricardo Jimenez and Claudia Angulo, Design
Briefs, Electronic Design, p. 79-80, March 17,
2005.
DS01014A-page 10
[10] AN544, “Math Utility Routines”, Frank J. Testa,
Microchip Technology Inc., 1997.
[11] AN575, “IEEE 754 Compliant Floating Point
Routines”, Frank J. Testa, Microchip Technology
Inc., 1997.
[12] AN617, “Fixed Point Routines”, Frank J. Testa,
Microchip Technology Inc., 1996.
[13] AN942, “Piecewise Linear Interpolation on PIC12/
14/16 Series Microcontrollers”, John Day and
Steven Bible; Microchip Technology Inc., 2004.
Data Sheets
[14] MCP6001/2/4 Data Sheet, “1 MHz, Low-Power
Op Amp”, Microchip Technology Inc., DS21733,
2005.
[15] PIC16F684 Data Sheet, “14-Pin Flash-Based,
8-Bit CMOS Microcontrollers with nanoWatt
Technology”,
Microchip
Technology
Inc.,
DS41202, 2004.
[16] PIC16C745/765 Data Sheet, “8-Bit CMOS
Microcontrollers with USB”, Microchip Technology
Inc., DS41124, 2000.
© 2005 Microchip Technology Inc.
AN1014
APPENDIX A:
MEASURED
RESULTS
Table A-1 shows the results of measuring discrete
capacitors with this method. The table shows the
nominal values chosen, the capacitance values
measured by a HP4285A LCR meter and the resulting
counts produced by the circuit described in Appendix
B: “Circuit Board”. This data is shown in Figure 15.
TABLE A-1:
LISTING OF MEASURED
RESULTS
Counts
(Note 1)
CSEN
(F)
Extracted CSEN
(F) (Note 2)
Nominal
Measured
k1
with
without
0p (open)
—
28,688
47.9p
17.1p
15p
15.3p
22,880
60.0p
29.3p
22p
21.4p
21,111
65.0p
34.3p
27p
28.0p
19,492
70.4p
39.7p
33p
33.2p
18,425
74.5p
43.8p
39p
38.5p
17,306
79.3p
48.6p
47p
48.2p
15,592
88.1p
57.3p
56p
52.5p
14,944
91.9p
61.2p
68p
68.2p
13,024
105.4p
74.7p
100p
97.6p
10,547
130.2p
99.5p
150p
150.4p
7,644
179.6p
148.9p
180p
176.6p
6,716
204.4p
173.7p
220
211.0p
5,792
237.0p
206.3p
270p
271.6p
4,632
296.4p
265.7p
330p
318.0p
3,920
350.2p
319.5p
470p
448.4p
2,863
479.4p
448.7p
680p
656.0p
1,976
694.5p
663.8p
1.0n
0.991n
1,351
1.015n
0.985n
1.5n
1.406n
952
1.441n
1.410n
2.2n
2.202n
609
2.250n
2.219n
2.7n
2.550n
488
2.807n
2.776n
3.3n
3.715n
338
4.048n
4.017n
3.9n
4.013n
313
4.370n
4.339n
5.6n
5.874n
215
6.350n
6.319n
6.8n
6.915n
182
7.493n
7.462n
10n
9.42n
126
10.79n
10.76n
Note 1:
2:
For simplicity, the value of k2 was
assumed to be constant and equal to the
value measured at 100 pF (k2 = 6,890).
The extracted CSEN is shown with
(ignoring 4CPAR) and without (including
4CPAR) subtracting 4CPAR = 30.7 pF.
© 2005 Microchip Technology Inc.
DS01014A-page 11
AN1014
APPENDIX B:
CIRCUIT BOARD
B.1
Schematic
The PCB described in this appendix was used for the
measurements in “Measured Results”. PCB design
files are available for downloading from Microchip’s
web site (www.microchip.com):
The components have reasonable tolerances since this
circuit is not accurate. R_CAL is 3.01 kΩ so that the
RCALCSEN time constant is about 23 ns, which is
much less than TCLK = 500 ns.
• AN1014.zip (Contains all of the following files)
- AN1014_SCH.dxf (schematic)
- AN1014_PL1.bmp (top silk-screen plot)
- AN1014_PL2.bmp (top metal plot)
- AN1014_PL3.bmp (bottom metal plot)
- AN1014_GER.zip (zipped Gerber files)
The microcontroller pin assignments are:
•
•
•
•
P1 = RC4
P2 = RC1
P3 = RC3
P4 = RC2
+5V
C1
RA3
0.1μF
U1
PIC16F684/P
RA3
RC4
RC3
1
2
3
4
5
6
7
VDD
VSS
RA0/AN0/C1IN+/ICSPDAT
RA5/T1CKI/OSC1/CLKIN
RA4/T1G/OSC2/AN3/CLKOUT RA1/AN1/C1IN-/VREF/ICSPCLK
RA2/AN2/COUT/T0CLKI/INT
RA3/MCLR/VPP
RC5/CCP1/P1A
RC0/AN4/C2IN+
RC1/AN5/C2INRC4/C2OUT/P1B
RC2/AN6/P1D
RC3/AN7/P1C
14
13
12
11
10
9
8
RA0
RA1
RA0
RA1
RC1
RC2
5
6
7
8
9
10
11
12
13
14
RA5
RA4
RA3
RC5
RC4
RC3
RA0
RA1
RA2
RC0
RC1
RC2
PICkit™ 1 Flash Starter Kit
Expansion Header J3
P1
1
2
3
4
C4
1μF
RC1
1
RC4
R_CAL
3.0kΩ
0.1%
C_INT
0.1μF
C_SEN
2
RC3
RC2
NOTE: All Resistors are 1%
FIGURE B-1:
DS01014A-page 12
Schematic.
© 2005 Microchip Technology Inc.
AN1014
B.2
Layout Plots
FIGURE B-2:
Top Silk-screen Layer.
FIGURE B-3:
Top Metal Layer.
© 2005 Microchip Technology Inc.
FIGURE B-4:
Bottom Metal Layer.
DS01014A-page 13
AN1014
B.3
Bill of Materials (BOM)
TABLE B-1:
Qty
Reference
BILL OF MATERIALS
Description
Manufacturer
Part Number
1
C_SEN
Ceramic Disk or Monolithic Capacitor, Leaded,
0.200” spacing, 10 pF to 1 nF
—
—
1
C1
Ceramic Capacitor, 100 nF, 50V, 10%, X7R, 0805
SMD
Kemet
C0805C104K5RACTU
2
C_INT, C4
Ceramic Capacitor, 1.0 μF, 16V, 10%, X7R, 0805
SMD
Kemet
C0805C105K5RACTU
1
P1
Header, 1 × 14, 0.100" Pitch, Vertical, Gold
Molex/Waldom
Electronics
22-28-4143
1
R_CAL
Chip Resistor, 3.01 kΩ, 1/8W, 1%, 0805 SMD
Yageo America
9C08052A3011FKHFT
1
U1
PIC16F684, PICmicro® microcontroller, 14-pin,
20 MHz, PDIP-14
Microchip
Technology Inc.
PIC16F684-I/P
2
(for C_SEN) Pin Receptacle, 0.015” to 0.025” dia., 0.060” Hole
dia.
Mill-Max®
0669-0-15-15-30-27-10-0
1
(for U1)
IC Socket, 14-pin DIP, Gold Plated, 0.300", Low
Profile
Mill-Max®
115-93-314-41-003000
1
—
Bare Printed Circuit Board
—
—
Note 1:
The capacitor, C_SEN, is an arbitrary value inserted into the C_SEN socket pins by the user. The user
may try values between 0 pF (open) to 1 μF to observe the circuit’s operation, if so desired.
DS01014A-page 14
© 2005 Microchip Technology Inc.
AN1014
Software License Agreement
The software supplied herewith by Microchip Technology Incorporated (the “Company”) is intended and supplied to you, the
Company’s customer, for use solely and exclusively with products manufactured by the Company.
The software is owned by the Company and/or its supplier, and is protected under applicable copyright laws. All rights are reserved.
Any use in violation of the foregoing restrictions may subject the user to criminal sanctions under applicable laws, as well as to civil
liability for the breach of the terms and conditions of this license.
THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR
SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
APPENDIX C:
FIRMWARE
The firmware file (AN1014.asm) is available for downloading from Microchip’s web site at www.microchip.com.
TABLE C-1:
MAIN ROUTINE
;---------------------------------------------------------------------;---------------------------------------------------------------------; Main Program
;---------------------------------------------------------------------;---------------------------------------------------------------------MAIN
;---------------------------------------; Initialize PICmicro
;---------------------------------------call
INITIALIZE
;---------------------------------------; Initialize Variables
;---------------------------------------bcf
FLAG, TRIP
; clear tick counter trip flag.
bsf
INTCON, GIE
; enable global interrupts
MAINLOOP
; configure comparator module and voltage reference
bsf
;
movlw
movwf
STATUS, RP0
76543210
b'10001110'
VRCON
; ---- Select Bank 1 -----
bcf
;
movlw
movwf
STATUS, RP0
76543210
b'00000010'
CMCON0
; ---- Select Bank 0 -----
clrf
clrf
clrf
C_COUNT_L
C_COUNT_H
C_COUNT_U
; clear C_SEN / C_INT ratio count
© 2005 Microchip Technology Inc.
; configure comparator reference
;
CVref Enabled; VRR High Range; VR=0x14
; configure comparator module
DS01014A-page 15
AN1014
TABLE C-1:
MAIN ROUTINE (CONTINUED)
; remove all electrical charges (ground all I/O pins)
bsf
STATUS, RP0
; ---- Select Bank 1 -----
;
;
;
;
;
movlw
movwf
/------------- COM (RC4) digital output
|/------------ R_CAL (RC3) digital output
||/----------- C_INT (RC2) digital output
|||
xx543210
b'00000011'
TRISC
bcf
STATUS, RP0
;
;
;
;
;
movlw
movwf
/------------- COM (RC4) ground
|/------------ R_CAL (RC3) ground
||/----------- C_INT (RC2) ground
|||
xx543210
b'00000000'
PORTC
; ---- Select Bank 0 -----
; long delay to ensure all charges are removed
DELAY_LOOP
btfss
goto
bcf
FLAG, TRIP
DELAY_LOOP
FLAG, TRIP
; no, loop
; clear tick counter trip flag.
; charge C_SEN
CHARGE
bsf
STATUS, RP0
; ---- Select Bank 1 -----
;
;
;
;
;
movlw
movwf
/------------- COM (RC4) digital output
|/------------ R_CAL (RC3) digital input (high impedance)
||/----------- C_INT (RC2) digital input (high impedance)
|||
xx543210
b'00001111'
TRISC
bcf
STATUS, RP0
;
;
;
;
;
movlw
movwf
/------------- COM (RC4) Vdd (digital output)
|/------------ R_CAL (RC3) (high impedance)
||/----------- C_INT (RC2) (high impedance)
|||
xx543210
b'00010000'
PORTC
; ---- Select Bank 0 -----
; share charges between C_SEN and C_INT
bsf
STATUS, RP0
;
;
;
;
;
movlw
movwf
/------------- COM (RC4) digital input (high impedance)
|/------------ R_CAL (RC3) digital input (high impedance)
||/----------- C_INT (RC2) digital output
|||
xx543210
b'00011011'
TRISC
DS01014A-page 16
; ---- Select Bank 1 -----
© 2005 Microchip Technology Inc.
AN1014
TABLE C-1:
MAIN ROUTINE (CONTINUED)
; compare voltage across C_INT to CVref ( 0.6875 * Vdd )
bcf
STATUS, RP0
; ---- Select Bank 0 -----
btfss
goto
CMCON0, 7
AHEAD
; is C_SEN > CVref?
;
yes, we are done, jump ahead
;
no, charge C_SEN again and
;
keep count how many loops
incf
btfsc
incf
btfsc
incf
C_COUNT_L, F
STATUS, Z
C_COUNT_H, F
STATUS, Z
C_COUNT_U, F
; save count
goto
CHARGE
AHEAD
; send capacitance count out via SPI
movfw
call
movfw
call
movfw
call
C_COUNT_U
SPI_PutByte
C_COUNT_H
SPI_PutByte
C_COUNT_L
SPI_PutByte
; discharge ( C_INT + C_SEN ) through R_CAL and time
clrf
clrf
TMR1L
TMR1H
; clear Timer1
bsf
STATUS, RP0
; ---- Select Bank 1 -----
;
movlw
movwf
76543210
b'10100110'
VRCON
; configure comparator reference
;
CVref Enabled; VRR Low Range; VR=0x06
;
;
;
;
;
movlw
movwf
/------------- COM (RC4) digital input (high impedance)
|/------------ R_CAL (RC3) digital output
||/----------- C_INT (RC2) digital output
|||
xx543210
b'00010011'
TRISC
bcf
STATUS, RP0
;
;
;
;
;
movlw
movwf
/------------- COM (RC4) (high impedance)
|/------------ R_CAL (RC3) ground
||/----------- C_INT (RC2) ground
|||
xx543210
b'00010000'
PORTC
bsf
T1CON, TMR1ON
© 2005 Microchip Technology Inc.
; ---- Select Bank 0 -----
; turn on Timer1, begin counting
DS01014A-page 17
AN1014
TABLE C-1:
MAIN ROUTINE (CONTINUED)
; compare voltage across C_INT to CVref ( 0.25 * Vdd )
btfss
goto
CMCON0, 7
$ - 1
; is C_INT > CVref?
;
yes, loop
bcf
T1CON, TMR1ON
;
no, turn off (stop) Timer1
; send R_CAL discharge counts (time) out via SPI
movfw
call
movfw
call
TMR1H
SPI_PutByte
TMR1L
SPI_PutByte
goto
MAINLOOP
DS01014A-page 18
; report Timer1 contents
© 2005 Microchip Technology Inc.
Note the following details of the code protection feature on Microchip devices:
•
Microchip products meet the specification contained in their particular Microchip Data Sheet.
•
Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•
Microchip is willing to work with the customer who is concerned about the integrity of their code.
•
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED,
WRITTEN OR ORAL, STATUTORY OR OTHERWISE,
RELATED TO THE INFORMATION, INCLUDING BUT NOT
LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE,
MERCHANTABILITY OR FITNESS FOR PURPOSE.
Microchip disclaims all liability arising from this information and
its use. Use of Microchip’s products as critical components in
life support systems is not authorized except with express
written approval by Microchip. No licenses are conveyed,
implicitly or otherwise, under any Microchip intellectual property
rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, KEELOQ, microID, MPLAB, PIC, PICmicro, PICSTART,
PRO MATE, PowerSmart, rfPIC, and SmartShunt are
registered trademarks of Microchip Technology Incorporated
in the U.S.A. and other countries.
AmpLab, FilterLab, Migratable Memory, MXDEV, MXLAB,
PICMASTER, SEEVAL, SmartSensor and The Embedded
Control Solutions Company are registered trademarks of
Microchip Technology Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, dsPICDEM,
dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR,
FanSense, FlexROM, fuzzyLAB, In-Circuit Serial
Programming, ICSP, ICEPIC, Linear Active Thermistor,
MPASM, MPLIB, MPLINK, MPSIM, PICkit, PICDEM,
PICDEM.net, PICLAB, PICtail, PowerCal, PowerInfo,
PowerMate, PowerTool, Real ICE, rfLAB, rfPICDEM, Select
Mode, Smart Serial, SmartTel, Total Endurance, UNI/O,
WiperLock and Zena are trademarks of Microchip Technology
Incorporated in the U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
© 2005, Microchip Technology Incorporated, Printed in the
U.S.A., All Rights Reserved.
Printed on recycled paper.
Microchip received ISO/TS-16949:2002 quality system certification for
its worldwide headquarters, design and wafer fabrication facilities in
Chandler and Tempe, Arizona and Mountain View, California in
October 2003. The Company’s quality system processes and
procedures are for its PICmicro® 8-bit MCUs, KEELOQ® code hopping
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
© 2005 Microchip Technology Inc.
DS01014A-page 19
WORLDWIDE SALES AND SERVICE
AMERICAS
ASIA/PACIFIC
ASIA/PACIFIC
EUROPE
Corporate Office
2355 West Chandler Blvd.
Chandler, AZ 85224-6199
Tel: 480-792-7200
Fax: 480-792-7277
Technical Support:
http://support.microchip.com
Web Address:
www.microchip.com
Australia - Sydney
Tel: 61-2-9868-6733
Fax: 61-2-9868-6755
India - Bangalore
Tel: 91-80-2229-0061
Fax: 91-80-2229-0062
China - Beijing
Tel: 86-10-8528-2100
Fax: 86-10-8528-2104
India - New Delhi
Tel: 91-11-5160-8631
Fax: 91-11-5160-8632
Austria - Wels
Tel: 43-7242-2244-399
Fax: 43-7242-2244-393
Denmark - Copenhagen
Tel: 45-4450-2828
Fax: 45-4485-2829
China - Chengdu
Tel: 86-28-8676-6200
Fax: 86-28-8676-6599
India - Pune
Tel: 91-20-2566-1512
Fax: 91-20-2566-1513
France - Paris
Tel: 33-1-69-53-63-20
Fax: 33-1-69-30-90-79
China - Fuzhou
Tel: 86-591-8750-3506
Fax: 86-591-8750-3521
Japan - Yokohama
Tel: 81-45-471- 6166
Fax: 81-45-471-6122
Germany - Munich
Tel: 49-89-627-144-0
Fax: 49-89-627-144-44
China - Hong Kong SAR
Tel: 852-2401-1200
Fax: 852-2401-3431
Korea - Gumi
Tel: 82-54-473-4301
Fax: 82-54-473-4302
China - Qingdao
Tel: 86-532-8502-7355
Fax: 86-532-8502-7205
Korea - Seoul
Tel: 82-2-554-7200
Fax: 82-2-558-5932 or
82-2-558-5934
Atlanta
Alpharetta, GA
Tel: 770-640-0034
Fax: 770-640-0307
Boston
Westborough, MA
Tel: 774-760-0087
Fax: 774-760-0088
Chicago
Itasca, IL
Tel: 630-285-0071
Fax: 630-285-0075
Dallas
Addison, TX
Tel: 972-818-7423
Fax: 972-818-2924
Detroit
Farmington Hills, MI
Tel: 248-538-2250
Fax: 248-538-2260
Kokomo
Kokomo, IN
Tel: 765-864-8360
Fax: 765-864-8387
Los Angeles
Mission Viejo, CA
Tel: 949-462-9523
Fax: 949-462-9608
San Jose
Mountain View, CA
Tel: 650-215-1444
Fax: 650-961-0286
Toronto
Mississauga, Ontario,
Canada
Tel: 905-673-0699
Fax: 905-673-6509
China - Shanghai
Tel: 86-21-5407-5533
Fax: 86-21-5407-5066
China - Shenyang
Tel: 86-24-2334-2829
Fax: 86-24-2334-2393
China - Shenzhen
Tel: 86-755-8203-2660
Fax: 86-755-8203-1760
China - Shunde
Tel: 86-757-2839-5507
Fax: 86-757-2839-5571
China - Wuhan
Tel: 86-27-5980-5300
Fax: 86-27-5980-5118
China - Xian
Tel: 86-29-8833-7250
Fax: 86-29-8833-7256
Malaysia - Penang
Tel: 60-4-646-8870
Fax: 60-4-646-5086
Philippines - Manila
Tel: 63-2-634-9065
Fax: 63-2-634-9069
Italy - Milan
Tel: 39-0331-742611
Fax: 39-0331-466781
Netherlands - Drunen
Tel: 31-416-690399
Fax: 31-416-690340
Spain - Madrid
Tel: 34-91-708-08-90
Fax: 34-91-708-08-91
UK - Wokingham
Tel: 44-118-921-5869
Fax: 44-118-921-5820
Singapore
Tel: 65-6334-8870
Fax: 65-6334-8850
Taiwan - Hsin Chu
Tel: 886-3-572-9526
Fax: 886-3-572-6459
Taiwan - Kaohsiung
Tel: 886-7-536-4818
Fax: 886-7-536-4803
Taiwan - Taipei
Tel: 886-2-2500-6610
Fax: 886-2-2508-0102
Thailand - Bangkok
Tel: 66-2-694-1351
Fax: 66-2-694-1350
10/31/05
DS01014A-page 20
© 2005 Microchip Technology Inc.