Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 26 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
26
Dung lượng
1,11 MB
Nội dung
Chuyên đề II Vi điều khiển ứng dụng ADC Ví dụ về ADC Conversion time Mạch ứng dụng To help designing analog hardware filters, Microchip offers a small application named FilterLab A/D 12-bit/10bit Resolution with +/- 1-bit accuracy 100 K Samples / Sec conversion rate Sample/Hold Amplifier Up to 16 Analog Inputs Analog Input Range: (VREF-) to Multiple conversion trigger sources (VREF+) Hardware A/D block Các bước khởi động ADC Configure theA/D module configure the port pins as analogue inputs, voltage reference, and digital I/O pins, select A/D converter input channel, select A/D conversion clock, select A/D conversion trigger source, turn on A/D module; Tiếp ConfigureA/D interrupt (if required) clear ADIF bit (IFS0,11>), select A/D interrupt priority, set ADIE bit (IEC0); Start sampling Wait the required acquisition time; Trigger acquisition end, start conversion; Tiếp Wait for A/D to complete, by either waiting for the A/D interrupt, or waiting for the DONE bit to get set; Read A/D result buffer, clear ADIF bit if required 10 Acquisition / Conversion Timing 12 Chọn kênh 13 Manual Acquisition / Conversion 14 Setting A/D Conversion Time ADCS sets conversion clock period ADCS value limited by maximum SPS of A/D Related to clock used by processor Tcy =1 / MIPS Tconv =Desired conversion time Clocks per conversion =14 for 12-bit A/D 15 ADCS =((2 * Tconv) / (14 * Tcy)) - Ví dụ ADCS =((2 * Tconv) / (CConv * Tcy)) - Example: 30 MIPS device, 12-bit A/D, max rate Tcy =1 / 30 MIPS =33.3 nsec Tconv =10 mSec (min) by specification ADCS =((2 * 10*10-6) / (14 * 33.3*10-9)) – =41.8 ADCS =42 =0x24 =0b101010 Tad =(ADCS+1) * (Tcy/2) =716 nsec Tconv =14 * Tad=10.03 mSec 16 Internal AD RC clock ADRC enables internal AD RC clock ADCS bits are ignored 17 For 12-bit A/D Nominal Rate =47 KSPS Nominal Tconv =21 mSec Chu kỳ ADC 18 Ví dụ lấy mẫu chuyển đổi thủ công 19 Ví dụ khởi động timer 20 C sample 21 A/D Buffer Module has a 16-word buffer Module writes results into buffer in completion Buffer will reset to ADCBUF0 after each Interrupt User software has read only access to buffer 22 Buffer Data Formats Results presented in one of four formats Integer (DOUT =0000 dddd dddd dddd) Fractional (DOUT =dddd dddd dddd 0000) Signed Integer (DOUT =ssss sddd dddd dddd) Signed fractional (DOUT =sddd dddd dddd 0000) 23 Channel Scanning When (CSCNA =1) group A will scan analog inputs 24 C examples void initADC( int amask) { AD1PCFG =amask; // select analog input pins AD1CON1 =0; // manual conversion sequence control AD1CSSL =0; // no scanning required AD1CON2 =0; // use MUXA, AVss and AVdd are used as Vref+/AD1CON3 =0x1F02; // Tad =2 x Tcy =125ns >75ns AD1CON1bits.ADON =1; // turn on theADC } //initADC int readADC( int ch) { AD1CHS =ch; // select analog input channel AD1CON1bits.SAMP =1; // start sampling TMR1 =0; // wait for sampling time while (TMR1[...]... Tconv =10 mSec (min) by specification ADCS =((2 * 10*10-6) / (14 * 33.3*10-9)) – 1 =41.8 ADCS =42 =0x24 =0b101010 Tad =(ADCS+1) * (Tcy/2) =716 nsec Tconv =14 * Tad=10.03 mSec 16 Internal AD RC clock ADRC enables internal AD RC clock ADCS bits are ignored 17 For 12-bit A/D Nominal Rate =47 KSPS Nominal Tconv =21 mSec Chu kỳ ADC 18 Ví dụ lấy mẫu và chuyển đổi thủ công 19 Ví dụ về khởi... Conversion 14 Setting A/D Conversion Time ADCS sets conversion clock period ADCS value limited by maximum SPS of A/D Related to clock used by processor Tcy =1 / MIPS Tconv =Desired conversion time Clocks per conversion =14 for 12-bit A/D 15 ADCS =((2 * Tconv) / (14 * Tcy)) - 1 Ví dụ ADCS =((2 * Tconv) / (CConv * Tcy)) - 1 Example: 30 MIPS device, 12-bit A/D, max rate Tcy =1 / 30 MIPS... will scan analog inputs 24 C examples void initADC( int amask) { AD1PCFG =amask; // select analog input pins AD1CON1 =0; // manual conversion sequence control AD1CSSL =0; // no scanning required AD1CON2 =0; // use MUXA, AVss and AVdd are used as Vref+/AD1CON3 =0x1F02; // Tad =2 x Tcy =125ns >75ns AD1CON1bits.ADON =1; // turn on theADC } //initADC int readADC( int ch) { AD1CHS =ch; // 1 select analog... return ADC1 BUF0; // 6 read the conversion result } // readADC 25 Automatic sampling timing void initADC( int amask) { AD1PCFG =amask; // select analog input pins AD1CON1 =0x00E0; // automatic conversion start after sampling AD1CSSL =0; // no scanning required AD1CON2 =0; // use MUXA, AVss and AVdd are used as Vref+/AD1CON3 =0x1F02; // Tsamp =32 x Tad; Tad=125ns AD1CON1bits.ADON =1; // turn on theADC }... =0x1F02; // Tsamp =32 x Tad; Tad=125ns AD1CON1bits.ADON =1; // turn on theADC } //initADC int readADC( int ch) { AD1CHS =ch; // 1 select analog input channel AD1CON1bits.SAMP =1; // 2 start sampling while (!AD1CON1bits.DONE); // 3 wait for the conversion to complete return ADC1 BUF0; // 4 read the conversion result } // readADC 26 ... dụ lấy mẫu và chuyển đổi thủ công 19 Ví dụ về khởi động bằng timer ngoài 20 C sample 21 A/D Buffer Module has a 16-word buffer Module writes results into buffer in completion Buffer will reset to ADCBUF0 after each Interrupt User software has read only access to buffer 22 Buffer Data Formats Results presented in one of four formats Integer (DOUT =0000 dddd dddd dddd) Fractional (DOUT =dddd ... =33.3 nsec Tconv =10 mSec (min) by specification ADCS =((2 * 10*10-6) / (14 * 33.3*10-9)) – =41.8 ADCS =42 =0x24 =0b101010 Tad =(ADCS+1) * (Tcy/2) =716 nsec Tconv =14 * Tad=10.03 mSec... Vref+/AD1CON3 =0x1F02; // Tad =2 x Tcy =125ns >75ns AD1CON1bits.ADON =1; // turn on theADC } //initADC int readADC( int ch) { AD1CHS =ch; // select analog input channel AD1CON1bits.SAMP =1; // start... (!AD1CON1bits.DONE); // wait for the conversion to complete return ADC1 BUF0; // read the conversion result } // readADC 25 Automatic sampling timing void initADC( int amask) { AD1PCFG =amask; // select analog