0
\$\begingroup\$

I have a device that continuously measures the value of 3 sensors connected to 3 ADC pins and working at 5V reference, so I have two options for voltage reference selection:

  1. Connecting AREF pin to 5V supply (REFS=00)
  2. Connecting AREF to a 100nF capacitor and choose AVcc as reference (REFS=01)

Till here everything works fine. I also want to measure chip temperature using the internal temperature sensor (ADC8), and as the datasheet says I must select the 1.1V internal voltage reference, so the first above options can not be used, If I choose the second option selecting the 1.1V reference while the capacitor is charged with 5V (due to other pins measurements) and again selecting back AVcc reference doesn't cause error in ADC measurement? I decided to read the internal temperature sensor without changing the reference voltage to 1.1V. So I read 50 samples and divided the sum to 11 (because I used 5V reference instead of 1.1V), but the result is about 0x170 (~76 deg C) that is incorrect.
Anyone can solve my problem?

\$\endgroup\$
1
\$\begingroup\$

Yes, switching the reference to internal will cause an error because the external capacitor is still charged to AVcc, and must be waited to discharge to internal reference.

However, the datasheet says you need to just discharge the first sample after changing the reference, so it will be more accurate and faster to just change the reference and discard maybe a few samples than to try sampling temperature with wrong reference 50 times.

\$\endgroup\$
0
\$\begingroup\$

As the microcontroller datasheet says the internal temperature sensor must be calibrated. I thought the value measured by an uncalibrated sensor has only a few degrees difference from the real value. As I searched the internet, I realized that this difference can be near 60 degrees (https://www.avrfreaks.net/forum/atmega328-temperature-sensor). So the problem of the large difference between the measured value and the actual value is solved.
As I described in the question changing the ADC reference voltage can cause other problems. Is it really necessary to change it? What happens if I read the internal temperature sensor with a 5V reference instead of 1.1V? I tested it by taking 50 samples at 1.1V reference converting it to millivolts (SamplesSum * 1100 / 50 / 1023) one time and taking 50 samples at 5V reference converting it to millivolts (SamplesSum * 5000 / 50 / 1023) another time. The result is the same and there has been just a little error because measuring with 1.1V reference is more accurate than 5V reference that it can be easily corrected by the calibration value.
And finally, to make the code simpler and using only a 16-bit integer to store values, I took 44 samples and divided the sum of all samples to 9 (SamplesSum * 5000 / 44 / 1023 = SamplesSum / 9). The result for my MCU is the temperature in degrees Celcius + 380 (My MCU calibration value is 380 - 273 = 107). I took 44 samples because the mentioned calculations have the lowest integer rounding error.

\$\endgroup\$

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.