English
Language : 

PIC32MX440F256H-80I Datasheet, PDF (515/646 Pages) Microchip Technology – 64/100-Pin General Purpose and USB 32-Bit Flash Microcontrollers
PIC32MX3XX/4XX
22.4.10 Free-Running Sample
Conversion Sequence
The Auto-Convert Conversion Trigger mode
(SSRC = 111) in combination with the Automatic Sam-
pling Start mode (ASAM = 1), allows the ADC module
to schedule acquisition/conversion sequences with no
intervention by the user or other device resources. This
“Clocked” mode allows continuous data collection after
module initialization. See Example 22-4 for a code
example.
EXAMPLE 22-4: CONVERTING 1 CHANNEL, AUTO-SAMPLE START, AUTO-CONVERT CODE
AD1PCFG = ~(1 << 5);
// all PORTB = Digital but RB5 = analog
AD1CON1 = 0x00E0;
// SSRC bit = 111 internal
// counter ends sampling and starts
// converting.
AD1CHS = 5 << 16;
// Connect RB5/AN5 as CH0 input
// in this example RB2/AN2 is the input
AD1CSSL = 0;
AD1CON3 = 0x0F00;
// Sample time = 15 Tad
AD1CON2 = 0x0004;
// Interrupt after every 2 samples
AD1CON1SET = 0x8000;
// turn ADC ON
AD1CON1SET = 0x0004;
// auto start sampling
while (1) // repeat continuously
{
while (!IFS1 & 0x0002);
// poll for interrupt
// flag for conversion done
IFS1CLR = 0x0002;
// clear ADC interrupt flag
// result of conversions is available in ADC1BUF0
// and ADC1BUF1
}
22.4.11 SAMPLING A SINGLE CHANNEL
MULTIPLE TIMES
In this case, one ADC input, AN0, will be acquired and
converted. The results are stored in the ADC1BUF buf-
fer. This process repeats 15 times until the buffer is full,
and then the module generates an interrupt. Then
entire process repeats.
With ALTS (AD1CON2<0>) clear, only the MUX A
inputs are active. The CH0SA (AD1CHS<19:16>) bits
and CH0NA (AD1CHS<23>) bit are specified (AN0-
VREF-) as the input to the sample/hold channel. Other
input selection bits are not used.
22.4.12 EXAMPLE: A/D CONVERSIONS
WHILE SCANNING THROUGH
ANALOG INPUTS
A typical setup might include all available analog input
channels to be sampled and converted. The CSCNA
(AD1CON2<10>) bit specifies scanning of the ADC
inputs. Other conditions are similar to the previous
example (see Section 22.4.11 “Sampling a Single
Channel Multiple Times”).
Initially, the AN0 input is acquired and converted. The
result is stored in the ADC1BUF buffer. Then the AN1
input is acquired and converted. This process of scan-
ning the inputs repeats 16 times until the buffer is full
and then the module generates an interrupt. Then the
entire process repeats.
© 2008 Microchip Technology Inc.
Preliminary
DS61143E-page 513