uncalibrated internal temperature sensor accuracy

Go To Last Post
29 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Various sources I've read including AVR122 indicate typical uncalibrated accuracy of +-10C. I just tested an ATtiny85, and am getting raw readings of 254 at room temperature (~20C). Is it just bad luck, or is +-10C just the average accuracy, with +-40C outliers still being somewhat common?

Here's the guts of my code:

    unsigned int temperature;

    ADMUX |= ((1<<REFS1) | 0x0f);   // select temperature sensor
    // turn on ADC with prescaler of /128
    ADCSRA = ((1<<ADEN)|(1<<ADSC)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0));
    while (ADCSRA & (1<<ADSC)); // wait for conversion to finish
    temperature = ADCW;

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you waiting for the internal reference to stabilise? The startup time can be as much as 70 μs, typically 40 μs.

I see you've selected a prescaler of 128. Can I assume you're running at 16 MHz? That would give you an ADC clock of 125 kHz. S/H takes place at 1.5 ADC clock cycles after conversion start. At 125 kHz that's only 12 μs (and change, counting machine cycles between the ADMUX |= and ADCSRA =), not enough for the reference to properly start.

Additionally, ADC noise reduction mode is recommended for reading the internal temperature sensor.

And touching on another of your threads, a bypass cap is also very important when using the ADC.

    ADMUX |= ((1<<REFS1) | 0x0f);

BTW, why the RWM?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is not just one-shot. I repeat the code in a loop with a 500ms delay. So the first result may be bogus, but after that the vref should be good.
"The first ADC conversion result after switching voltage reference source may be inaccurate, and the user is advised to discard this result."

The ~254 running result is with a 100nf cap next to the Vcc pin. Interestingly without the cap I get better results - ~278.

This is with the internal 8Mhz RC oscillator, 5V.

Not sure why I used the |=; probably some lazy cut/paste code. Changing it to a direct assignment doesn't make a difference in the results, though it saves 2 bytes on the code size.

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ralphd wrote:
Interestingly without the cap I get better results - ~278.
This is not 'better', merely 'closer to what you expect'.

In truth, I've seen wildly different results from one AVR to the next, and in fact different results on the same AVR depending on whether I do the conversion in active mode, idle mode, or ADC noise reduction mode, with a spread of over 20 LSB.

A big component in the out-of-the-box accuracy of the temperature sensor is the bandgap. It has a nominal voltage of 1.1 V, but can be as far off typical as +/- 10%.

The bottom line is you need to calibrate. Multi-point calibration with linear interpolation is likely best, as the sensor's response isn't very linear. The sensor's resolution is only about 1 degree C per LSB anyway. If you really need an accurate temperature sensor, this isn't going to be it.

There are techniques you could apply with a bit of external hardware (RC filter), and at the cost of AREF and a GPIO pin which could theoretically improve accuracy/resolution to about 0.25 C or better, but an NTC or a DS18S80 would probably be a better bet.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Different AVR data sheets give different formulas for the Temperature Sensor.

I would guess that modern AVRs all use the same 1.1V BandGap Voltage generator. And probably use similar silicon for the Sensor.

So it is up to you to choose the most 'likely' formula. And do some form of calibration. Quite honestly, just reading the office temperature is 'good enough'. Set your 'offset' accordingly. Then subsequent readings will give you a rough idea of chip temperature.

Most people only use the Sensor for 'it is too hot, hardware has failed'.

Somewhere, I have some test code. I can't remember where. I think I may have posted it here in a thread about "Reading Temperature with the Watchdog Oscillator"

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What voltages are your VBG (I assume that you know your Vcc )?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

What voltages are your VBG (I assume that you know your Vcc )?

Indeed--that usually needs a one-time calibration IME.

Back to the original question--are your readings riding high or low? What makes you think that a temperature sensor internal to an IC drawing several mA will give a reading corresponding to the temperature in the room?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
raw readings of 254 at room temperature (~20C)
! OP¨'s 1rst post
Quote:
Interestingly without the cap I get better results - ~278.

Well, they seem 40 C low.... excluding overheating...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Quote:

