Hi All
I having some issues reading the voltage from two ADC channels. It seems like both channels are outputting the same value, where it should be different. This is my code.
void InitADC(void) { //ADMUX=(1<<REFS0); // For Aref=2.5V; ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); //Rrescalar div factor =128 } uint16_t ReadADC(uint8_t ch) { ADMUX =0; ADMUX |=(1<<ch); //Start Single conversion ADCSRA|=(1<<ADSC); //Wait for conversion to complete while(!(ADCSRA & (1<<ADIF))); ADCSRA|=(1<<ADIF); uint16_t number = ((ADCH<< 8)|ADCL); return(number); }
I am then calling the following in my code
chA = ReadADC(1); chB = ReadADC(2);
At fist i though i would need to clear ADMUX, which i am doing but it make no difference.
Please advice what i am doing wrong?