| Electronic Components Datasheet Search |
|
AN1250 Datasheet(PDF) 7 Page - Microchip Technology |
|
|
|||||||||||||||||||||||||||||
AN1250 Datasheet(HTML) 7 Page - Microchip Technology |
|
7 / 22 page ![]() © 2009 Microchip Technology Inc. DS01250A-page 7 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; //set all A/D channels to digital I/O pins TRISB = 0x0000; LATB = 0x0000; PORTB = 0x0000; //set all channels to logical 0 outputs Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); //Wait for charge to drain TRISB = ADSELECT[Index]; //set selected channel to input AD1PCFGL = ~ADSELECT[Index]; //set selected channel to analog A/D input Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); //wait for A/D to connect to channel AD1CHS = Index; //select A/D channel CTMUCONbits.IDISSEN = 1; //Drain any charge on the A/D circuit Nop(); Nop(); Nop(); Nop(); Nop(); //Wait for charge to drain CTMUCONbits.IDISSEN = 0; //Stop discharge of A/D circuit IFS0bits.AD1IF = 0; //Make sure A/D interrupt flag = 0 AD1CON1bits.SAMP = 1; //Manually start sampling CTMUCONbits.EDG2STAT = 0; // Make sure edge2 is 0 CTMUCONbits.EDG1STAT = 1; // Set edge1 - Start Charge for (count = 0; count < loopCount; count++); // Delay for CTMU charge time CTMUCONbits.EDG1STAT = 0; //Clear edge1 - Stop Charge IFS0bits.AD1IF = 0; AD1CON1bits.SAMP = 0; //Clear SAMP bit to begin manual A/D conversion while(!IFS0bits.AD1IF); //Wait for the A/D conversion to finish immediateValue = ADC1BUF0; //Read the value from the A/D conversion AD1CON1bits.SAMP = 0; IFS0bits.AD1IF = 0; AD1CON1bits.DONE = 0; //Make sure A/D bits are cleared //End of CTMU read |
|
|
Link URL |
| Does ALLDATASHEET help your business so far? [ DONATE ] |
About Alldatasheet | Advertisement | Contact us | Privacy Policy | Link to Datasheet | Link Exchange | Manufacturer List All Rights Reserved©Alldatasheet.com |
| Russian : Alldatasheetru.com | Korean : Alldatasheet.co.kr | Spanish : Alldatasheet.es | French : Alldatasheet.fr | Italian : Alldatasheetit.com Portuguese : Alldatasheetpt.com | Polish : Alldatasheet.pl | Vietnamese : Alldatasheet.vn Indian : Alldatasheet.in | Mexican : Alldatasheet.com.mx | British : Alldatasheet.co.uk | New Zealand : Alldatasheet.co.nz |
|
Family Site : ic2ic.com |
icmetro.com |