ADC revised

This commit is contained in:
Tristan Krause 2019-04-03 14:09:58 +02:00
parent f9e56b44f3
commit 2d26632f41
9 changed files with 42 additions and 17 deletions

View file

@ -5,23 +5,28 @@ void ADU::init() volatile
// externe Referenz an AREF
ADMUX = 0;
// ADC aktiviert, prescaler = 128
ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
// ADC aktiviert, Interruptbetrieb, prescaler = 128
ADCSRA = _BV(ADEN) | _BV(ADIE) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
}
void ADU::handleConversionComplete() volatile
{
active = false;
}
uint16_t ADU::getValue(uint8_t channel) volatile
{
while(active);
active = true;
// lege Kanal fest
ADMUX = (ADMUX & 0xE0) | channel;
// starte Konvertierung
ADCSRA |= _BV(ADSC);
// warte Konvertierungszeit ab
_delay_us(13 * 1000000 * 128 / F_CPU + 1);
// warte auf Ende
while(ADCSRA & _BV(ADSC));
// warte auf Ende der Konvertierung
while(active);
return ADCW;
}