This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:software:homelab:library:adc [2010/02/08 14:51] – mikk.leini | en:software:homelab:library:adc [2020/07/20 12:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Analog to digital converter | + | ====== Analog to Digital Converter |
| - | Analoog-digitaalmuunduri teek on AVR ADC mooduli kasutamise lihtsustamiseks. Teegi muundamise funktsioonid on blokeeruvad, ehk nende väljakutsumisel jääb protsessor muundamise lõppu ootama. Muundamise aeg sõltub | + | This library provides functions to use AVR analog to digital converter. All the conversion functions in library are blocking, which means the processor waits as long as it takes to get the results. The conversion time depends on the ADC clock. |
| - | ===== Andmetüübid | + | ===== Data Types ===== |
| - | * **// | + | * **// |
| - | * // | + | * // |
| - | * // | + | * // |
| - | * // | + | * // |
| - | * **// | + | * **// |
| - | * // | + | * // |
| - | * // | + | * // |
| - | * // | + | * // |
| - | * // | + | * // |
| - | * // | + | * // |
| - | * // | + | * // |
| - | * // | + | * // |
| - | ===== Funktsioonid | + | ===== Functions |
| - | * **//void adc_init(adc_reference reference, adc_prescale prescale)// | + | * **//void adc_init(adc_reference reference, adc_prescale prescale)// |
| - | * // | + | Initializes |
| - | * // | + | * // |
| + | * // | ||
| - | * **// | + | * **// |
| - | * //channel// - ADC kanali | + | Converts specified |
| - | * Tagastab | + | * //channel// - ADC channel |
| + | * Return | ||
| - | * **// | + | * **// |
| - | * //channel// - ADC kanali | + | Converts specified |
| - | * // | + | * //channel// - ADC channel |
| - | * Tagastab | + | * // |
| + | * Return | ||
| - | ===== Näide | + | ===== Example |
| - | Näites seatakse analoog-digitaalmuundur töövalmis ja loetakse kahelt sisendkanalilt pinge. Kanali | + | For example ADC is initialized and two analog channel values are converted to digital. Value of channel |
| <code c> | <code c> | ||
| Line 45: | Line 48: | ||
| unsigned short x, y; | unsigned short x, y; | ||
| - | // Analoog-digitaalmuunduri seadistamine | + | // Initializing ADC. Reference voltage from AVCC. |
| - | // Võrdluspinge tuleb AVCC viigult. Muunduri töötakt | + | // Clock is 8 times slower than system clock. |
| - | // on 8 korda madalam kontrolleri taktist. | + | |
| adc_init(ADC_REF_AVCC, | adc_init(ADC_REF_AVCC, | ||
| - | // Kanali | + | // Converting channel |
| x = adc_get_value(0); | x = adc_get_value(0); | ||
| - | // Kanali | + | // Converting and averaging channel |
| y = adc_get_average_value(1, | y = adc_get_average_value(1, | ||
| } | } | ||