ADC count swapping

adcmicrocontroller

I'm working on a atmega16l microcontroller and my project is to display the humidity and temperature of in the room on an LCD screen. I'm taking ADC input from humidity(0-5) volts DC and temperature sensor(0-0.5) volts DC and according to that I have to switch the room warmer and humidifier. But at present my controller is showing one problem that it is showing correct humidity all time, but approx about 1 time in six repetition the temperature ADC input is flipped with the humidity ADC input while humidity ADC input remains the same.
For getting rid of this problem I have tried to change the port of both adc apart from each other but then also the problem remains the same.

Please tell me how to solve this problem.

Best Answer

If it is not a software problem, I believe Ignacio is right : that's probably a MUX or sample time problem.

The ADC has a sample-and-hold capacitor (to ground) of about 10pF that holds enough charge for one ADC conversion. This capacitor is fed through a resistor by the ADC MUX that switches from the various input pins. This MUX also has a capacitor of about 4pF. (I don't remember the exact values of the resistors).

schematic

simulate this circuit – Schematic created using CircuitLab

If the output impedence of your sources is low enough, the capacitors get charged (more or less) instantly and all this behaves just like a switch to an ADC. However, if the output impedence of your temperature sensor is high, the current that flows from/to your temperature sensor between the moment you switch the MUX and the moment you read the ADC may not be enough to charge correctly the capacitors, and you would read the same value as before MUX switching.

You can correct this by either :

  • waiting long enough after changing the input, so that the capacitors have had time to settle,

  • adding a capacitor between your high impedence input pin and ground. The value would have to be much larger than 14pF (in a ratio determined by the desired accuracy), yet small enough for your temperature time variations to be slower than the RC time constant of your capacitor & sensor impedance.