I use Arduino Ethernet board.
There are other interesting things in the datasheet:
According to page 255 it should be possible discharge the mux cap directly to ground by selecting "ADC input" number 15 (1111 bin). That is better, than my solution with the temp sensor.
Also a 1.1 V reference can be selected as an input on virtual input channel 14 (1110 bin).
But you cannot select inputs > 7 with the Arduino library analogRead function, you have to use your own.
EDIT:
I have tested it and it works:
Code: Select all
//setup ADC, this can be done in the setup section
ADCSRB = 0;
ADCSRA &= B10000111; // Set Start disable, Auto trigger disable, Interrupts disable, Do not modify Prescaler
//this may go to a DischargeMuxCap subroutine - it should connect the mux to GND
ADMUX = B01001111; // Uref=Vcc, ADC input = GND
//test conversion if we are really connected to ground
ADCSRA |= B01000000; // Fire the conversion
while (bit_is_set(ADCSRA,ADSC)); // Wait until finished
return (ADCL | (ADCH << 8)); // Conversion result, in our case should be 0, or result = (ADCL | (ADCH << 8)); if we are not in subroutine but directly in the loop
//if we want to continue conversion on another input when we have the mux cap discharged
//(remove the return line above)
ADMUX = B01000000 | input; // Uref=Vcc, ADC input = input, possible values (0-5 Arduino AD input pins, 6-7 not connected pins, 8=temp sensor, 14=internal bandgap reference, 15=GND)
//same conversion as above
ADCSRA |= B01000000; // Fire the conversion
while (bit_is_set(ADCSRA,ADSC)); // Wait until finished
return (ADCL | (ADCH << 8)); // Conversion result , or result = (ADCL | (ADCH << 8)); if we are not in subroutine but directly in the loop
tested on Arduino Ethernet (ATMEGA 328 P)