PIC32 Family Reference Manual
DS61104E-page 17-36
© 2007-2011 Microchip Technology Inc.
Example 17-5:
Converting 1 Channel, Auto-Sample Start, Conversion Trigger Based Conversion Start Code
AD1PCFG = 0xFFFB;
// all PORTB = Digital; RB2 analog
AD1CON1 = 0x0040;
// SSRC bit = 010 implies GP TMR3
// compare ends sampling and starts
// converting.
AD1CHS = 0x00020000;
// Connect RB2/AN2 as CH0 input
// in this example RB2/AN2 is the input
AD1CSSL = 0;
AD1CON3 = 0x0000;
// Sample time is TMR3, TAD = internal TPB * 2
AD1CON2 = 0x0004;
// Interrupt after 2 conversions
// set TMR3 to time out every 125 ms
TMR3= 0x0000;
PR3= 0x3FFF;
T3CON = 0x8010;
AD1CON1SET = 0x8000;
// turn ON the ADC
AD1CON1SET = 0x0004;
// start auto sampling every 125 mSecs
while (1)
// repeat continuously
{
while (!IFS1 & 0x0002){};
// conversion done?
ADCValue = ADC1BUF0;
// yes then get first ADC value
IFS1CLR = 0x0002;
// clear ADIF
}
// repeat