This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:avr:adc [2010/03/02 12:42] – Translation in progress yllars | en:avr:adc [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Analog-to-digital | + | ====== Analog-to-digital |
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' | 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' | ||
- | 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' | + | 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' |
- | AVR ADC töötab võrdlusmeetodil (inglise keeles // | + | 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, |
- | 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 | + | A typical |
- | 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. | + | < |
- | ~~PB~~ | + | <box 100% round # |
- | <box 100% round # | + | Task: measure the voltage in ADC channel |
- | + | ||
- | Vaja on mõõta ATmega128 | + | |
<code c> | <code c> | ||
Line 24: | Line 22: | ||
unsigned char result; | unsigned char result; | ||
- | // Võrdluspingeks | + | // Choose |
- | // (eeldatavasti on see ühendatud | + | // (it is assumed AREF is connected to the +5V supply) |
- | // Multiplekseriga kanali | + | // Choose channel |
- | // 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 | + | // 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; | ||
} | } |