Microchip Technology Microstick for the 5V PIC24F K-series DM240013-2 DM240013-2 Datenbogen
Produktcode
DM240013-2
2013 Microchip Technology Inc.
DS30003030B-page 211
PIC24FV16KM204 FAMILY
To perform an A/D conversion:
1.
1.
Configure the A/D module:
a) Configure the port pins as analog inputs
a) Configure the port pins as analog inputs
and/or select band gap reference inputs
(ANSx registers).
(ANSx registers).
b) Select the voltage reference source to
match the expected range on the analog
inputs (AD1CON2<15:13>).
inputs (AD1CON2<15:13>).
c)
Select the analog conversion clock to
match the desired data rate with the
processor clock (AD1CON3<7:0>).
match the desired data rate with the
processor clock (AD1CON3<7:0>).
d) Select the appropriate sample/conversion
sequence (AD1CON1<7:4> and
AD1CON3<12:8>).
AD1CON3<12:8>).
e) Configure the MODE12 bit to select A/D
resolution (AD1CON1<10>).
f)
Select how conversion results are
presented in the buffer (AD1CON1<9:8>).
presented in the buffer (AD1CON1<9:8>).
g) Select the interrupt rate (AD1CON2<6:2>).
h) Turn on the A/D module (AD1CON1<15>).
h) Turn on the A/D module (AD1CON1<15>).
2.
Configure the A/D interrupt (if required):
a) Clear the AD1IF bit.
b) Select the A/D interrupt priority.
a) Clear the AD1IF bit.
b) Select the A/D interrupt priority.
To perform an A/D sample and conversion using
Threshold Detect scanning:
1.
Threshold Detect scanning:
1.
Configure the A/D module:
a) Configure the port pins as analog inputs
a) Configure the port pins as analog inputs
(ANSx registers).
b) Select the voltage reference source to
match the expected range on the analog
inputs (AD1CON2<15:13>).
inputs (AD1CON2<15:13>).
c)
Select the analog conversion clock to
match the desired data rate with the
processor clock (AD1CON3<7:0>).
match the desired data rate with the
processor clock (AD1CON3<7:0>).
d) Select the appropriate sample/conversion
sequence (AD1CON1<7:4> and
AD1CON3<12:8>).
AD1CON3<12:8>).
e) Configure the MODE12 bit to select A/D
resolution (AD1CON1<10>).
f)
Select how the conversion results are
presented in the buffer (AD1CON1<9:8>).
presented in the buffer (AD1CON1<9:8>).
g) Select the interrupt rate (AD1CON2<6:2>).
2.
Configure the threshold compare channels:
a)
a)
Enable auto-scan; set the ASEN bit
(AD1CON5<15>).
(AD1CON5<15>).
b)
Select the Compare mode, “Greater Than,
Less Than or Windowed”; set the CMx bits
(AD1CON5<1:0>).
Less Than or Windowed”; set the CMx bits
(AD1CON5<1:0>).
c)
Select the threshold compare channels to
be scanned (AD1CSSH, AD1CSSL).
be scanned (AD1CSSH, AD1CSSL).
d)
If the CTMU is required as a current
source for a threshold compare channel,
enable the corresponding CTMU channel
(AD1CTMENH, AD1CTMENL).
source for a threshold compare channel,
enable the corresponding CTMU channel
(AD1CTMENH, AD1CTMENL).
e)
Write the threshold values into the
corresponding ADC1BUFx registers.
corresponding ADC1BUFx registers.
f)
Turn on the A/D module (AD1CON1<15>).
3.
Configure the A/D interrupt (OPTIONAL):
a)
a)
Clear the AD1IF bit.
b)
Select the A/D interrupt priority.
Note:
If performing an A/D sample and
conversion, using Threshold Detect in
Sleep Mode, the RC A/D clock source
must be selected before entering into
Sleep mode.
conversion, using Threshold Detect in
Sleep Mode, the RC A/D clock source
must be selected before entering into
Sleep mode.