|
PIC18F25K20T-ISS Datasheet, PDF (270/456 Pages) Microchip Technology – 28/40/44-Pin Flash Microcontrollers with nanoWatt XLP Technology | |||
|
◁ |
PIC18F2XK20/4XK20
19.2.9 A/D CONVERSION PROCEDURE
This is an example procedure for using the ADC to
perform an Analog-to-Digital conversion:
1. Configure Port:
⢠Disable pin output driver (See TRIS register)
⢠Configure pin as analog
2. Configure the ADC module:
⢠Select ADC conversion clock
⢠Configure voltage reference
⢠Select ADC input channel
⢠Select result format
⢠Select acquisition delay
⢠Turn on ADC module
3. Configure ADC interrupt (optional):
⢠Clear ADC interrupt flag
⢠Enable ADC interrupt
⢠Enable peripheral interrupt
⢠Enable global interrupt(1)
4. Wait the required acquisition time(2).
5. Start conversion by setting the GO/DONE bit.
6. Wait for ADC conversion to complete by one of
the following:
⢠Polling the GO/DONE bit
⢠Waiting for the ADC interrupt (interrupts
enabled)
7. Read ADC Result
8. Clear the ADC interrupt flag (required if interrupt
is enabled).
Note 1: The global interrupt can be disabled if the
user is attempting to wake-up from Sleep
and resume in-line code execution.
2: Software delay required if ACQT bits are
set to zero delay. See Section 19.3 âA/D
Acquisition Requirementsâ.
EXAMPLE 19-1: A/D CONVERSION
;This code block configures the ADC
;for polling, Vdd and Vss as reference, Frc
clock and AN0 input.
;
;Conversion start & polling for completion
; are included.
;
MOVLW
Bâ10101111â ;right justify, Frc,
MOVWF
ADCON2
; & 12 TAD ACQ time
MOVLW
Bâ00000000â ;ADC ref = Vdd,Vss
MOVWF
ADCON1
;
BSF
TRISA,0
;Set RA0 to input
BSF
ANSEL,0
;Set RA0 to analog
MOVLW
Bâ00000001â ;AN0, ADC on
MOVWF
ADCON0
;
BSF
ADCON0,GO ;Start conversion
ADCPoll:
BTFSC
ADCON0,GO ;Is conversion done?
BRA
ADCPoll
;No, test again
; Result is complete - store 2 MSbits in
; RESULTHI and 8 LSbits in RESULTLO
MOVFF
ADRESH,RESULTHI
MOVFF
ADRESL,RESULTLO
DS41303G-page 270
ï£ 2010 Microchip Technology Inc.
|
▷ |