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.

  • 3
    \$\begingroup\$ You say the ADC inputs are flipped but of course that is a physical impossibility unless you have hardware that can do this so, do you mean the displayed readings get flipped or just one of the displayed readings? \$\endgroup\$ – Andy aka Dec 18 '13 at 8:02
  • \$\begingroup\$ No physically it is not flipped. Internally it is flipping someway. And what I'm getting is displayed reading of temperature approx one in every 6 time repetition of display is according to the adc count of humidity sensor. But the humidity display is same as it should be. \$\endgroup\$ – user28940 Dec 18 '13 at 8:21
  • 3
    \$\begingroup\$ Are you giving the ADC mux sufficient time to settle? \$\endgroup\$ – Ignacio Vazquez-Abrams Dec 18 '13 at 8:27
  • \$\begingroup\$ I'd look for a problem in the firmware. Probably your logic is wrong somewhere \$\endgroup\$ – miceuz Dec 18 '13 at 8:41
  • \$\begingroup\$ At present I'm coding in Code vision AVR. And I'm sensing the both adc at a same time but display they after 2 second delay \$\endgroup\$ – user28940 Dec 18 '13 at 9:14

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).


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.