This is an example procedure for using the ADC
to perform an Analog-to-Digital Conversion:
- 1.Configure Port:
- a.Disable
pin output driver (refer to the TRISx register)
- b.Configure
pin as analog (refer to the ANSELx register)
- 2.Configure the ADC module:
- a.Select
ADC conversion clock
- b.Configure
voltage reference
- c.Select
ADC input channel
- d.Configure precharge (ADPRE) and acquisition (ADACQ) time period
- e.Turn on
ADC module
- 3.Configure ADC interrupt (optional):
- a.Clear ADC
interrupt flag
- b.Enable
ADC interrupt
- c.Enable
global interrupt (GIE bit)(1)
- 4.If ADACQ !=
0
, software must wait the required
acquisition time(2).
- 5.Start conversion by setting the GO bit.
- 6.Wait for ADC conversion to complete by
one of the following:
- Polling
the GO bit
- Waiting
for the ADC interrupt (if interrupt is enabled)
- 7.Read ADC Result.
- 8.Clear the ADC interrupt flag (if
interrupt is enabled).
Notes:
- 1.With global interrupts disabled (GIE
=
0
), the device will wake from Sleep, but will not enter an
Interrupt Service Routine.
- 2.Refer to the ADC Acquisition Requirements section for more details.