Table of Contents

Analog to Digital Converter

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.

Data Types

Functions

Initializes ADC. Parameters:

Converts specified ADC channel analog value to digital. Function is blocking. Parameter:

Converts specified ADC channel analog value to digital desired number of times and calculates the average. Function is blocking. Parameters:

Example

For example ADC is initialized and two analog channel values are converted to digital. Value of channel 0 is assigned to variable x and averaged value of channel 1 to variable y.

#include <homelab/adc.h>
 
int main(void)
{
	unsigned short x, y;
 
	// Initializing ADC. Reference voltage from AVCC.
	// Clock is 8 times slower than system clock.
	adc_init(ADC_REF_AVCC, ADC_PRESCALE_8);
 
	// Converting channel 0 value.
	x = adc_get_value(0);
 
	// Converting and averaging channel 1 value.
	y = adc_get_average_value(1, 10);
}