Professional Documents
Culture Documents
STEP 2: CONNECT CAPACITORS AND When a user approaches the capacitive sensor, the
SETTLE size of the external capacitance will increase with
respect to the internal capacitance. This will result in a
The two capacitors are connected in parallel and the
change in the settling voltages of the two samples.
charges are allowed to settle. As the external
capacitance increases, so does its initial charge For the Sample A, when the external sensor increases
(Equation 2). The internal capacitance does not in capacitance and is discharged to VSS, the final
change, so its charge remains constant. This step is settling voltage will decrease. For the Sample B, when
shown in Figure 5. the external sensor increases in capacitance and is
charged to VDD, the final settling voltage will increase.
STEP 3: ADC CONVERSION Thus, as the external capacitance increases, the two
settling points of the CVD waveform will diverge which
The final voltage on Chold is determined by the size of
causes a shift in the sensor reading.
the external capacitance in relation to the size of the
internal capacitance (Equation 3). Noise will cause a shift in the settled voltage based on
the phase of the noise signal. For low-frequency noise,
STEPS 4-6: REVERSE THE PRECHARGE the phase will be approximately equivalent for both
VOLTAGES AND REPEAT samples. Since the effect of the noise is roughly the
same for both samples, we are able to significantly
The operation is then performed again, but this time the
attenuate noise from our signal by taking the difference
precharge voltages are reversed.
between the two settling points, causing the effect of
The difference between the two results is used as the the noise offset to cancel itself out. As the noise
current sensor reading. This is why the scanning frequency increases, the quality of this noise rejection
technique is commonly called differential CVD. The decreases and further filtering techniques become
complete waveform of the differential CVD sensing necessary. As the time difference between the two
method is shown in Figure 2. samples decreases, the ability to reject higher
frequencies increases. This is one of the reasons why
performing the scan in assembly (rather than C) can
increase the noise performance of the sensing method.
GO/DONE = 1
Internal ADC Hold Capacitor
GO/DONE = 1
VV
SS
SS
Sample A Sample B
Time
ADPREF
RIC(3)
ANx
(6)
CSENSOR RSENSOR
GO/DONE
CPIN(5)
DAC(1)
RSS(4) 8 / 10 / 12
ADC
VDD VDD
FVR
CHOLD
(7) 0 = Left Justify
ADFM
1 = Right Justify
ANx
(6)
(7)
RIC(3)
CSENSOR RSENSOR ADON(2) ADNREF(1)
8 / 16
CPIN(5)
CHS
VREF-(1) ADRESH ADRESL
I/O Port Drivers
STEP-BY-STEP ANALYSIS
Note: Since VDD is usually considered constant
Precharge Stage for an application, most of the following
math will divide by VDD to remove it from
Both capacitors are charged to known, opposite
the equation. This is the same as
voltage states, as defined in Equation 2. The internal
assuming VDD is equal to 1V.
ADC capacitance can be charged using either the
drivers of an unused analog pin, another sensors pin,
or (if available as an ADC channel selection on the FIGURE 4: PRECHARGE STAGE,
chosen PIC device) the Digital-to-Analog Converter. SAMPLE A AND SAMPLE B
Sample A
EQUATION 2: PRECHARGE STAGE Idle / Reference
Q base = Cbase V base Sensor VADC
Differential Result
The above equation for the settling voltage is the
ADC generic form, true for both the first and second of the
differential samples. The actual settling voltage for the
first sample (A) is calculated by substituting 0 for Vbase
and VDD for VADC. The second sample (B) is
calculated by substituting VDD for Vbase and 0 for VADC.
VB
V
Internal ADC Hold Capacitor
VA
External Capacitive Sensor
VVSS
SS
Sample A Sample B
Time
V released = V settle Vhold = 0 V base = V DD Calculate the general form equation for the CVD
V settle V hold = VDD V base = 0 settling voltage when a finger is present on the sensor:
C base + C finger V base + C hold V hold
Vreleased C base Chold Vsettle pressed = --------------------------------------------------------------------------------------------
------------------------- = --------------------------------- + --------------------------------- C hold + Cbase + C finger
VDD C hold + Cbase C hold + C base
Use the equation for V to calculate the settling point
differential for the CVD waveform when a finger is
EQUATION 4: DIFFERENTIAL RESULT
present on the sensor:
Difference in Voltage Between the Two CVD Settling Points
V pressed C base + C finger Chold
V released C base Chold ----------------------- = ---------------------------------------------------------------
------------------------- = ---------------------------------- V DD Chold + C base + C finger
V DD C hold + C base
Vreleased
Vpressed
Internal ADC Hold Capacitor
VSS
VSS
Sample A Sample B
Time
Timing Considerations the settling delay should be set to the minimum amount
of time that still provides at least 90-95% of the
PRECHARGE DELAY fully-settled sensitivity. Specific applications may
require a longer settling delay (for example, if theres a
Definition: the amount of time spent charging the
large external capacitance/resistance) or a shorter
internal and external capacitors.
settling delay (for example, if noise in the design is a
This delay does not have a significant impact on the known problem).
noise performance of the system. However, if the CVD
implementation is using other sensors as the reference DIFFERENTIAL DELAY
voltage source to the internal hold capacitor, and either
The amount of time between Sample A and Sample B.
the sensor or its reference has a large time constant,
its possible the default delay will not provide enough The differential delay should be minimized in order to
time for the external reference source to fully charge to maximize the low-frequency noise rejection of the
VDD before exiting the Precharge stage. waveform.
If both capacitors are not charged completely, the Adding a small randomization to the time between the
sensors signals will be corrupted. The circuit no longer two samples will help attenuate noise in the lower kHz
has a known charge prior to entering the Acquisition range but is not mandatory.
stage. Instead, the charge is now dependent on the
capacitance. This is an inoperable mode for the CVD SAMPLING DELAY
scanning method and should be avoided. The Definition: the amount of time between Sample A and
precharge delay should be increased until there is no the next Sample A. In other words, the amount of time
doubt that a full charge will occur before every sample. between CVD waveforms.
Looking at the waveform on an oscilloscope will add The sampling delay should be randomized to attenuate
capacitance to the sensor equivalent to that of a very noise frequencies that are harmonics of the sampling
heavy press. If the oscilloscope shows the sensor is not rate of the sensor.
fully charging before entering the Acquisition stage, the
precharge time should be increased.
CVD WITH TWO ACQUISITION
To increase the precharge time in the code examples
STAGES
provided in this application note, add more NOPs to the
line after the comment Optional additional and/or The ideal settling voltage for a normal CVD waveform
variable delay and before the Acquisition stage. on both Sample A and Sample B is *VDD. This
To increase the precharge time in other code libraries provides the largest separation between the settled
or frameworks, look for the advanced waveform voltage and the voltage rails, which maximizes its
settings and find the precharge (sometimes called the robustness against clipping due to noise. In order for
Chold-Charge delay) setting. the settling voltages to be near *VDD, the internal and
external capacitors must be roughly equivalent.
ACQUISITION/SETTLING DELAY If the internal capacitor is much larger than the external
Definition: the amount of time spent allowing the capacitor (or vice versa), the settling voltage will be
capacitors to equalize to a median voltage after being proportionally dominated by the larger capacitors
precharged to opposite states. starting value. This results in a less-than-ideal level of
sensitivity.
During the entire Acquisition stage of the CVD
waveform until the ADC conversion has begun, the To solve this problem, two Acquisition stages can be
sensor will be set to an input (TRIS=1) which means it chained together to force the final voltage closer to
will have a high-impedance. Any low-impedance *VDD.
source near the sensor will be able to affect the settled If the external capacitor is much larger than the internal
charge by either discharging or charging it further. In capacitor:
other words, this is the noise susceptible period of our
Perform the normal CVD Precharge and
waveform. For this reason, the time allowed for this
Acquisition stages. (Equation 3)
stage should be minimized.
Maintain the voltage on the external capacitor
There is a trade-off to be considered when deciding on while simultaneously re-charging the internal
the amount of settling delay time. If the settling delay is capacitor.
too small, the charge across both capacitors will not
Perform another Acquisition stage. (Equation 6)
fully settle to an equalized value. This will reduce the
amount of sensitivity when additional external
capacitance is added to the circuit. However, if the
settling delay is too large, noise will be able to couple
in to the sensor and corrupt the final voltage. In general,
double = C
V total normal
base V settle + C hold V hold
GO/DONE = 1
Voltage
GO/DONE = 1
VSS
SS
Sample A Sample B
Time
GO/DONE = 1
Internal ADC Hold Capacitor
GO/DONE = 1
External Capacitive Sensor
VSS
SS
Sample A Sample B
Time
half
Q total normal
= C base Vbase + C hold V settle
GO/DONE = 1
Voltage
Vreleased
Vpressed
Internal ADC Hold Capacitor
GO/DONE = 1
VSS
Sample A Sample B
Time
double
Vtotal is the final settling voltage for a Double-CVD waveform.
CVD SCANNING WITH ACTIVE When designing the guard for an application, the best
solution is to encircle the sensor and its trace
GUARD
completely. If this is not possible, particular care should
The CVD scan is measuring total capacitance, so as be taken at any point where a low-impedance source
the base capacitance of a sensor decreases, the comes near to the sensor. Communication lines, motor
change in signal caused by a users finger will increase. drive lines, ground planes, and power planes are
Active guards are a way of minimizing the base examples of traces that should be kept away from
capacitance by reducing the electric potential between capacitive sensors. The guard trace should be placed
the sensor and its surrounding environment. between the sensor and these sources. However, you
do not want to place the guard between the user and
the sensor, as this will shield the sensor from the effect
of the approaching finger.
FIGURE 11: ELECTRIC FIELD LINES WITH AND WITHOUT A GUARD TRACE
Sensor
Chassis Ground
Sensor
Low-Impedance Guard
Chassis Ground
Any power planes or low-impedance traces should be A series resistor can be added to the guard to increase
guarded from the sensor. its time constant when charged and discharged. The
better the guard waveform can be designed to match
Around the sensors pad, the guards trace should be the sensors waveform, the less electric potential is
about 1 mm thick and separated from the sensor by 2-3 seen by the sensor and the better its sensitivity.
mm.
This implementation is slightly inefficient due to a
Following the sensors trace back to the PIC devices one-instruction cycle timing difference between the
pin, the guards trace can be same thickness as the output of the guard and the connection of the two
sensors trace: 0.1-0.3 mm. The separation of the capacitors. (See the example code implementation in
guard trace from the sensor trace can be as small as the appendix.) This time difference could be overcome
0.5 mm. by using a hardware timer and a PWM output to
The standard method for guarding involves using a synchronize the guards change in potential with the
unity-gain amplifier to buffer the sensors waveform connection of the two capacitors. Due to the tuning
onto a surrounding trace. This is more expensive than required for this configuration based on FOSC, no
necessary since there are two available options for example code is provided.
driving the guard signal that do not require external
components.
VVSS
SS
Sample A Sample B
Time
Guarding with the DACOUT Pin The benefits of the guard could be further enhanced by
using the individual CVD settling values for Sample A
If the DACOUT pin is used to drive the guard signal as and Sample B to constantly tune the DAC to the closest
shown in Figure 13, the sensors waveform can be matching output voltage for each. For a 10-bit ADC and
much more closely matched by choosing the settling a 5-bit DAC, this can be achieved by simply
value of the DAC during the two Acquisition stages. right-shifting the ADC result by 5 bits and using it as the
This method provides 70-90% of the benefits of a DACOUT settling voltage on the next sample.
perfectly matched guard. If the DACOUT pin is
available, this is the recommended method to use. If
DACOUT is not available, using an I/O driven guard is
the next best option.
VVSS
SS
Sample A Sample B
Time
(For example, the metal layer on a For example, if the trace were driven to VSS at all times,
metal-over-capacitive system. This is not required, then increased coupling would cause Sample B to
but beneficial if the metal layer can short to the decrease its settling voltage. At the same time,
sensor.) increased capacitance will cause Sample B to increase
its settling voltage. Since these two effects tend to
If the target being detected is isolated from the happen at the same time, there is a conflict between
sensors ground reference, placing a mutual drive which direction to shift and sensitivity is lost. There will
near the sensor will allow the application to detect also be strange behaviors on the sensors signal when
changes in the permittivity between the sensor one effect overpowers the other.
and the mutual drive.
VVSS
SS
Sample A Sample B
Time
AADPRE = PRECHARGE_DELAY;
AADACQ = SETTLING_DELAY;
// Single-Guard-Pin enabled
AADGRDbits.GRDAOE = 1;
AADGRDbits.GRDBOE = 0;
AADGRDbits.GRDPOL = 0;
void ServiceHardwareADC(void)
{
AADCON0bits.CHS = 0b00000;
AADCON0bits.GO = 1;
while(AADCON0bits.GO);
differentialResult = AADRES1 | 0x0400;
differentialResult -= AADRES0;
SAMPLE A: SAMPLE B:
#define PIC_DACCON0_VDD 0xC0 #define PIC_DACCON0_VSS 0x00
#define PIC_DACCON1_VDD 0x1F #define PIC_DACCON1_VSS 0x00
#define PIC_ADCON0_SELECT_DAC 0x79 #define PIC_ADCON0_SELECT_DAC 0x79
#define PIC_ADCON0_SELECT_AN0 0x01 #define PIC_ADCON0_SELECT_AN0 0x01
; Initialize the DAC for VDD Reference ; Initialize the DAC for VSS Reference
BANKSEL DACCON0 BANKSEL DACCON0
movlw PIC_DACCON0_VDD movlw PIC_DACCON0_VSS
movwf DACCON0 movwf DACCON0
movlw PIC_DACCON1_VDD movlw PIC_DACCON1_VSS
movwf DACCON1 movwf DACCON1
; Optional additional and/or variable delay ; Optional additional and/or variable delay
NOP NOP
; Perform the ADC Conversion (GO/nDONE = 1) ; Perform the ADC Conversion (GO/nDONE = 1)
bsf ADCON0, 1 bsf ADCON0, 1
; Result stored in ADRESL and ADRESH ; Result stored in ADRESL and ADRESH
SAMPLE A: SAMPLE B:
#define SENSOR_LAT LATA #define SENSOR_LAT LATA
#define SENSOR_TRIS TRISA #define SENSOR_TRIS TRISA
#define SENSOR_PIN 0 #define SENSOR_PIN 0
#define REFERENCE_LAT LATA #define REFERENCE_LAT LATA
#define REFERENCE_PIN 1 #define REFERENCE_PIN 1
; Initialize AN1 as the Reference Source ; Initialize AN1 as the Reference Source
BANKSEL REFERENCE_LAT BANKSEL REFERENCE_LAT
bsf REFERENCE_LAT, REFERENCE_PIN bcf REFERENCE_LAT, REFERENCE_PIN
; Optional additional and/or variable delay ; Optional additional and/or variable delay
NOP NOP
; Perform the ADC Conversion (GO/nDONE = 1) ; Perform the ADC Conversion (GO/nDONE = 1)
bsf ADCON0 ,1 bsf ADCON0 ,1
; Result stored in ADRESL and ADRESH ; Result stored in ADRESL and ADRESH
Example: Double-CVD Waveform with This code example implements the Double-CVD
DAC as Reference waveform using the DAC as the reference voltage
source for the internal ADC hold capacitance.
SAMPLE A: SAMPLE B:
#define PIC_DACCON0_VDD 0xC0 #define PIC_DACCON0_VSS 0x00
#define PIC_DACCON1_VDD 0x1F #define PIC_DACCON1_VSS 0x00
#define PIC_ADCON0_SELECT_DAC 0x79 #define PIC_ADCON0_SELECT_DAC 0x79
#define PIC_ADCON0_SELECT_AN0 0x01 #define PIC_ADCON0_SELECT_AN0 0x01
#define SENSOR_LAT LATA #define SENSOR_LAT LATA
#define SENSOR_TRIS TRISA #define SENSOR_TRIS TRISA
#define SENSOR_PIN 0 #define SENSOR_PIN 0
; Initialize the DAC for VDD Reference ; Initialize the DAC for VSS Reference
BANKSEL DACCON0 BANKSEL DACCON0
movlw PIC_DACCON0_VDD movlw PIC_DACCON0_VSS
movwf DACCON0 movwf DACCON0
movlw PIC_DACCON1_VDD movlw PIC_DACCON1_VSS
movwf DACCON1 movwf DACCON1
; Perform the ADC Conversion (GO/nDONE = 1) ; Perform the ADC Conversion (GO/nDONE = 1)
bsf ADCON0, 1 bsf ADCON0, 1
; Result stored in ADRESL and ADRESH ; Result stored in ADRESL and ADRESH
Example: Half-CVD Waveform with DAC This code example implements the Half-CVD
as Reference waveform using the DAC as the reference voltage
source for the internal ADC hold capacitance.
This method requires an unimplemented ADC channel
to store the ADCs charge.
SAMPLE A: SAMPLE B:
#define PIC_DACCON0_VDD 0xC0 #define PIC_DACCON0_VSS 0x00
#define PIC_DACCON1_VDD 0x1F #define PIC_DACCON1_VSS 0x00
#define PIC_ADCON0_SELECT_DAC 0x79 #define PIC_ADCON0_SELECT_DAC 0x79
#define PIC_ADCON0_SELECT_AN0 0x01 #define PIC_ADCON0_SELECT_AN0 0x01
#define PIC_ADCON0_UNIMP_CH 0xF1 #define PIC_ADCON0_UNIMP_CH 0xF1
#define SENSOR_LAT LATA #define SENSOR_LAT LATA
#define SENSOR_TRIS TRISA #define SENSOR_TRIS TRISA
#define SENSOR_PIN 0 #define SENSOR_PIN 0
; Initialize the DAC for VDD Reference ; Initialize the DAC for VSS Reference
BANKSEL DACCON0 BANKSEL DACCON0
movlw PIC_DACCON0_VDD movlw PIC_DACCON0_VSS
movwf DACCON0 movwf DACCON0
movlw PIC_DACCON1_VDD movlw PIC_DACCON1_VSS
movwf DACCON1 movwf DACCON1
; Perform the ADC Conversion (GO/nDONE = 1) ; Perform the ADC Conversion (GO/nDONE = 1)
bsf ADCON0, 1 bsf ADCON0, 1
NOP ; (Recommended) 0.5 TAD Delay NOP ; (Recommended) 0.5 TAD Delay
EXAMPLE: I/O Driven Guard The differences between Sample A and Sample B have
been bolded and colored in red. Notice that the steps
This code example implements the CVD waveform remain the same except the initialization of the voltage
using another sensor as the reference voltage source references and the guard drive.
for the internal hold capacitor and a dedicated I/O pin
for the guard signal.
SAMPLE A: SAMPLE B:
#define SENSOR_LAT LATA #define SENSOR_LAT LATA
#define SENSOR_TRIS TRISA #define SENSOR_TRIS TRISA
#define SENSOR_PIN 0 #define SENSOR_PIN 0
#define REFERENCE_LAT LATA #define REFERENCE_LAT LATA
#define REFERENCE_PIN 1 #define REFERENCE_PIN 1
#define GUARD_LAT LATA #define GUARD_LAT LATA
#define GUARD_PIN 2 #define GUARD_PIN 2
#define PIC_ADCON0_SELECT_AN0 0x01 #define PIC_ADCON0_SELECT_AN0 0x01
#define PIC_ADCON0_SELECT_AN1 0x05 #define PIC_ADCON0_SELECT_AN1 0x05
; Initialize AN1 as the Reference Source ; Initialize AN1 as the Reference Source
BANKSEL REFERENCE_LAT BANKSEL REFERENCE_LAT
bsf REFERENCE_LAT, REFERENCE_PIN bcf REFERENCE_LAT, REFERENCE_PIN
; Optional additional and/or variable delay ; Optional additional and/or variable delay
NOP NOP
; Perform the ADC Conversion (GO/nDONE = 1) ; Perform the ADC Conversion (GO/nDONE = 1)
bsf ADCON0 ,1 bsf ADCON0 ,1
; Result stored in ADRESL and ADRESH ; Result stored in ADRESL and ADRESH
EXAMPLE: DACOUT Driven Guard This code example implements the CVD waveform
using the DAC as the reference voltage source for the
SAMPLE A: internal hold capacitor and, simultaneously, as the
#define PIC_DACCON0_VDD 0xC0 DACOUT guard driver.
#define PIC_DACCON1_VDD 0x1F
#define PIC_DACCON1_SETTLE_A 0x0E
#define PIC_ADCON0_SELECT_DAC 0x79
#define PIC_ADCON0_SELECT_AN1 0x05
#define SENSOR_LAT LATA
#define SENSOR_TRIS TRISA SAMPLE B:
#define SENSOR_PIN 1 #define PIC_DACCON0_VSS 0x00
#define DACOUT_LAT LATA #define PIC_DACCON1_VSS 0x00
#define DACOUT_PIN 0 #define PIC_DACCON1_SETTLE_B 0x10
; Initialize the DAC for VDD Reference ; Initialize the DAC for VSS Reference
BANKSEL DACCON0 BANKSEL DACCON0
movlw PIC_DACCON0_VDD movlw PIC_DACCON0_VSS
movwf DACCON0 movwf DACCON0
movlw PIC_DACCON1_VDD movlw PIC_DACCON1_VSS
movwf DACCON1 movwf DACCON1
; Perform the ADC Conversion (GO/nDONE = 1) ; Perform the ADC Conversion (GO/nDONE = 1)
bsf INDF1, 1 bsf INDF1, 1
; Result stored in ADRESL and ADRESH ; Result stored in ADRESL and ADRESH
Example: CVD Sampling Using a Sensor The differences between Sample A and Sample B have
as the Reference and a Mutual Drive been bolded and colored in red. Notice that the steps
remain the same except the initialization of the voltage
references and the mutual drive direction.
SAMPLE A: SAMPLE B:
#define SENSOR_LAT LATA #define SENSOR_LAT LATA
#define SENSOR_TRIS TRISA #define SENSOR_TRIS TRISA
#define SENSOR_PIN 0 #define SENSOR_PIN 0
#define REFERENCE_LAT LATA #define REFERENCE_LAT LATA
#define REFERENCE_PIN 1 #define REFERENCE_PIN 1
#define MUTUAL_LAT LATA #define MUTUAL_LAT LATA
#define MUTUAL_PIN 2 #define MUTUAL_PIN 2
#define PIC_ADCON0_SELECT_AN0 0x01 #define PIC_ADCON0_SELECT_AN0 0x01
#define PIC_ADCON0_SELECT_AN1 0x05 #define PIC_ADCON0_SELECT_AN1 0x05
; Initialize AN1 as the Reference Source ; Initialize AN1 as the Reference Source
BANKSEL REFERENCE_LAT BANKSEL REFERENCE_LAT
bsf REFERENCE_LAT, REFERENCE_PIN bcf REFERENCE_LAT, REFERENCE_PIN
; Optional additional and/or variable delay ; Optional additional and/or variable delay
NOP NOP
; Perform the ADC Conversion (GO/nDONE = 1) ; Perform the ADC Conversion (GO/nDONE = 1)
bsf ADCON0 ,1 bsf ADCON0 ,1
; Prepare Mutual Drive for Sample B ; Prepare Mutual Drive for Sample A
BANKSEL MUTUAL_LAT BANKSEL MUTUAL_LAT
bsf MUTUAL_LAT, MUTUAL_PIN bcf MUTUAL_LAT, MUTUAL_PIN
NOTES:
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 Microchips 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 Microchips 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.
QUALITY MANAGEMENT SYSTEM Microchip received ISO/TS-16949:2009 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
CERTIFIED BY DNV Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Companys quality system processes and procedures
are for its PIC MCUs and dsPIC DSCs, KEELOQ code hopping
== ISO/TS 16949 == devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchips quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.