What voltages are your VBG (I assume that you know your Vcc )?

Indeed--that usually needs a one-time calibration IME.

Back to the original question--are your readings riding high or low? What makes you think that a temperature sensor internal to an IC drawing several mA will give a reading corresponding to the temperature in the room?


20C is 293K, so 254 is 39K too low. And yes, I would expect an AVR drawing 5-10mA to be ~4K warmer than ambient.
http://www.narkidae.com/research...

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sparrow2 wrote:
What voltages are your VBG (I assume that you know your Vcc )?

Good idea to check Vbg.

   ADMUX = 0x0c;   // select 1.1 Vbg

I get raw readings of ~189/1023 * 5.0V = 0.924V!
Figure 22-37 indicates typical Vbg @20-25c & 5V would be around 1.08V. Table 21-4 indicates a "guideline" minimum of 1.0V, so it seems I got unlucky with one of the worst chips in the bin as far as Vbg goes.

Switching to 3.2V supply gives much better results:
Vbg = ~325/1023 * 3.2V = 1.017V

The improvement in temperature sensor accuracy is HUGE. At 3.2V I get raw readings hovering around 295-296.

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As with the temperature sensor, you need to make a bunch of readings on the BG channel to get good results. The reasons vary. There are extensive threads on this (both reading BG and the temperature channel).

Short answer, that works well in practice: Take at least 16 consecutive ADC reads of the channel. Ideally 20 or more. Use that last conversion result.

I have a current app where I need to switch from (A)Vcc reference to BG reference. So there is a two-fold process to get good results:

-- Calibrate the BG. I do that at ISP time, assuming Vcc is 5.0V. If my adjustment factor in EEPROM hasn't been set, I set up and run a bunch of conversions on the BG channel using Vcc reference, then store that result.

-- When switching to the BG reference from Vcc reference during run time, it takes some time and conversions for the cap on AREF to "die down" to BG level. So I do a bunch of dummy conversions.

Right, wrong, or indifferent that's the way (at least many) AVR8 models work. You and I can stand on the shoulders of the giants that did the investigative work to come up with the above workarounds.

Using my calibrated BG value:
https://www.avrfreaks.net/index.p...

"AVRs measure their own VCC, but do it badly. "
https://www.avrfreaks.net/index.p...

Other "anecdotal" links:
https://www.avrfreaks.net/index.p...
https://www.avrfreaks.net/index.p... and links to prior within
https://www.avrfreaks.net/index.p...
https://www.avrfreaks.net/index.p... temperature sensor like this thread

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And proper decoupling is a necessaty for decent ADC behaviour (amongst others). OP has a different opinion about that, so OP can ignore this tip.

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tricia, and Ulyana. You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ralphd wrote:
I get raw readings of ~189/1023 * 5.0V = 0.924V!
I assume you are waiting 1 ms for Vbg to settle, are averaging a number of results, and are testing with a bypass cap in place...
Quote:
Table 21-4 indicates a "guideline" minimum of 1.0V, so it seems I got unlucky with one of the worst chips in the bin as far as Vbg goes.
It's up for interpretation whether the 1.0V-1.2V range given for Vbg is a 'guideline'. Table 21.4 pertains to the reset characteristics, and says it is. Tables 21-8 and 21-9 pertain to the ADC, and say only that the 2.56V reference min/typ/max voltages are 'guidelines'.

It isn't outside the realm of possibility that you've stumbled across a part so far out-of-spec, but it would be quite unusual. Have you tested with other t85s?

Quote:
Switching to 3.2V supply gives much better results:
This is suspect. You're seeing a difference of over 90 mV. At room temperature figure 22-36 suggests you should see ~23 mV. Figure 22-37 tells a similar story.

Again, while this isn't outside of the realm of possibility, I'd start to suspect a bad device or an oversight in the test procedure.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does the number increase with your thumb on the computer?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
Does the number increase with your thumb on the computer?

