pYro_65:
Thanks for the reply, I got it working eventually and it performs well, cheers.
I didn't notice any change from setting the ACME, maybe this is a default value or gets set by Arduino's init() function.
I also found that slowing the A/D clock seems to give much cleaner readings. Here's some code that I use (on a 328P) but it should translate easily to the Mega:
/*** this part in main() or setup()
ADCSRA |= (_BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0) | _BV(ADEN)); // a/d prescaler = sysclk/128, a/d enable
ADMUX = (_BV(7) | _BV(6)); // use internal 1.1v ref & clear channel bits
***/
uint16_t readAnalog(uint8_t port)
{
uint8_t hi;
uint8_t lo;
ADMUX |= port; // OR in desired channel
ADCSRA |= _BV(ADSC); // Start ADC conversion
while(ADCSRA & _BV(ADSC)) { ; } // wait for a/d complete
lo = ADCL; // must read ADCL first
hi = ADCH;
return (hi << 8) | lo;
}
The first line of code (the "// a/d prescaler = sysclk/128, a/d enable" part) is what sets the A/D converter clock.
Hope this helps.
-- Roger