Analog-to-Digital Conversion: Industrial Embedded Systems
Analog-to-Digital Conversion: Industrial Embedded Systems
Outline
ADC architectures
Steps of A/D conversion
ADC architectures
SAR
Successice Approximation Register AD Converter with feedback Generally N=8-16 bit (PIC24FJ128GA010 has N=10bit ADC) Conversion time: N cycle
Initially set VDAC to Vref, then see if Vin higher or lower than VDAC. If > Vref, then next guess is between Vref and Vref, else next guess is between Vref and GND. Do this for each bit of the ADC
ADC architectures
Counter ramp ADC
Simple Slow Conversion time: 2N cycle
Flash ADC
Fast Conversion time: 1 cycle Requires the most transistors of any architecture, N-bit converter requires 2N-1 comparators. Commercially available flash converters up to 12 bits.
If input voltage is higher, a voltage divider can be used to fit the voltage level. To imrpove the performance a voltage follower is also applied (use a rail-to-rail Op-Amp)
Steps of AD conversion
Configuring AD modul Enable analog input channel(s) Set the reference voltage Clock cycle, clock source (TAD) Sampling and conversion settings Form of the result Enable modul Configure A/D interrupt (if required) Delete flag belonging to the ADC Enable interrupt Select the given analog channel Sampling time (1-31 TAD) Time to charge up the storage capacitor Conversion time (12 TAD) The end of the conversion is indicated by a flag Read the value from the buffer register If required delete interrupt flag
Configure AD modul
AD module has 6 Special Function Register (SFR) AD1CON1, AD1CON2, AD1CON3, AD1CHS, AD1PCFG, AD1CSSL PIC24 has 16 analog input pin (AN0-AN15) Enable analog input channel(s) Using AD1PCFG register 0s will mark the analog inputs, and 1s will configure the respective pins as digital inputs AD1PCFG = 0xFFDF; // AN5 analog input Set the reference voltage AD1CON2 register<15:13> Internal voltage level (AVDD, AVSS) External reference voltage Combination of the two AD1CON2bits.VCFG = 0b000;
// ref+=VDD, ref-=VSS
7
Configure AD modul
Clock cycle (TAD) In the case of PIC24FJ128GA010 minimum clock cylce TAD is 75ns Clock derived from sytem clock (TCY) AD1CON3bits.ARDC = 0; //system clock, TCY=2*TOSC
TAD=TCY (ACDS + 1) AD1CON3bits.ADCS = 0;
//TAD=TCY=250ns>75ns
Configure AD modul
Sampling time Its value depends on the input resistane of the signal and the storage capacitor The frequency of the input signals also has to be taken into consideration The accuracy can be improved by increasing the sampling time
Configure AD modul
Sampling and conversion settings The sampling time and the beginning of the conversion can be determined By software (delete AD1CON1bits.SAMP bit) By hardware (Active transition on INT0 pin ends sampling and starts conversion) Automatic conversion AD1CON3bits.SSRC = 0b000; //software conversion AD1CON3bits.SSRC = 0b111; //automatic conversion In the case of software conversion the enough sampling time should be guaranteed in the code In the case of automatic conversion the sampling has to set: AD1CON1bits.SAMC = 31; //TSAMP=31TAD=7.75us After conversion automatically Sampling begins immediately after last conversion completes Sampling begins when SAMP bit is set AD1CON1.ASAM = 0; //no automatic sampling
10
Configure AD modul
Data output format integer/fractional and signed/nonsigned AD1CON1bits.FORM = 0b00; //integer PIC put the result of the AD conversion in to a 16-bit register ADC1BUF x
//turn on ADC
11
Configure AD modul
void initADC() { AD1PCFG = 0xFFDF; AD1CON1bits.SSRC = AD1CON1bits.FORM = AD1CON2bits.VCFG = AD1CON3bits.ADRC = AD1CON3bits.ADCS = AD1CON1bits.ADON = }
// enable AN5 chnnel //software conversion //integer // ref+=VDD, ref-=VSS //system clock, TCY=2*TOSC //TAD=TCY=250ns>75ns //turn on ADC
12
Temperature sensor
13
ADC interrupt
Priority level IPC3bits.AD1IP Flag IFS0bits.AD1IF Enable bit IEC0bits.AD1IE We can select, after how many samling/conversion We can give after how many completion of sample/convert sequence an interrupt occur AD1CON2bits.SMPI Interrupt function
void _ISR _ADC1Interrupt (void) { //instruction IFS0bits.AD1IF = 0; // delete ADC interrupt flag!!! }
14