Hello
I am using an Arduino Micro with a ATmega32u4 chip. As a first step in a bigger experiment that involves fast reading of an analog pin I try to manually read the ADC register. However, this fails so far:
uint16_t adc_read(uint8_t ch)
{
// select the corresponding channel 0~5
ch &= 0b00000101; // ensure valid argument
ADMUX = (ADMUX & 0xF8) | ch; // select channel
// write '1' to ADSC to start single convertion
ADCSRA |= _BV(ADSC);
// wait for conversion to complete
while (ADCSRA & _BV(ADSC));
return (ADC);
}
ADC gets initialized inside the setup function with
ADMUX = _BV(REFS0);
ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
The values returned by the adc_read function are always above 1000 whereas calling analogRead returns values between 200~300 (noise).
Can someone help me to fix this issue?