Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:avr:adc [2010/03/02 12:42] – Translation in progress yllarsen:avr:adc [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Analog-to-digital converter ======+====== Analog-to-digital Converter ======
  
 Analog-to-digital converter (ADC) transforms an analog voltage value to a digital value. The allowed voltage range on an ADC input of an AVR microcontroller is 0 to 5.5 V. The size of the digital value is 10 bits, but its precision is ±2 units. The error may be even larger, if the microcontroller's supply voltage is not protected from interference. AVR has a separate voltage supply and comparison voltage pin for ADC. The separate supply voltage helps to cut down the interference and it may not differ more than 0.3 V from the main supply voltage. Comparison voltage defines the maximum digital value. For example, if the comparison voltage is 3 V then an input with the same voltage will read as 2<sup>10</sup> - 1 (1023). Analog-to-digital converter (ADC) transforms an analog voltage value to a digital value. The allowed voltage range on an ADC input of an AVR microcontroller is 0 to 5.5 V. The size of the digital value is 10 bits, but its precision is ±2 units. The error may be even larger, if the microcontroller's supply voltage is not protected from interference. AVR has a separate voltage supply and comparison voltage pin for ADC. The separate supply voltage helps to cut down the interference and it may not differ more than 0.3 V from the main supply voltage. Comparison voltage defines the maximum digital value. For example, if the comparison voltage is 3 V then an input with the same voltage will read as 2<sup>10</sup> - 1 (1023).
  
-AVR ADC works on the principal of successive approximation. In short, the measured voltage is compared to specific voltage levels and the results are reported as a bit array. This method is relatively slow, as each bit in the final result is calculated separately. AVR spends 13 clock cycles for each measuring, except the first (on start-up), which takes 25 cycles. These cycles are not the controller'work cyclesthough, but instead special cycles allocated to the ADC unit by the frequency divider. The ADC frequency should be 50-200 kHz to achieve maximum precision, on higher frequencies the precision fades. In some cases it is more important to get a large number of readings instead of maximum precision, in which case using a larger frequency is totally justified.+AVR ADC works on the principal of successive approximation. In short, the measured voltage is compared to specific voltage levels and the results are reported as a bit array. This method is relatively slow, as each bit in the final result is calculated separately. AVR spends 13 clock cycles for each measuring, except the first (on start-up), which takes 25 cycles. These cycles are not the controller'duty cycles though, but instead special cycles allocated to the ADC unit by the frequency divider. The ADC frequency should be 50-200 kHz to achieve maximum precision, on higher frequencies the precision fades. In some cases it is more important to get a large number of readings instead of maximum precision, in which case using a larger frequency is totally justified. According to AVR documentation, one measuring takes 13-260 µs.
  
-AVR ADC töötab võrdlusmeetodil (inglise keeles //successive approximation//). Lühidalt öeldes toimub mõõdetava pinge võrdlemine kindlate nivoopingetega ja tulemuste esitamine tõeväärtuste-, ehk bitijadana. See meetod on suhteliselt aeganõudev, sest iga biti leidmine lõppväärtuses toimub eraldi. AVR-il kulub töö ajal 13 takti ühe mõõtmise tegemiseks ja 25 takti kõige esimesel mõõtmisel (käivitusel). Need taktid pole aga kontrolleri töötaktidvaid spetsiaalselt ADC üksuse jaoks sagedusjaguriga saadud taktidMaksimaalse täpsuse saamiseks peaks ADC takt olema 50-200 kHzKõrgemal taktil kaob täpsusVahel on ka mõõtmiste suur arv olulisem kui täpsus ja siis on põhjendatud suurema sageduse kasutamine. Ühele mõõtmisele kuluvaks ajaks on AVR dokumentatsioonis antud 13-260 µs.+The measured value can be read as an 8or 10-bit valueSince AVR itself is an 8-bit deviceit has two 8-bit registers for storing the ADC valuesIt is possible to specify in the settings whether the first two or the last two bits go to a separate registerIf the two younger bits, which characterize the result less, are separated, the result can be read as an 8-bit value - a combination like that is called a left-aligned resultThe other combination, where both registers are read and the value is in 10-bit format, is called a right-aligned result.
  
-Mõõtetulemust saab kasutaja lugeda 8- ja 10-bitisena. Kuna AVR on 8-bitinesiis ADC mõõteväärtuste jaoks on sel kaks 8-bitist registritSeadistustes saab määratakas 10-bitisest väärtusest 2 esimest või 2 viimast bitti lähevad eraldi registrisseKui eraldatakse noorimat ehk tulemust vähem iseloomustavat bitti, saab mõõtetulemuse 8-bitisena lugeda - sellist kombinatsiooni nimetatakse vasak-asetusega mõõtetulemuseks (//left align//)Teistpidist kombinatsioonikus kaht tulemusregistrit lugedes tekib 10-bitine arv, nimetatakse parem-asetusega mõõtetulemuseks (//right align//).+A typical AVR has analog voltage input channels, ATtiny series have only a fewsome ATmega devices have 16, but there is always only one converterTo make it possible to use different inputsthe device has a built-in multiplexer. The input of the multiplexer is definable using a special registerThe ADC unit has a few more properties: using the processor's sleep mode for converting to reduce the interference and the option to use an internal fixed comparison voltage (usually 2.65 Vin some models 1 V).
  
-Mõõdetavaid analoogpinge sisendkanaleid on AVR-idel tavaliselt 8, ATtiny seerial üksikud, mõnel ATmega seeria kiibil 16, kuid muundureid on siiski üks. Erinevate sisendite kasutamiseks on kiibis multiplekser. Multiplekseri sisend on spetsiaalse registriga määratav. ADC üksusel on veel mõned omadused: muundamine protsessori magamisrežiimis müra vähendamiseks ja sisemise fikseeritud võrdluspinge (2,56 V, mõnel ka 1 V) kasutamise võimalus.+<pagebreak>
  
-~~PB~~+<box 100% round #EEEEEE|Example>
  
-<box 100% round #EEEEEE|Näide> +Task: measure the voltage in ADC channel of an ATmega128. The voltage is in range of 0-5 V and the result should be at 8-bit precision.
- +
-Vaja on mõõta ATmega128 ADC kanali pinget vahemikus 0-5 V 8-bitise täpsusega.+
  
 <code c> <code c>
Line 24: Line 22:
  unsigned char result;  unsigned char result;
  
- // Võrdluspingeks AREF viigu valimine + // Choose AREF pin for the comparison voltage 
- //   (eeldatavasti on see ühendatud +5V toiteahelasse+ //   (it is assumed AREF is connected to the +5V supply
- // Multiplekseriga kanali valimine + // Choose channel in the multiplexer 
- // Tulemus on vasak-asetusega+ // Left align the result
  ADMUX = (1 << REFS0) | (1 << ADLAR) | (3);  ADMUX = (1 << REFS0) | (1 << ADLAR) | (3);
  
- // ADC üksuse käivitamine+ // Start the ADC unit
- // teisendustakti seadmine 16 korda aeglasemaks töötaktist+ // set the conversion cycle 16 times slower than the duty cycle
  ADCSRA = (1 << ADEN) | (1 << ADPS2) | (1 << ADSC);  ADCSRA = (1 << ADEN) | (1 << ADPS2) | (1 << ADSC);
  
- // Mõõtmise lõpetamise ootamine+ // Wait for the measuring process to finish
  while (ADCSRA & (1 << ADSC)) continue;  while (ADCSRA & (1 << ADSC)) continue;
  
- // 8-bitise tulemuse lugemine+ // Read the 8-bit value
  result = ADCH;  result = ADCH;
 } }
en/avr/adc.1267533760.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0