Different V_Aref for different analog pins? Is is doable?

I have this question so let me describe the context:

I have one sensor that outputs no more than 1V analog voltage (say it's a centigrade temperature sensor). I also have a sensor that will output 0-5V range analog voltage (say it's an accelerometer).

I want good accuracy for the 0-1V temp sensor so I want to use 1.024V internal reference voltage. I need larger range for the accelerometer so I will use default 5V reference for the accelerometer.

My question is, can this be done safely with arduino C (change reference, measure first channel, change reference measure second channel) or do I have to use assembly code or port manipulation to make sure I am not for a moment comparing 0-5V signal with 1.024V reference (I thought that could be bad)? Thanks.

Isn’t this covered in the reference page for analogReference()?

You just have throw away the first couple of readings after switching.


That is an interesting question.

I have two method that I am thinking here.

Method 1 : Build a op-amp circuit to convert to Vin into 0 to 5 V

Method 2 : use of a 4066 chip. ← SPST CMOS switch + Inverter gate ← Make one or use SPDT CMOS chip.
The 1 V / 5 V can be control be a digital pin. You have to time it right in your software.

My idea

Another idea: Why not use a voltage divider on the 5V signal and use the 1.024V AREF for both sensors?

I'm with John on this one. Unless there is a particular reason why you can't, I usually just get a small multi-turn potentiometer and adjust it to give the proper range.

The thing is, I will have several of these sensors and any channel could receive this 0-1V range sensor so I have to do software solution instead. I'll just toss out the first reading as James said. Thanks everyone!

liudr: I'll just toss out the first reading as James said. Thanks everyone!

It takes more than 1.

Note: After changing the analog reference, the first few readings from analogRead() may not be accurate.



So what is the reason of this inaccuracy of the first few reading? Thanks.

Well maybe you only need to discard the first.

From the ATmega328 datasheet: "When the bandgap reference voltage is used as input to the ADC, it will take a certain time for the voltage to stabilize. If not stabilized, the first value read after the first conversion may be wrong."

Thanks James.