In the Arduino Mega it's possible to use differential mode between two analog pins with 10x
gain (or 200x
). But, the resolution is halved (-512
... 511
) as it's possible to measure negative difference. But with some precision voltage reference switching and 200x
gain you might be able to archieve some precision.
The downside is those ADC
channels are not supported by analogRead
, you have to do it directly by setting ADMUX
register (or ADMUX
and ADCSRB
) to desired differential channel with gain.
byte backup = ADMUX; // store the arduino settings
ADMUX = _BV(REFS1) | _BV(MUX3) | _BV(MUX0); // internal 1.1V reference, differential: ADC1+ ADC0-, gain: 10x
// there should be some delay to stabilize the voltage reference (if another one was selected)
// but it's possible to preset it by analogReference(INTERNAL1V1); in the setup() so no delay will be needed
ADCSRA |= _BV(ADSC); // start conversion
while ((ADCSRA & _BV(ADSC)) != 0); // wait for conversion end (ADSC is cleared after the end by hardware)
int val = ADC; // read the result
ADMUX = backup; // restore original settings (from arduino)
In the Arduino everything else in ADC is configured and ADC is started, so just necessary changes are here. It should be working but I didn't tested it (I don't have the Arduino Mega here)