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 13:04] – 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. According to AVR documentation, one measuring takes 13-260 µs.+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.
  
 +The measured value can be read as an 8- or 10-bit value. Since AVR itself is an 8-bit device, it has two 8-bit registers for storing the ADC values. It is possible to specify in the settings whether the first two or the last two bits go to a separate register. If 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 result. The other combination, where both registers are read and the value is in 10-bit format, is called a right-aligned result.
  
 +A typical AVR has 8 analog voltage input channels, ATtiny series have only a few, some ATmega devices have 16, but there is always only one converter. To make it possible to use different inputs, the device has a built-in multiplexer. The input of the multiplexer is definable using a special register. The 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 V, in some models 1 V).
  
-Mõõtetulemust saab kasutaja lugeda 8- ja 10-bitisena. Kuna AVR on 8-bitine, siis ADC mõõteväärtuste jaoks on sel kaks 8-bitist registrit. Seadistustes saab määrata, kas 10-bitisest väärtusest 2 esimest või 2 viimast bitti lähevad eraldi registrisse. Kui eraldatakse 2 noorimat ehk tulemust vähem iseloomustavat bitti, saab mõõtetulemuse 8-bitisena lugeda - sellist kombinatsiooni nimetatakse vasak-asetusega mõõtetulemuseks (//left align//). Teistpidist kombinatsiooni, kus kaht tulemusregistrit lugedes tekib 10-bitine arv, nimetatakse parem-asetusega mõõtetulemuseks (//right align//).+<pagebreak>
  
-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.+<box 100% round #EEEEEE|Example>
  
-~~PB~~ +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.
- +
-<box 100% round #EEEEEE|Näide> +
- +
-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.1267535058.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