บทที่ 4 วงจร adc
DESCRIPTION
บทที่ 4 วงจร ADC. เทอดศักดิ์ ลิ่วหาทอง สาขาวิชาอิเล็กทรอนิกส์ สถาบันเทคโนโลยีพระจอมเกล้าเจ้าคุณทหารลาดกระบัง. Analog & Digital Signal. Analog Signal. Digital Signal. Digital Signal. Analog to Digital Converter. Quantize. Sampling and Hold. Sampling Rate Selection. Sampling Rate - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/1.jpg)
บทท่ี 4 วงจร ADC
เทอดศักด์ิ ลิ่วหาทองสาขาวชิาอิเล็กทรอนิกส์
สถาบนัเทคโนโลยพีระจอมเกล้าเจา้คณุทหารลาดกระบงั
![Page 2: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/2.jpg)
Analog & Digital Signal
000000000100010000110010000101001100011101000010010101001011011000110101110011111000010001100101001110100
Digital SignalAnalog Signal
000000000100010000110010000101001100011101000010010101001011011000110101110011111000010001100101001110100
Digital Signal
![Page 3: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/3.jpg)
Analog to Digital Converter
000000000100010000110010000101001100011101000010010101001011011000110101110011111000010001100101001110100
QuantizeSampling and Hold
![Page 4: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/4.jpg)
Sampling Rate Selection
000000000100010000110010000101001100011101000010010101001011011000110101110011111000010001100101001110100
000000000100010000110010000101001100011101000010010101001011011000110101110011111000010001100101001110100
000000000100010000110010000101001100011101000010010101001011011000110101110011111000010001100101001110100
000000000100010000110010000101001100011101000010010101001011011000110101110011111000010001100101001110100
Sampling Ratefs >= 2 Bandwidth
![Page 5: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/5.jpg)
Sampling Rate Selection
000000000100010000110010000101001100011101000010010101001011011000110101110011111000010001100101001110100
000
001
010
011
100
101
ResolutionLSB = (Vref+-Vref-)/2k
vin
VRef+
Vref-
D0D1
Dk-1
![Page 6: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/6.jpg)
ADC ชนิด Successive Approximation
![Page 7: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/7.jpg)
ADC ของ PIC18F8722
• PIC18F8722 มวีงจร Analog to Digital Converter ขนาด 10 bit ทัง้หมด 16 วงจร (AN0-AN15)
![Page 8: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/8.jpg)
ADC ของ PIC18F8722
![Page 9: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/9.jpg)
ADC ของ PIC18F8722
![Page 10: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/10.jpg)
ADC ของ PIC18F8722
![Page 11: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/11.jpg)
Register ของ ADC
• PIC มี Register ท่ีเก่ียวกับ ADC ทัง้หมด 5 ตัวคือ1. A/D Result High Register (ADRESH)2. A/D Result Low Register (ADRESL)3. A/D Control Register 0 (ADCON0)4. A/D Control Register 1 (ADCON1)5. A/D Control Register 2 (ADCON2)
![Page 12: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/12.jpg)
ADRESH และ ADRESL
• ADRESH และ ADRESL เป็น Register ท่ีใชเ้ก็บ ผลลัพธข์องการแปลง ADC
![Page 13: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/13.jpg)
ADCON0
• ADCON0 เป็น Register ท่ีใชก้ำาหนดวา่จะใหว้งจรVAin ของวงจร ADC ต่อกับ AN ตัวท่ีเท่าใด(CHS3:0)
• สัง่ให้ ADC เริม่ทำางาน Go/DONE• และตรวจสอบวา่ ADC ทำางานเสรจ็หรอืยงั
ADON
![Page 14: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/14.jpg)
ADCON0
![Page 15: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/15.jpg)
ADCON1
• ADCON1 เป็น Register ท่ีใชก้ำาหนดให้ AN ตัวใด ทำางานเป็น Analog Input Port หรอืทำางานเป็น
Digital I/O Port (PCFG3:0)• และกำาหนดให้ RA3/AN3 เป็น VRef+ และ RA2/AN2
เป็น VRef- (VCFG1:0)
![Page 16: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/16.jpg)
ADCON1
![Page 17: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/17.jpg)
ADCON2
• ADCON2 เป็น
Register ท่ี ใชก้ำาหนด
Acquisition Time ของ
วงจร ADC
![Page 18: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/18.jpg)
Acquisition Time
• สญัญาณ Analog จะถกูป้อนผ่านสวทิซไ์ปเขา้ที่ขา VAin ของวงจร ADC
• จากนัน้ CHOLD จะถกูชารจ์ประจุใหม้แีรงดันเท่ากับขาVAin
![Page 19: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/19.jpg)
Acquisition Time
• เพื่อใหก้ารแปลง ADC มคีวามถกูต้อง จะต้องให้ แรงดันของ CHOLD เท่ากับ VAin
• เนื่องจาก VAin ชารจ์ประจุ CHOLD ผ่าน RS, RSS ดังนัน้ จงึต้องใชเ้วลาในการชารจ์ประจุ เราเรยีกเวลาดัง
กล่าววา่ Acquisition Time (TACQ)
![Page 20: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/20.jpg)
Acquisition Time
![Page 21: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/21.jpg)
• เราสามารถตัง้ค่า Acquisition Time ได้จากACQT<2:0>
• เมื่อเซท็ให้ GO/DONE = 1 PIC จะรอเป็นเท่ากับAcquisition Time จากนัน้จงึเริม่แปลง ADC
• และเมื่อแปลง ADC เสรจ็แล้ว GO/DONE จะเท่ากับ0
![Page 22: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/22.jpg)
ขัน้ตอนการแปลง ADC
![Page 23: บทที่ 4 วงจร ADC](https://reader033.vdocuments.site/reader033/viewer/2022061520/56815b22550346895dc8e206/html5/thumbnails/23.jpg)
#include <p18f8722.h>#include <adc.h>#include <delays.h>#include <timers.h>
#define NUMBER_OF_LEDS 8
#pragma code
int result;int shift;void main(void){
TRISAbits.TRISA0=1;TRISD = 0;PORTD = 0;
ADCON1 = 0b00001110;ADCON2 = 0b10001010;
ADCON0bits.ADON = 1;while(1){
ADCON0bits.GO=1;while(ADCON0bits.GO);result = ADRES;result >>=2;if(result==0) result = 1;
// PORTD = result;PORTD=1<<shift;shift++;shift %=8;
Delay10KTCYx(20);}
}