I heated up a 3/8" short steel rod on a wood stove. When I balanced it on top of the t85, the numbers shot up by ~40. I put the steel rod in the freezer until it had ice crystals on it, and again balanced it on top of the t85. The numbers dropped by ~20.

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I haven't found my other tiny85-pu yet, and my digispark is giving me "USB device not recognized", but in the mean time I did some more decoupling tests.
At 5V with a 100nf cap raw temperature numbers are bouncing around 246. I added a 220nf cap in parallel, and the numbers dropped by 2 (~244). I removed the 100nf cap (leaving the 220), and the numbers dropped to 236. Removing the 220nf caused the numbers to jump to 274-276.

I see now why many projects use external temperature sensors. A 10c 10K thermistor is looking a lot easier...

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

"AVRs measure their own VCC, but do it badly. "
https://www.avrfreaks.net/index.p...

Thanks for the references. The above post indicates non-linearity in Vbg to the tune of ~100mV is not unheard of.

It looks like if I want reasonably accurate temperature readings for a 100C range, I'd need 3 calibrations:
1) calibrate Vbg at typical VCC
2) calibrate the temperature sensor at the low end of the range
4) calibrate the temperature sensor at the high end of the range

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I see now why many projects use external temperature sensors. A 10c 10K thermistor is looking a lot easier...

Again, it depends on what you intend to use the internal temperature sensor for. Appropriate IMO for "board/enclosure too hot". Not appropriate IMO for ambient sensing, due to chip self-heating.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I dont like the way you set the mux before you enable the a/d. Put that enable line in a function called 'initad()' and call it before you enter the main while. Call readad() as needed.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ralphd--

In one of the prior discussions on similar topic(s) I did some tests with BG varying AVR supply voltage. I did NOT get the results you saw; rather the readings were +/- 1 ADC count.
https://www.avrfreaks.net/index.p...
(which is the "badly" thread near the end)

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
I dont like the way you set the mux before you enable the a/d. Put that enable line in a function called 'initad()' and call it before you enter the main while. Call readad() as needed.

Not that it would affect the performance of the ADC, but that's the way I did it (aside from the fact I didn't use the same function names) I just cut/paste the two parts of my code into my post, rather than posting the whole code.

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you had a look at AVR122? The non-linearity of Vbg over a range of Vcc isn't nearly as profound as the non-linearity of the temperature sensor itself.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just tested a couple of t84a's, date code 1333, running off the internal 8Mhz RC oscillator. Vbg and the temperature results are much better than the t85.

5.0V T=287 steady, vref =~213 = 1.041V
2nd chip: 4.78V T=285 steady ,vref =~ 225 = 1.0513
3.25v: T= 290 steady, vref = 334 steady = 1.06V
2nd chip: T=290 steady, vref = 341 steady = 1.083

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So you don't want to try my suggestion? Or are you talking just to hear your head roar? What did they tell you about being argumentative in "How to get along with Other Engineers" class? Just keep showing yer arse, then go to the LinkedIn AVR forum and piss them off too.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ralphd wrote:
I just tested a couple of t84a's
'A' parts are manufactured using a different process, so different electrical properties are expected. If you had any vanilla t84 to test, it wouldn't surprise me if they performed similarly to the t85.

Here are a few related posts:
https://www.avrfreaks.net/index.p...
https://www.avrfreaks.net/index.p...

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use the internal temp sensor of a T25 in a solar charge controller project, I was not concerned with accuracy of the temp sensor as much as measuring the delta over time to adjust the battery float voltage, up with cooler temps, down with hotter temps. Seems to work well in this app. Since the supply voltage is more or less constant and the supply line is bypassed with the same value cap, the readings are fairly consistent from board to board.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try running your read-the-ad routine on a regular old ad channel with a pot on it. That doesnt work either huh? Could it be because you are reinitializg the a/d everytime?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found my other t85-pu and tested it with a 220nF decoupling cap between VCC and gnd.
T85 #2 4.98V/ T=234 steady, 268w/o cap, vref =~210 = 1.02v, ~192 w/ cap = 0.935
3.25v: T= 278 steady, vref =~ 337= 1.07V , w/o cap = unstable

So once again, the Vbg @5V is outside the 1.0-1.2V range.

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you read a 1.5V AA cell and get an accurate reading? (you arent reading the a/d correctly).

Imagecraft compiler user