b15f/firmware/adu.cpp

33 lines
586 B
C++
Raw Normal View History

2019-03-25 14:40:36 +00:00
#include "adu.h"
2019-04-03 06:40:14 +00:00
void ADU::init() volatile
2019-03-25 14:40:36 +00:00
{
// externe Referenz an AREF
2019-05-16 08:44:38 +00:00
ADMUX = _BV(REFS0);
2019-03-25 14:40:36 +00:00
2019-04-03 12:09:58 +00:00
// ADC aktiviert, Interruptbetrieb, prescaler = 128
ADCSRA = _BV(ADEN) | _BV(ADIE) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
}
void ADU::handleConversionComplete() volatile
{
active = false;
2019-03-25 14:40:36 +00:00
}
2019-04-03 06:40:14 +00:00
uint16_t ADU::getValue(uint8_t channel) volatile
2019-03-25 14:40:36 +00:00
{
2019-04-03 12:09:58 +00:00
while(active);
active = true;
2019-03-25 14:40:36 +00:00
// lege Kanal fest
ADMUX = (ADMUX & 0xE0) | channel;
// starte Konvertierung
ADCSRA |= _BV(ADSC);
2019-04-03 12:09:58 +00:00
// warte auf Ende der Konvertierung
while(active);
2019-03-27 09:33:26 +00:00
2019-03-25 14:40:36 +00:00
return ADCW;
}