AVR121: Enhancing ADC resoluion by oversampling Feaures Increasing he resoluion by oversampling Averaging and decimaion Noise reducion by averaging samples 8-bi Microconrollers Applicaion Noe 1 Inroducion Amel s AVR conroller offers an Analog o Digial Converer wih 10-bi resoluion. In mos cases 10-bi resoluion is sufficien, bu in some cases higher accuracy is desired. Special signal processing echniques can be used o improve he resoluion of he measuremen. By using a mehod called Oversampling and Decimaion higher resoluion migh be achieved, wihou using an exernal ADC. This Applicaion Noe explains he mehod, and which condiions need o be fulfilled o make his mehod work properly. Figure 1-1. Enhancing he resoluion. A/D A/D A/D 10-bi 11-bi 12-bi Rev.
2 Theory of operaion 2.1 Sampling frequency Before reading he res of his Applicaion Noe, he reader is encouraged o read Applicaion Noe AVR120 - Calibraion of he ADC, and he ADC secion in he AVR daashee. The following examples and numbers are calculaed for Single Ended Inpu in a Free Running Mode. ADC Noise Reducion Mode is no used. This mehod is also valid in he oher modes, hough he numbers in he following examples will be differen. The ADCs reference volage and he ADCs resoluion define he ADC sep size. The ADC s reference volage, V REF, may be seleced o AVCC, an inernal 2.56V / 1.1V reference, or a reference volage a he AREF pin. A lower V REF provides a higher volage precision bu minimizes he dynamic range of he inpu signal. If he 2.56V V REF is seleced, his will give he user ~2.5mV accuracy on he conversion resul, and he highes inpu volage ha is measured is 2.56V. Alernaively one could consider using he ADC inpu channels wih gain sage. This will give he user he possibiliy of measuring an analog signal wih beer volage precision, a he expense of he ADCs dynamic range. If i is no accepable o rade dynamic range for beer volage resoluion, one could choose o rade oversampling of he signal for improved resoluion. This mehod is however limied by he characerisic of he ADC: Using oversampling and decimaion will only lower he ADCs quanizaion error, i does no compensae for he ADCs inegral non-lineariy. The Nyquis heorem saes ha a signal mus be sampled a leas wice as fas as he bandwidh of he signal o accuraely reconsruc he waveform; oherwise, he high-frequency conen will alias a a frequency inside he specrum of ineres (passband). The minimum required sampling frequency, in accordance o he Nyquis Theorem, is he Nyquis Frequency. Equaion 2-1. The Nyquis Frequency f > 2 nyquis f signal Where f signal is he highes frequency of ineres in he inpu signal. Sampling frequencies above f nyquis are called oversampling. This sampling frequency, however, is jus a heoreical absolue minimum sampling frequency. In pracice he user usually wishes he highes possible sampling frequency, o give he bes possible represenaion of he measured signal, in ime domain. One could say ha in mos cases he inpu signal is already oversampled. The sampling frequency is a resul of prescaling he CPU clock; a lower prescaling facor gives a higher ADC clock frequency. A a cerain poin, a higher ADC clock will decrease he accuracy of he conversion as he Effecive Number Of Bis, ENOB, will decrease. All ADCs has bandwidh limiaions, AVRs ADC is no excepion. According o he daashee, o ge a 10 bis resoluion on he conversion resul, he ADC clock frequency should be 50kHz 200kHz. When he ADC clock is 200kHz, he sampling frequency is ~15kSPS, which confines he upper frequency in he sampled signal o ~7.5kHz. According o he daashee, he ADC clock can be driven on frequencies up o 1Mhz, hough his will lower he ENOB. 2 AVR121
AVR121 3 Theory 3.1 Oversampling and decimaion The heory behind Oversampling and decimaion is raher complex, bu using he mehod is fairly easy. The echnique requires a higher amoun of samples. These exra samples can be achieved by oversampling he signal. For each addiional bi of resoluion, n, he signal mus be oversampled four imes. Which frequency o sample he inpu signal wih, is given by Equaion 3-1. To ge he bes possible represenaion of a analog inpu signal, i is necessary o oversample he signal his much, because a larger amoun of samples will give a beer represenaion of he inpu signal, when averaged. This is o be considered as he main ingredien of his Applicaion Noe, and will be furher explained by he following heory and examples. Equaion 3-1. Oversampling frequency f oversampling = 4 n f nyquis 3.2 Noise To make his mehod work properly, he signal-componen of ineres should no vary during a conversion. However anoher crieria for a successful enhancemen of he resoluion is ha he inpu signal has o vary when sampled. This may look like a conradicion, bu in his case variaion means jus a few LSB. The variaion should be seen as he noise-componen of he signal. When oversampling a signal, here should be noise presen o saisfy his demand of small variaions in he signal. The quanizaion error of he ADC is a leas 0.5LSB. Therefore, he noise ampliude has o exceed 0.5 LSB o oggle he LSB. Noise ampliude of 1-2 LSB is even beer because his will ensure ha several samples do no end up geing he same value. Crierias for noise, when using he decimaion echnique: The signal-componen of ineres should no vary significanly during a conversion. There should be some noise presen in he signal. The ampliude of he noise should be a leas 1 LSB. Normally here will be some noise presen during a conversion. The noise can be hermal noise, noise from he CPU core, swiching of I/O-pors, variaions in he power supply and ohers. This noise will in mos cases be enough o make his mehod work. In specific cases hough, i migh be necessary o add some arificial noise o he inpu signal. This mehod is refereed o as Dihering. Figure 3-1 (a) shows he problem of measuring a signal wih a volage value ha is beween wo quanizaion seps. Averaging four samples would no help, since he same low value would be he resul. I may only help o aenuae signal flucuaion. Figure 3-1 (b) shows ha by adding some arificial noise o he inpu signal, he LSB of he conversion resul will oggle. Adding four of hese samples halves he quanizaion seps, producing resuls ha gives beer represenaions of he inpu value, as shown in Figure 3-1 (c). The ADCs virual resoluion has increased from 10 o 11-bi. This mehod is refereed o as Decimaion and will be explained furher in secion 3-3. 3
Figure 3-1. Increasing he resoluion from 10-bi o 11-bi. Oupu value 517 516 515 514 513 Oupu value 518 517 516 515 514 513 a) Oupu value b) 517 516 515 514 c) Anoher reason o use his mehod is o increase he Signal o Noise Raio. Enhancing he Effecive Number Of Bis, ENOB, will spread he noise over a greaer binary number. The noises influence on each binary digi will decrease. Doubling he sampling frequency will lower he in-band noise by 3dB, and increase he resoluion of he measuremen by 0.5 bis. 4 AVR121
AVR121 3.3 Averaging The convenional meaning of averaging is adding m samples, and dividing he resul by m. Refereed o as normal averaging. Averaging daa from an ADC measuremen is equivalen o a low-pass filer and has he advanage of aenuaing signal flucuaion or noise, and flaen ou peaks in he inpu signal. The Moving Average mehod is very ofen used o do his. I means aking m readings, place hem in a cyclic queue and average he mos recen m. This will give a sligh ime delay, because each sample is a represenaion of he las m samples. This can be done wih or wihou overlapping windows. Figure 3.2 shows seven (Av1-Av7), independenly Moving Average resul wihou overlapping. Figure 3-2. Moving Average principle V 680 670 660 650 640 Av1 Av2 Av3 Av4 Av5 Av6 Av7 I is imporan o remember ha normal averaging does no increase he resoluion of he conversion. Decimaion, or Inerpolaion, is he averaging mehod, which combined wih oversampling, which increases he resoluion. Digial signal processing ha oversamples and lowpass-filers a signal is ofen referred o as inerpolaion. In his sense, inerpolaion is used o produce new samples as a resul of averaging a larger amoun of samples. The higher he number of samples averaged is, he more selecive he low-pass filer will be, and he beer he inerpolaion. The exra samples, m, achieved by oversampling he signal are added, jus as in normal averaging, bu he resul are no divided by m as in normal averaging. Insead he resul is righ shifed by n, where n is he desired exra bi of resoluion, o scale he answer correcly. Righ shifing a binary number once is equal o dividing he binary number by a facor of 2. As seen from Equaion 3-1, increasing he resoluion from 10-bis o 12-bis requires he summaion of 16 10-bi values. A sum of 16 10-bi values generaes a 14-bi resul where he las wo bis are no expeced o hold valuable informaion. To ge back o 12-bi i is necessary o scale he resul. The scale facor, sf, given by Equaion 3-2, is he facor, which he sum of 4 n samples should be divided by, o scale he resul properly. n is he desired number of exra bi. Equaion 3-2. n sf = 2 5
3.4 When will Oversampling and Decimaion work? Normally a signal conains some noise, his noise very ofen has he characerisic of Gaussian noise, more commonly known as Whie noise or Thermal noise, recognized by he wide frequency specrum and ha he oal energy is equally divided over he enire frequency range. In hese cases he mehod of Oversampling and decimaion will work, if he ampliude of he noise is sufficien o oggle he LSB of he ADC conversion. In oher cases i migh be necessary o add arificial noise signal o he inpu signal, his mehod is referred o as Dihering. The waveform of his noise should be Gaussian noise, bu a periodical waveform will also work. Wha frequency his noise signal should have depends on he sampling frequency. A rule of humb is: When adding m samples, he noise signals period should no exceed he period of m samples. The ampliude of he noise should be a leas 1 LSB. When adding arificial noise o a signal, i is imporan o remember ha noise has mean value of zero; insufficien oversampling herefore may cause an offse, as shown in Figure 3-3. Figure 3-3. Offse caused by insufficien sampling. V V a) V b) c) 6 AVR121 The sippled line illusraes he averaged value of he sawooh signal. Figure 3-3 (a) will cause a negaive offse. Figure 3-3 (b) will cause a posiive offse. In Figure 3-3
AVR121 (c) he sampling is sufficien, and offse is avoided. To creae an arificial noise signal, one of he AVRs couners can be used. Since he couner and he ADC use he same clock source, his gives he possibiliy of synchronizing he noise and he sampling frequencies o avoid offse. 3.5 Example 1 A Brew Maser in Dublin wans o measure he emperaure of a process in his brewery. A slow varying signal represens he emperaure measuremen, and he nominal volage in is environmenal emperaure is 2.5 V. Figure 3-4 shows he characerisic of he emperaure-measuring device. Figure 3-4. Volage / Temperaure funcion Volage [m V] 2 0.1 o Temperaure [ o C ] The Brew Maser doesn wan o minimize he dynamic range of he inpu signal and chooses a 5V reference volage for he ADC. In his case a 10-bi ADC canno provide a conversion resul accurae enough, since he resul s LSB represens a ~5mV sep. This is unaccepable since his will give a resul ha may be up o 0.25 C off. The Brew Maser desires he resul o have 0.1 C accuracy, which demands a volage resoluion below 2mV. If he measuremen was represened by a 12 bis ADC, he volage sep represening LSB would decrease o ~1.22mV. Wha he Brew Maser needs o do is o ransform he 10-bi ADC o a virual 12-bi ADC. The inpu signal is varying very slowly; a very high sampling frequency is herefore no required. According o he daashee, he ADC clock frequency should be beween 50kHz and 200kHz o ensure 10-bi effecive resoluion. The Brew Maser herefore chooses a 50kHz ADC clock frequency. Then he sampling frequency becomes ~3800 SPS. A one poin he DC value ha represen he emperaure measuremen is 2.4729V. Table 3-1 shows he differen resoluion opions measuring his value when Vin = 2.4729V and VREF = 5V. 7
Table 3-1. Resoluion opions. Resoluion Volage resoluion Oversa mpled Righ shifed Ideal decimaed resul Ideal volage represenaion Maximum Bandwidh 10 bi ~5 mv NA NA NA 2.4658V ~7600Hz (1) 11 bi ~2.5 mv 4X 1X 1012 2.4707V ~1900Hz (1) 12 bi ~1.22mV 16X 2X 2025 2.4719V ~475Hz (1) 13 bi ~610 uv 64X 3X 4051 2.4725V ~118Hz (1) 14 bi ~300 uv 256X 4X 8103 2.4728V ~29Hz (1) 15 bi ~150 uv 1024X 5X 16206 2.4728V ~7Hz (1) 16 bi ~75 uv 4096X 6X 32413 2.4729V ~3Hz (1) Noes: 1. ADC Clock = 200kHz The resul of a single conversion is 505, which a firs glance may seem correc. Bu his binary number also corresponds o for insance 2.4683V. This makes he user uncerain and causes errors in he emperaure measuremen. In cerain cases his migh be criical. As concluded before; a signal normally includes enough noise o make he decimaion mehod feasible. To increase he resoluion by one bi, four samples from he same neighborhood are added. These samples have values ha differ from each oher by a few LSB, because of he noise. These four samples are added: 508 + 507 + 505 + 505 = 2025. According o he decimaion principle he answer now need o be scaled back o 11- bi. I needs o be righ shifed n imes, where n is he desired exra number of bis. The resul is 1012. Afer increasing he resoluion, i suddenly is possible o achieve samples beween he original quanizaion seps. Sill, he signal is oversampled enough o increase he resoluion furher, o 12 bi. Adding 16 10-bi samples and righ-shifing he resul 2 imes will do his. The resul is 2025. This number is more reliable, since he error margin is reduced o ~1.22mV using a 12 bi resul. This example shows ha he user who sared off wih a slow varying signal, sampled 3800 imes per second, wih a volage accuracy of ~5mV, now has 240 samples per second wih a 12-bi resoluion, and a volage accuracy of ~1.22mV. The user migh sill wan o even ou signal flucuaions by averaging 16 12-bi samples, he convenional way. This is done by adding 16 samples and dividing he resul by 16. A he end he user has 15 SPS consising of 16 averaged 12-bi adjacen samples, (15 16 16 = 3840). Normal averaging will minimize he consequences of random noise, Oversampling and decimaion will uilize he noise o enhance he resoluion 8 AVR121
AVR121 3.6 Example 2 To show he efficiency of his mehod, he following example will show ha i is no necessary o use an exernal ADC o ge higher accuracy. A signal generaor is used o produce a linear ramp signal from 0V o 5V. In a low noise environmen, wih a signal generaor and an AVR conroller plugged ino an STK500 board, here may no be enough noise o oggle he las few bis of he 10-bi signal. I is herefore necessary o add arificial noise o he inpu signal, o make he LSB oggle. Four mehods were used successfully: Adding noise, generaed by a signal generaor, direcly o he inpu signal. Generaing noise wih he AVR, using PWM, and adding i o he inpu signal. Adding noise, generaed by he AVR, o AREF when using AVCC as VREF. Adding noise, generaed by he AVR, o AREF when using AREF as VREF. The easies way o diher a signal is o add whie noise direcly o he signal, bu in mos cases he user does no have, or does no wan o have, his kind of noise signal in he measuring environmens. A more available mehod is o se up one of he couners in he AVR o produce a PWM signal and hen low-pass filer his noise o appear as a DC wih a ripple peak-o-peak value of a few LSB. An example of such a filer s deails and componen values are shown in Figure 3-5. Figure 3-5. LP-filer VCC 220Ω AREF 220Ω 0.3uF Timer/Couner 0.1uF 1k Ω 10k Ω If VCC = 5V, he filered signal a he AREF pin appears as 2.5V when he couner s duy-cycle is 0%, and as 5V when he couner s duy-cycle is 100%. In his example he duy cycle of he PWM-signal is 50%, and he base frequency is ~3900Hz. The 10kΩ poeniomeer is used o adjus his ripple. The PWM- signal is used eiher as he reference volage o he ADC a AREF, or as a noise generaor conneced o he AREF pin. Wih AVCC se as ADC reference volage. The idea is ha small variaions in he reference volage will give he same effec as small variaions in he inpu signal, wihou disurbing he inpu signal. Measuring a linear ramp signal as shown in Figure 3-6, gives he four graphs as shown in Figure 3-7, Figure 3-8, Figure 3-9 and Figure 3-10. Figure 3-7 shows a 10- bi discree represenaion of he inpu ramp signal, measured wihou arificial noise 9
added. The quanizaion seps are very marked. To increase he resoluion, he quanizaion seps need o be reduced. Figure 3-8 shows a 12-bi discree represenaion of he inpu signal when AREF is he ADC reference volage, and AREF is added a few LSB noise. According o Equaion 3-1, each 12-bi resul consiss of 16 10-bi samples. The offse was adjused for he ADC, and in accordance wih Applicaion Noe AVR120, he gainerror also needed adjusmen. Figure 3-9 shows a 14-bi discree represenaion of he inpu signal and Figure 3-10 shows he 16-bi discree represenaion of he inpu signal. When measuring a signal conaining noise, or when he reference volage is varying like in his example, i is imporan o remember ha he op and boom values are decreased by he same value as he ampliude of he noise signal, giving a sligh reducion in he dynamic range of he measured signal. In his cerain case, as a safey margin, he offse was adjused for 100mV. Figure 3-6. Ramp Signal, 0-5V, 100% synchronous. Ramp Signal, 0-5V, 100% synchronous Volage [V] 2,56 2,55 2,54 2,53 2,52 2,51 2,5 2,49 2,48 2,47 Time [s] 10 AVR121
AVR121 Figure 3-7. Ramp Signal reproduced wih 10-bi resoluion 10-bi resoluion 2,56 2,55 2,54 Oupu value [V] 2,53 2,52 2,51 2,5 2,49 2,48 2,47 Inpu value [V] Figure 3-8. Ramp Signal reproduced wih 12-bi resoluion 12-bi resoluion 2,56 2,55 2,54 Oupu value [V] 2,53 2,52 2,51 2,5 2,49 2,48 2,47 Inpu value [V] 11
Figure 3-9. Ramp Signal reproduced wih 14-bi resoluion 14-bi resoluion 2,56 2,55 2,54 Oupu value [V] 2,53 2,52 2,51 2,5 2,49 2,48 2,47 Inpu value [V] Figure 3-10. Ramp Signal reproduced wih 16-bi resoluion 16-bi resoluion 2,56 Oupu value [V] 2,55 2,54 2,53 2,52 2,51 2,5 2,49 2,48 2,47 Inpu value [V] One can easily see ha by using he oversampling and decimaion mehod, i is possible o increase resoluion significanly. 12 AVR121
AVR121 Summary When he ADC samples a signal, i quanizes he signal in discree seps. This inroduces some error, ofen referred o as quanizaion error. Normal averaging will only even ou signal flucuaions, while Decimaion will increase he resoluion. In a 4- imes-oversampled signal, four adjacen daa poins are averaged o produce a new daa poin. Which frequency o oversample he signal wih, can be calculaed by equaion 3-1. Adding hese exra samples and righ-shifing he resul by a facor n, yields a resul wih resoluion increased by n bis. Averaging four ADC resuls o ge a new ADC resul is he same as if he ADC sampled a ¼ of he rae, bu also has he effec of averaging he quanizaion noise, which improves SNR. This will increase he ENOB and reduce he quanizaion error. Wih he availabiliy of faser ADCs and wih low memory cos, he advanages of oversampling are cos effecive and desirable. Some noise has o be presen in he signal, a leas 1 LSB. If he noise ampliude is no sufficien, add noise o he signal. Accumulae 4 n 10-bi samples, where n is he desired exra number of bis in he resoluion. Scale he accumulaed resul, by righ shifing i n imes. Compensae for errors, according o Applicaion Noe AVR120. 13
Disclaimer Amel Corporaion 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Regional Headquarers Europe Amel Sarl Roue des Arsenaux 41 Case Posale 80 CH-1705 Fribourg Swizerland Tel: (41) 26-426-5555 Fax: (41) 26-426-5500 Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshasui Eas Kowloon Hong Kong Tel: (852) 2721-9778 Fax: (852) 2722-1369 Japan 9F, Tonesu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan Tel: (81) 3-3523-3551 Fax: (81) 3-3523-7581 Amel Operaions Memory 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 Microconrollers 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 La Chanrerie BP 70602 44306 Nanes Cedex 3, France Tel: (33) 2-40-18-18-18 Fax: (33) 2-40-18-19-60 ASIC/ASSP/Smar Cards Zone Indusrielle 13106 Rousse Cedex, France Tel: (33) 4-42-53-60-00 Fax: (33) 4-42-53-60-01 1150 Eas Cheyenne Mn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Scoish Enerprise Technology Park Maxwell Building Eas Kilbride G75 0QR, Scoland Tel: (44) 1355-803-000 Fax: (44) 1355-242-743 RF/Auomoive Theresiensrasse 2 Posfach 3535 74025 Heilbronn, Germany Tel: (49) 71-31-67-0 Fax: (49) 71-31-67-2340 1150 Eas Cheyenne Mn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Biomerics/Imaging/Hi-Rel MPU/ High Speed Converers/RF Daacom Avenue de Rochepleine BP 123 38521 Sain-Egreve Cedex, France Tel: (33) 4-76-58-30-00 Fax: (33) 4-76-58-34-80 Lieraure Requess www.amel.com/lieraure Disclaimer: The informaion in his documen is provided in connecion wih Amel producs. No license, express or implied, by esoppel or oherwise, o any inellecual propery righ is graned by his documen or in connecion wih he sale of Amel producs. EXCEPT AS SET FORTH IN ATMEL S TERMS AND CONDITIONS OF SALE LOCATED ON ATMEL S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Amel makes no represenaions or warranies wih respec o he accuracy or compleeness of he conens of his documen and reserves he righ o make changes o specificaions and produc descripions a any ime wihou noice. Amel does no make any commimen o updae he informaion conained herein. Unless specifically provided oherwise, Amel producs are no suiable for, and shall no be used in, auomoive applicaions. Amel s producs are no inended, auhorized, or warraned for use as componens in applicaions inended o suppor or susain life. Amel Corporaion 2005. All righs reserved. Amel, logo and combinaions hereof, Everywhere You Are, AVR, AVR Sudio and ohers, are he regisered rademarks or rademarks of Amel Corporaion or is subsidiaries. Oher erms and produc names may be rademarks of ohers.