Các bước khởi động ADCConfigure the A/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 co
Trang 1Chuyên đề II
Vi điều khiển và ứng dụng
Trang 2Ví dụ về ADC
2
Trang 3Conversion time
3
Trang 4Mạch ứng dụng
4
To help designing analog hardware filters, Microchip offers a small application named FilterLab
Trang 66
Trang 7A/D block
7
Trang 8Các bước khởi động ADC
Configure the A/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;
8
Trang 9Configure A/D interrupt (if required)
clear ADIF bit (IFS0,11>),
select A/D interrupt priority,
set ADIE bit (IEC0<11>);
Start sampling
Wait the required acquisition time;
Trigger acquisition end, start conversion;
9
Trang 10Wait 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
Trang 11Voltage reference
11
Trang 12Acquisition / Conversion Timing
12
Trang 13Chọn kênh
13
Trang 14Manual Acquisition / Conversion
14
Trang 15Setting A/D Conversion Time
ADCS sets conversion clock period
D
Related to clock used by processor
Tcy = 1 / MIPS
Tconv = Desired conversion time
Clocks per conversion = 14 for 12-bit A/D
ADCS = ((2 * Tconv) / (14 * Tcy)) - 1
15
Trang 16Ví dụ
ADCS = ((2 * Tconv) / (CConv * Tcy)) - 1
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)) – 1
= 41.8
ADCS = 42 = 0x24 = 0b101010
Tad = (ADCS+1) * (Tcy/2) = 716 nsec
Tconv = 14 * Tad= 10.03 mSec
16
Trang 17Internal AD RC clock
ADRC enables internal AD RC clock
ADCS bits are ignored
For 12-bit A/D
Nominal Rate = 47 KSPS Nominal Tconv = 21 mSec
17
Trang 18Chu kỳ ADC
18
Trang 19Ví dụ lấy mẫu và chuyển đổi thủ công
19
Trang 20Ví dụ về khởi động bằng timer ngoài
20
Trang 21C sample
21
Trang 22Buffer will reset to
ADCBUF0 after each
Interrupt
User software has
read only access to buffer
22
Trang 23Buffer Data Formats
Results presented in one of four formats
Trang 24Channel Scanning
When (CSCNA = 1) group A will scan analog inputs
24
Trang 25AD1CON2 = 0; // use MUXA, AVss and AVdd are used as AD1CON3 = 0x1F02; // Tad = 2 x Tcy = 125ns >75ns
Vref+/-AD1CON1bits.ADON = 1; // turn on the ADC
while (TMR1< 100); // 6.25 us AD1CON1bits.DONE = 1; // 4 start the conversion while (!AD1CON1bits.DONE); // 5 wait for the conversion to complete return ADC1BUF0; // 6 read the conversion result
} // readADC
25
Trang 26AD1CON2 = 0; // use MUXA, AVss and AVdd are used as AD1CON3 = 0x1F02; // Tsamp = 32 x Tad; Tad=125ns
Vref+/-AD1CON1bits.ADON = 1; // turn on the ADC } //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 ADC1BUF0; // 4 read the conversion result
} // readADC
26