ATmega328 temperature sensor

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

I've read all the datasheets and so on, so this problem is probably real.

I have just got my first ATmega328 chips going after previously using 168s. That means I should now have the internal temperature sensor available.

I have loads of stuff that reads other AtoD values out of the chip, so I'm pretty convinced I don't have anything grossly wrong with my AtoD routines.

[ In particular I have implemented a 5ms delay after changing reference voltages, since this needs to be done on the 1V1 internal ref, which works fine on other channels. ] Anyway I'm averaging 16 readings, so the ref would have settled for most of them.

I see the d/s says that at room temp I should get roughly 314mv = 314/1100*1024 ~ 292 counts

Instead I get about 370 counts, which ought to correspond to about 100C.
There's no way the chip is at 100C, the case is cold to the touch.

It goes up nicely if I point my hot air gun at the MPU, so I am reading some sort of temperature sensor.

The d/s says it may be "a bit out" but this seems a huge error.

Any thoughts - or is this sort of deviation from expectations just my bad luck?

TVM

David

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

Quote:

Anyway I'm averaging 16 readings, so the ref would have settled for most of them.

perhaps compare the 16th reading to the average. If coming down from e.g. 5V reference it takes some number of conversions to "bleed down" the reference. There are some threads on this--try to search them out.

Quote:

I have just got my first ATmega328 chips going after previously using 168s. That means I should now have the internal temperature sensor available.


Well, that depends on the rest of the letters (or lack thereof) in the part number.

Original 48/88/168--no temperature sensor channel
P versions -- temperature sensor channel
A/PA versions -- temperature sensor channel

So any made in the past four years or so should have it.

I only used the temperature sensor on one app and it was "close enough" for overheating detection purposes. I don't remember all the analysis.

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

:twisted: perhaps your AVR is running hot? Can you put your finger on it?

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

> the case is cold to the touch.

theusch - Well it could be documentation I guess.

the d/s I have "8271D–AVR–05/11" says all 328 parts have, irrespective of A, P etc.

But that could be wrong - though the value goes up and down about 1 degree per degree, it just starts at 100 not zero.

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

Quote:

the d/s I have "8271D–AVR–05/11" says all 328 parts have, irrespective of A, P etc.


I won't disagree. I said nothing about that. I was questioning the '168 not having it. Which was true in the past, but not for chips made in the past four years or so.

If you construct a small test program that does nothing but use the BG and report ADC counts from the temperature channel, what results do you get? That will let us peek at your code, and perhaps try it ourselves to try to get more insight.

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

Got similar behaviour with a mega88PA. Any with a working internal temperature sensor in this mcu family.

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

hof - as far as I can see it works - in that it goes up and down by about 1 degree per degree. But the base-line output is outside the range suggested in the d/s

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
//------------------------------ 
unsigned int readchiptemp(void){ 
//read ch n of internal a/d  10 bit unsigned 

  ADMUX= 0xC0 + 8; //select 1.1 vref + channel 8 
  ADCSRA |= 0x40;  //init conversion 
  while((ADCSRA & 0x40) != 0){}; //wait for conv complete 
  return ADC; 
} 

//------------------------- 
void internaltemploop(void){ 
//read ad chan 8, 1mv/deg C-> 0degc=0v 1000degc=1.0v 
char c; 
unsigned int rawtempdat; 

  cprintf("internaltemploop  q=quit\n"); 
  ad2volts=1.1/1023.0; //1.1v=1023  
//  cprintf("ad2volts %#7.3f \n",ad2volts); 
  volts2degC = 25.0/0.314; 
  cprintf("ad   V        degC    degF \n"); 
  c=0; 
  while(c != 'q'){ 
    if(kbhit()){ 
      c=getchar(); 
    }  
    rawtempdat=readchiptemp();    //1023=1.1v 
    volts = rawtempdat*ad2volts;  //1.1 
    degC = volts*volts2degC;      
    degF = degC * 1.8 + 32.0; 
    cprintf("%4d %#7.3f %#7.1f %#7.1f \r",rawtempdat,volts,degC,degF); // 
    delnms(1); 
    StackCheck(); 
  } 
} 

Imagecraft compiler user

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

I see the same thing with my 88PA. it reads 366 at room remperature (about 22C in here), should be around 311 according to the datasheet since the chip isnt near that hot (cool to the touch).

This is uncalibrated (offset/gain), but it seems like an awful lot of error, doesn't it?

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

Quote:

(cool to the touch).

Anything beneath blood temperature (37C) is going to feel "cool to the touch". Use a temperature probe on the chip to calibrate it.

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

clawson wrote:
Anything beneath blood temperature (37C) is going to feel "cool to the touch". Use a temperature probe on the chip to calibrate it.

granted, but my point was really more to say that the chip isnt even close to the 80C that i get back since that would be very hot to the touch.

I guess the question at this point is-- "is it possible that the uncalibrated chip is 55C (or mV) off?". I could certainly calibrate it, but a two-point calibration is somewhat infeasible (costly man hours) in production.

Not to thread hijack, but I think I'm seeing the same behavior as dexdynedgc

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

sadffffff,

Your figures match mine exactly - the chip reads 65 degrees or so above what the d/s says it should - apart from that it seems to work fine :-)

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

I betcha you arent using the 1.1V reference are you? (Hint: the green subroutine up there works)

Imagecraft compiler user

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

bobgardner,
I'm using that same reference. Your code is just about what I have word for word. To be sure, I replaced my code with yours this morning, and unfortunately there is no difference. Thanks anyway, it's always nice to check against someone elses code.

dexdynedgc,
I'm still a little concerned if theres an appreciable gain error to go along with this offset. I'm going to shoot the question to a field applications engineer today. I'll post back if I find anything.

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

I've just found one out of a batch of 10 that reads 20 degrees higher.

I have another sensor on the same board, and I can only say that VERY ROUGHLY they both go up in parallel. No exactitude whatever, just to within 15% or so.

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

Interesting to note that in Xmega each chip not only has a factory profiled oscillator calibration value (just as tiny/mega do) but there also calibration values for ADC, DAC and temperature sensor. So it looks like Atmel may have learned from their mistakes and realised it would be wise to factory calibrate each die in the newer design chips.