C1VIN- -
C1IN+
C1VIN+ C1 C1OUT
0
MUX +
FixedRef 1 C1OUT (to SR Latch)
0
MUX C1POL
CVREF
1
Note 1: When C1ON = 0, the C1 comparator will produce a ‘0’ output to the XOR Gate.
C1RSEL
2: Q1 and Q3 are phases of the four-phase system clock (FOSC).
3: Q1 is held high during Sleep mode.
* Comparator modules capable of touch sense as described must have the SR-latch option.
C2POL
C2R 0 SYNCC2OUT
MUX
D Q 1 To Timer1 Gate, SR Latch
and other peripherals
C2IN+ 0
MUX From Timer1
FixedRef 1 Clock
0
MUX
CVREF 1 C2VREF
C2VSEL
Note 1: When C1ON = 0, the C2 comparator will produce a ‘0’ output to the XOR Gate.
2: Q1 and Q3 are phases of the four-phase system clock (FOSC).
3: Q1 is held high during Sleep mode.
To handle scanning four buttons is straightforward in called due to other interrupts, and those should be han-
software when using C code. It is easiest to handle the dled appropriately by the user, to coexist with the fixed
buttons’ measured raw and average data as arrays, time-base Timer0 interrupts. An abstracted, high level
where each entry is a button’s value. It is also nice to form is as follows:
have individual trip thresholds for each button, in the
event different buttons behave differently. In plain C, EXAMPLE 1: SIMPLE ISR
these variables would be declared as follows: void isr {
unsigned int average [4]; // If capacitive interrupt
if (T0IF == 1) {
unsigned int trip [4];
Note: A simple trip threshold will be assumed for // Grab TMR1 Reading
purposes of discussion. Application note StopTimers();
AN1103, “Software Handling of Capacitive GetMeasurement();
Sensing,” contains more detail on various // Test if Pressed
methods of detecting button presses. if (IsButtonPressed(index))
Averaging is fundamental to all methods.
SetFlag(index);
The array variable average holds the average values else
for each button, indexed 0 to 3. Likewise,the most ClearFlag(index);
recent reading may be stored in an array for viewing or
to aid design, but this raw data does not need to be // Perform 16-point average
stored since it is measured at the end of a scan when PerformAverage(index);
a decision for pressed or not pressed is made in the
// Set next sensor
Interrupt Service Routine (ISR).
index = (++index) & 0x03;
To set the big picture before going into further detail, the SetComparators(index);
basic operation is completed in the Interrupt Service RestartTimers();
Routine. The ISR will be called by a Timer0 overflow }
interrupt each time a button is ready to have a }
measurement taken and complete a scan. It may be
C1CH
C2OUT
T1CKI
S
R Q Timer1
¼ VDD
.
. C2CH
. 0
1 COM
2
3 R
4
Cs5 5
6
7 S0
8 S1
9
S2
.
.
.
Sensors
Cs0 thru Cs15
.
.
. 0
1 COM
Cs10 2
3 R
4
5
. 6
. 7 S0
8 S1
. 9
S2
.
.
.
Additional MUXes
RestartTimers();
}
}
• 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.
06/25/07