English
Language : 

AN1250 Datasheet, PDF (7/22 Pages) Microchip Technology – Microchip CTMU for Capacitive Touch Applications
AN1250
Example 3 provides the equivalent code for reading the
capacitive touch sensors using the CTMU on a PIC24F
device. Example 4 has the same algorithm for a
PIC18F device. Note that the channel number being
read is referenced by the Index variable. The
ADSELECT array is setup to have the correct bits set for
the corresponding Index variable so that the correct
channel is set to an analog A/D. The A/D value is
temporarily stored in the variable, immediateValue.
The LoopCount determines how long the CTMU
current source charges the capacitive touch circuit.
EXAMPLE 3: READING THE CAPACITIVE TOUCH SENSOR CIRCUIT SOFTWARE ALGORITHM
(PIC24F)
//Read CTMU (Get the raw sensor reading)
AD1PCFGL= 0xFFFF;
TRISB = 0x0000;
LATB = 0x0000;
PORTB = 0x0000;
Nop(); Nop(); Nop(); Nop();
Nop(); Nop(); Nop(); Nop();
//Wait for charge to drain
TRISB = ADSELECT[Index];
AD1PCFGL = ~ADSELECT[Index];
Nop(); Nop(); Nop(); Nop();
Nop(); Nop(); Nop(); Nop();
//wait for A/D to connect to channel
AD1CHS = Index;
CTMUCONbits.IDISSEN = 1;
Nop(); Nop(); Nop(); Nop(); Nop();
//Wait for charge to drain
CTMUCONbits.IDISSEN = 0;
IFS0bits.AD1IF
= 0;
AD1CON1bits.SAMP
= 1;
CTMUCONbits.EDG2STAT = 0;
CTMUCONbits.EDG1STAT = 1;
for (count = 0; count < loopCount; count++);
CTMUCONbits.EDG1STAT = 0;
IFS0bits.AD1IF
= 0;
AD1CON1bits.SAMP
= 0;
while(!IFS0bits.AD1IF);
immediateValue = ADC1BUF0;
AD1CON1bits.SAMP
= 0;
IFS0bits.AD1IF
= 0;
AD1CON1bits.DONE
= 0;
//End of CTMU read
//set all A/D channels to digital I/O pins
//set all channels to logical 0 outputs
//set selected channel to input
//set selected channel to analog A/D input
//select A/D channel
//Drain any charge on the A/D circuit
//Stop discharge of A/D circuit
//Make sure A/D interrupt flag = 0
//Manually start sampling
// Make sure edge2 is 0
// Set edge1 - Start Charge
// Delay for CTMU charge time
//Clear edge1 - Stop Charge
//Clear SAMP bit to begin manual A/D conversion
//Wait for the A/D conversion to finish
//Read the value from the A/D conversion
//Make sure A/D bits are cleared
© 2009 Microchip Technology Inc.
DS01250A-page 7