You are on page 1of 18

Cu lc b Nghin cu Khoa hc Khoa in in t

ADC l b chuyn i tn hiu tng t thnh tn hiu s


Dng p

Sensors

Analog Nhit , m, m thanh, nh sng, p sut, gia tc,

ADC

Digital

Nhim v chuyn i 1 i lng lin tc thnh 1 i lng digital ri rc (continuous to discrete) (Ri rc ho tn hiu lin tc)

Sample & Hold

Sample & Hold

Sample Time: Chu k ly mu

nT

Resolution: phn gii phn gii n-bit ngha l ADC c th biu din c 2n gi tr ca tn hiu analog ng vo Voltage reference (Vref) Khi V_in = Vref ADC c v gi tr max: 1111111 (n-bit 1) Vref phi l ngun p rt n nh

10-bit 14 channels AN0-AN13 The conversion result (10-bit) is stored into the ADC result registers: ADRESL & ADRESH Selectable internal Vref or External Vref The ADC can generate an interrupt upon completion of a conversion.

ADC Configuration 1. Port configuration 2. Channel selection 3. ADC voltage reference selection 4. ADC conversion clock source 5. Interrupt control 6. Results formatting

ADC Configuration 1. Port configuration ANSEL Register Analog (set bit = 1) ANSEL: AN0-7 ANSELH: AN8-13 TRIS Register Input (set bit =1)

Example: use ADC channel AN3 (RA3, pin5) ANSEL |= 1<<3; TRISA3=1;

ADC Configuration 2. Channel selection The CHS bits CHS<3:0> of the ADCON0 register determine which channel is connected to the sample and hold circuit. Example CHS<3:0> = 0011 CHS3=0; CHS2=0; CHS1=1; CHS0=1; select AN3

ADC Configuration 3. ADC voltage reference selection VCFG <1:0>bits of the ADCON0 register AVDD - AVSS : 5V 0V internal V_ref Example VCFG1=0; VCFG0=0; Select internal V_ref VCFG1=1; VCFG0=1; Select external V_ref (External V_ref must be connected to pin AN2 & AN3)

ADC Configuration 4. ADC conversion clock source The ADCS bits of the ADCON0 register. Example ADCS1=0; ADCS0=1; //Select sample time TAD=8*MC //or fsample = Fosc/8

ADC Configuration 4. ADC conversion clock source

ADC Configuration 5. Interrupt control The ADC interrupt flag is the ADIF bit in the PIR1 register. The ADC interrupt enable is the ADIE bit in the PIE1 register. The ADIF bit must be cleared in software. You must set PEIE bit and GIE bit to enable Global Interrupt & Peripheral Interrupt

ADC Configuration 6. Results formatting The ADFM bit of the ADCON0 register controls the output format.

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 Turn on ADC module 3. Configure ADC interrupt (optional): Clear ADC interrupt flag Enable ADC interrupt Enable peripheral interrupt Enable global interrupt

4. Wait the required acquisition time. 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).

You might also like