Chuyên đề II
Vi điều khiển và ứng dụng
ADC
Ví dụ về ADC
2
Conversion time
3
Mạch ứng dụng
To help designing analog hardware filters, Microchip offers a small
application named FilterLab
4
A/D
12-bit/10bit Resolution with +/- 1-bit accuracy
100 K Samples / Sec conversion rate
1 Sample/Hold Amplifier
Up to 16 Analog Inputs
Analog Input Range: (VREF-) to
Multiple conversion trigger sources
5
(VREF+)
Hardware
6
A/D block
7
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;
8
Tiếp
ConfigureA/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
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
Voltage reference
11
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)) - 1
Ví 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
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 độ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 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; // 1. select analog input channel
AD1CON1bits.SAMP =1; // 2. start sampling
TMR1 =0; // 3. wait for sampling time
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