23
VI ĐIỀU KHIỂN NHÓM THỰC HIỆN: 05 – BK - B

BK - B Fightingggg(2)

Embed Size (px)

DESCRIPTION

Vi dieu khiển

Citation preview

PowerPoint Presentation

VI IU KHINNHM THC HIN: 05 BK - BI. THNH LP NHM Danh sch nhmSTTH V TNMSSVGHI CH1Nguyn Hu Tr209029282T Phc Hong209009463Trng Thng Qun209021564Cao Nht Quang20902087BK - B12:42 PMII. TIM Phng v iu Khin Nhit BK - B12:42 PM

III. NGUYN L HOT NG1. Mch nguyn lBK - B12:42 PM

III. NGUYN L HOT NG1. Mch nguyn lBK - B12:42 PM

III. NGUYN L HOT NG1. Mch nguyn lBK - B12:42 PM

III. NGUYN L HOT NG1. Mch nguyn lBK - B12:42 PM

III. NGUYN L HOT NG1. Mch nguyn lBK - B12:42 PM

III. NGUYN L HOT NG2. M phng bng ProteusBK - B12:42 PM

III. NGUYN L HOT NG3. Gii thiu v Module ADC ca PIC16F887BK - B12:42 PMADC l b chuyn i tn hiu tng t thnh tn hiu sAnalogADCDigitalDngpNhit , m, m Thanh, nh Sng, p Sut, .3. Gii thiu v Module ADC ca PIC16F887BK - B12:42 PMRi rc ha tn hiu lin tc

III. NGUYN L HOT NG3. Gii thiu v Module ADC ca PIC16F887BK - B12:42 PMChu k ly mu

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

III. NGUYN L HOT NG3. Gii thiu v Module ADC ca PIC16F887BK - B12:42 PM10 bit14 channels AN0 AN13The conversion result (10 bit) is store into the ADC result registers: ADRESL & ADRESHSelect Internal Vref or External VrefThe ADC can generate an interrupt upon completion of a conversionModule ADC PIC16F887III. NGUYN L HOT NG3. Gii thiu v Module ADC ca PIC16F887BK - B12:42 PM Port configuration Channel seletion ADC voltage reference selection ADC conversion clock source Interrupt control Results formattingHow to Use Module ADC PIC16F887III. NGUYN L HOT NG3. Gii thiu v Module ADC ca PIC16F887BK - B12:42 PM Port configurationANSEL 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;

How to Use Module ADC PIC16F887III. NGUYN L HOT NG3. Gii thiu v Module ADC ca PIC16F887BK - B12:42 PM Channel seletionCHS bits CHS chn knh cho vic ly mu.Example: CHS = 0010 chn AN2CHS3 = 0;CHS2 = 0;CHS1 = 1;CHS0 = 0;How to Use Module ADC PIC16F887III. NGUYN L HOT NG3. Gii thiu v Module ADC ca PIC16F887BK - B12:42 PM ADC voltage reference selectionVCFG bits of the ADCON0 registerAVDD AVSS: 5V 0V internal V-refExample: VCFG1 = 0; VCFG0 = 0; // chn V_ref ni VCFG1 = 1; VCFG0 = 1; // chn V_ref ngoiCh : V_ref ngoi phi ni v chn AN2 v AN3.How to Use Module ADC PIC16F887III. NGUYN L HOT NG3. Gii thiu v Module ADC ca PIC16F887BK - B12:42 PM ADC conversion clock source The ADC bits of the ADCON0 registerExample: ADCS1 = 0; ADCS0 = 0; - fsample = Fosc/8.How to Use Module ADC PIC16F887

III. NGUYN L HOT NG3. Gii thiu v Module ADC ca PIC16F887BK - B12:42 PM Interrupt controlThe 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.

Results formattingHow to Use Module ADC PIC16F887III. NGUYN L HOT NG4. Code mu setup module ADCBK - B12:42 PMvoid adc_init(){// ADCS = 00 Fosc/2// ADCS = 01 Fosc/8// ADCS = 10 Fosc/32// ADCS = 11 F_RCADCS1 = 0;ADCS0 = 1;

// Voltage reference: Internal Vref// VCFG = 00 Internal Vref// VCFG = 11 External VrefVCFG1 = 0;VCFG0 = 0;

// Select Input chanel: AN3// CHS = 0000 Select AN0// CHS = 0001 Select AN1// CHS = 0010 Select AN2// ...// CHS = 1101 Select AN13CHS3 = 0;CHS2 = 1;CHS1 = 0;CHS0 = 0;

// Result format: Right// ADFM = 1 Right justified// ADFM = 0 Left justifiedADFM = 1;

// Turn on ADC ModuleADON = 1;

//delay to wait for adc module init.__delay_ms (1);}III. NGUYN L HOT NG4. Code mu setup module ADCBK - B12:42 PMvoid port_init(){ANS4 = 1; // Chon kenh ADC AN4ANSELH = 0;TRISA = 0b00100000; //RA5 input

}

void int_init(){GIE = 1; //Global Interrupt EnablePEIE = 1; //Peripheral Interrupt EnableADIE = 1; //ADC Interrupt EnableADIF = 0; //Clear ADC Interrupt Flag}III. NGUYN L HOT NGIV. M PHNGBK - B12:42 PMBK - B12:42 PMThank you for your attention