dsPIC30F Family Reference Manual
DS70064C-page 17-30 © 2004 Microchip Technology Inc.
17.14 Specifying How Conversion Results are Written Into the Buffer
As conversions are completed, the module writes the results of the conversions into the A/D
result buffer. This buffer is a RAM array of sixteen 10-bit words. The buffer is accessed through
16 address locations within the SFR space named ADCBUF0...ADCBUFF.
User software may attempt to read each A/D conversion result as it is generated, however, this
would consume too much CPU time. Generally, to simplify the code, the module will fill the buffer
with results and then generate an interrupt when the buffer is filled.
17.14.1 Number of Conversions per Interrupt
The SMPI<3:0> bits (ADCON2<5:2>) will select how many A/D conversions will take place
before the CPU is interrupted. This can vary from 1 sample per interrupt to 16 samples per
interrupt. The A/D converter module always starts writing its conversion results at the beginning
of the buffer, after each interrupt. For example, if SMPI<3:0> = 0000, the conversion results will
always be written to ADCBUF0. In this example, no other buffer locations would be used.
17.14.2 Restrictions Due to Buffer Size
The user cannot program a combination of CHPS and SMPI bits that specifies more than 16
conversions per interrupt when the BUFM bit (ADCON2<1>) is ‘0’, or 8 conversions per interrupt
when the BUFM bit (ADCON2<1>) is ‘0’. The BUFM bit function is described below.
17.14.3 Buffer Fill Mode
When the BUFM bit (ADCON2<1>) is ‘1’, the 16-word results buffer (ADRES) will be split into two
8-word groups. The 8-word buffers will alternately receive the conversion results after each
interrupt event. The initial 8-word buffer used after BUFM is set will be located at the lower
addresses of ADCBUF. When BUFM is ‘0’, the complete 16-word buffer is used for all conversion
sequences.
The decision to use the BUFM feature will depend upon how much time is available to move the
buffer contents after the interrupt, as determined by the application. If the processor can quickly
unload a full buffer within the time it takes to sample and convert one channel, the BUFM bit can
be ‘0’ and up to 16 conversions may be done per interrupt. The processor will have one sample
and conversion time before the first buffer location is overwritten.
If the processor cannot unload the buffer within the sample and conversion time, the BUFM bit
should be ‘1’. For example, if SMPI<3:0> = 0111, then eight conversions will be loaded into 1/2
of the buffer, following which an interrupt will occur. The next eight conversions will be loaded into
the other 1/2 of the buffer. The processor will therefore have the entire time between interrupts
to move the eight conversions out of the buffer.
17.14.4 Buffer Fill Status
When the conversion result buffer is split using the BUFM control bit, the BUFS status bit
(ADCON2<7>) indicates the half of the buffer that the A/D converter is currently filling. If
BUFS = 0, then the A/D converter is filling ADCBUF0-ADCBUF7 and the user software should
read conversion values from ADCBUF8-ADCBUFF. If BUFS = 1, the situation is reversed and
the user software should read conversion values from ADCBUF0-ADCBUF7.