You are on page 1of 23

VI IU KHIN

NHM THC HIN: 05 BK - B

I. THNH LP NHM
Danh sch nhm

STT

H V TN

MSSV

Nguyn Hu Tr

20902928

T Phc Hong

20900946

Trng Thng Qun

20902156

Cao Nht Quang

20902087

BK - B

09:48:57 AM

GHI CH

II. TI

M Phng v iu Khin Nhit

BK - B

09:48:57 AM

III. NGUYN L HOT NG


1. Mch nguyn l

BK - B

09:48:57 AM

III. NGUYN L HOT NG


1. Mch nguyn l

BK - B

09:48:57 AM

III. NGUYN L HOT NG


1. Mch nguyn l

BK - B

09:48:57 AM

III. NGUYN L HOT NG


1. Mch nguyn l

BK - B

09:48:57 AM

III. NGUYN L HOT NG


1. Mch nguyn l

BK - B

09:48:57 AM

III. NGUYN L HOT NG


2. M phng bng Proteus

BK - B

09:48:57 AM

III. NGUYN L HOT NG


3. Gii thiu v Module ADC ca PIC16F887

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

Sens
or
Nhit , m,
m Thanh, nh
Sng,
p Sut, .

BK - B

Dn
g
p

Analo
g

09:48:58 AM

AD
C

Digit
al

III. NGUYN L HOT NG


3. Gii thiu v Module ADC ca PIC16F887

Ri rc ha tn hiu lin tc

BK - B

09:48:58 AM

III. NGUYN L HOT NG


3. Gii thiu v Module ADC ca PIC16F887

Chu k ly mu

phn gii: 2n

Voltage reference(Vref)
Vref phi l ngun n nh.
V_in = Vref -> ADC c v
gi tr max: 111111(n
bit 1)

x
Vin
Vref
1023

BK - B

09:48:58 AM

III. NGUYN L HOT NG


3. Gii thiu v Module ADC ca PIC16F887

Module ADC PIC16F887


10 bit
14 channels AN0 AN13
The conversion result (10 bit) is store into the
ADC result registers: ADRESL & ADRESH
Select Internal Vref or External Vref
The ADC can generate an interrupt upon
completion of a conversion

BK - B

09:48:58 AM

III. NGUYN L HOT NG


3. Gii thiu v Module ADC ca PIC16F887

How to Use Module ADC PIC16F88

BK - B

Port configuration
Channel seletion
ADC voltage reference selection
ADC conversion clock source
Interrupt control
Results formatting

09:48:58 AM

III. NGUYN L HOT NG


3. Gii thiu v Module ADC ca PIC16F887

How to Use Module ADC PIC16F88

Port configuration
ANSEL Register -> Analog (Set bit =1)
ANSEL: i vi AN0 AN7.
ANSELH: i vi AN8 AN13.
TRIS Register Input (Set bit = 1)
Example: use ADC channel AN2 (RA2,
pin4)
ANSEL |= 0x04;
TRISA2 = 1;

BK - B

09:48:58 AM

III. NGUYN L HOT NG


3. Gii thiu v Module ADC ca PIC16F887

How to Use Module ADC PIC16F88

Channel seletion
CHS bits CHS<2:0> chn knh cho vic
ly mu.
Example: CHS<2:0> = 0010 chn AN2
CHS3 = 0;
CHS2 = 0;
CHS1 = 1;
CHS0 = 0;
BK - B

09:48:58 AM

III. NGUYN L HOT NG


3. Gii thiu v Module ADC ca PIC16F887

How to Use Module ADC PIC16F88

ADC voltage reference selection

VCFG<1:0> bits of the ADCON0 register


AVDD AVSS: 5V 0V internal V-ref
Example: VCFG1 = 0;
VCFG0 = 0;
// chn V_ref ni
VCFG1 = 1;
VCFG0 = 1;
// chn V_ref ngoi
Ch : V_ref ngoi phi ni v chn AN2 v AN3.
BK - B

09:48:58 AM

III. NGUYN L HOT NG


3. Gii thiu v Module ADC ca PIC16F887

How to Use Module ADC PIC16F88

ADC conversion clock source

The ADC bits of the ADCON0 register


Example: ADCS1 = 0;
ADCS0 = 0; - fsample = Fosc/8.

BK - B

09:48:58 AM

III. NGUYN L HOT NG


3. Gii thiu v Module ADC ca PIC16F887

How to Use Module ADC PIC16F88

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.
Must set PEIE and GIE bit to enable Global
Interrupt & Peripheral Interrupt.

BK - B

Results formatting
09:48:58 AM

III. NGUYN L HOT NG


4. Code mu setup module ADC

void adc_init()
{
//
ADCS
//
ADCS
//
ADCS
//
ADCS
ADCS1 = 0;
ADCS0 = 1;

// Voltage reference: Internal Vref


//
VCFG <1:0> = 00 Internal Vref
//
VCFG <1:0> = 11 External Vref
VCFG1 = 0;
VCFG0 = 0;

// Select Input chanel: AN3


//
CHS <3:0> = 0000
//
CHS <3:0> = 0001
//
CHS <3:0> = 0010
//
...
//
CHS <3:0> = 1101
CHS3 = 0;
CHS2 = 1;
CHS1 = 0;
CHS0 = 0;

// Result format: Right


//
ADFM = 1 Right justified
//
ADFM = 0 Left justified
ADFM = 1;

<1:0>
<1:0>
<1:0>
<1:0>

=
=
=
=

00
01
10
11

Fosc/2
Fosc/8
Fosc/32
F_RC

Select AN0
Select AN1
Select AN2
Select AN13

// Turn on ADC Module


ADON = 1;
//delay to wait for adc module init.
__delay_ms (1);
}

BK - B

09:48:58 AM

III. NGUYN L HOT NG


4. Code mu setup module ADC

void port_init()
{
ANS4 = 1; // Chon kenh ADC AN4
ANSELH = 0;
TRISA = 0b00100000;
//RA5 input

void int_init()
{
GIE = 1; //Global Interrupt Enable
PEIE = 1; //Peripheral Interrupt Enable
ADIE = 1; //ADC Interrupt Enable
ADIF = 0; //Clear ADC Interrupt Flag
}

BK - B

09:48:58 AM

IV. M PHNG

BK - B

09:48:58 AM

THANK YOU FOR


YOUR ATTENTION

BK - B

09:48:58 AM

You might also like