Xmega ADC internal temperature sensor problems

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

I am struggling to get meaningful values out of my ATxmega128a1 ADC using the internal temperature sensor input.
I have configured the ADC with:
1 Mhz clock (16 Mhz peripheral clock and 16 prescale divisor)
12 Bit resolution,
internal input mode with no gain,
input mux for internal temp,
internal temperature sensor is enabled.
Tried both Signed and Unsigned modes,
And used both 1V and Vcc/1.6 reference voltage,
I have read the ADC Cal value from NVM and written to the CALL CALH registers (which appears funny since the value is 0x0FF for multiple xmegas).

I am especially confused by how to use the Internal Temp Cal value that is also stored in NVM.
I have two units, one has the internal temp Cal value of 0xAE4 and the other 0x8DC.
I understand that these values are suppose to represent 85 degrees Celcius but I'm not sure how to use this since the value would seem to be dependent upon the ADC settings such as VRef and signed versus unsigned modes, etc.
Any help would be greatly appreciated.

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

The internal temperature sensor is not well documented (at least last time I looked). That is a sign of it not working, not working well, or not considered to be important by Atmel.

I remember one previous thread about the internal Xmega temperature sensor, where someone managed to get a little bit more details from Atmel, but not much. Maybe using the search function can bring up that old thread.

Also remember that the ADC itself is broken in many twisted ways. Get the latest A1 datasheet and check the errata section.

Stealing Proteus doesn't make you an engineer.

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

WCM,

Welcome to the Forum.

Several thoughts on the Xmega internal Temp:

I don't have meaningful results, yet, either.

Get Application Note: AVR1300: Using the Xmega ADC.
It has a better explaination of the "Internal" Inputs for the ADC, (Temp, Bandgap, Vcc/10, and DAC).

You mentioned sampling at 1MHz. This is too fast for the Internal sources. Somewhere in the Xmega data sheets and the Ap Note it says that the Maximum sampling for the internal sources is 100 KS/second. You must increase your ADC clock divisor, to slow down your sampling of this signal.

I read my Temp "Calibration" values from AVR Studio4 via my programmer, not in software. My High byte was 0C Low byte was 06 Hex. (3078 dec).

The setup Atmel used to make the calibration measurements was: Unsigned mode, 12 bit, Internal 1.00 V Reference. Certainly start with this format.

Using a two point calibration, 0 ADC counts at 0 K, (-273.15 'C), and 3078 dec (My callibration values), at 358 K, (85'C), I get 'C = ((ADC Count)*(0.116309))-273.15

Note first that Atmel says the Calibration at 85'C giving the Calibration bytes can be off by +/- 5 'C.

My first effort, (with MANY) variables I haven't tracked down yet, gave a chip temp of 42 'C. Way too high. Ambient is 23 'C. Say the chip die is +5'C, (Rough Guess), + 5'C high side error, gives 33'C, not 42'C.

When I switched 1 bit in the code, on the Mux control, to measure the Vcc/10 instead of the Temp, I got ResH = 193, ResL = 5 giving Vcc/10 + delta V = 0.359 V.
Delta V is Estimated at 0.05 * Vref, (Vref = 1V,), Delta V = 0.05 V, (Estimated, not yet measured.)
(This estimate is from the Ap Note.)
This then gives a Vcc/10 of 0.359 - 0.05 = 0.309
Vcc = 3.09 V.
I have a 3 V linear regulator on the board, so this seems abut right! :)

I will have to actually measure Vcc, and Delta V, to double check the above.

Anyways, Very early code, with some uncertainties, gave a meaningful Vcc reading, and a meaningless Chip Temp reading...

It may be several weeks or so before I can really get back to testing this... (Trip away from home without this board...).

Just thougth I would share my initial Test Results with you.

JC

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

What voltage do you get when measuring the temperature sensor?

I get 0.535 volts. This could be the forward voltage drop of a silicon diode. That's what I would use for measuring chip temperature.

Silicon diode forward voltage changes about -2mv/°C. To test my theory someone should put their Xmega in the refrigerator, freezer, and/or the oven, and see how it changes. I would volunteer but my Xplain board is plugged into a USB port on my 'puter, and the USB cable isn't long enough. :)

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

Thanks for the feedback guys!
My testing has been shelved for the near term by higher priority items and I probably won't get back to it for a couple of weeks, but I wanted to give some details on VCC measurements that we performed as well.

Measured VCC/10 (internal input) …
Should be VCC/10 = 3.3/10 = .33
But actually VCC was measured as 3.308

Configured to run unsigned, prescaler 128, 12 bit resolution
Result values from the ADC range from 0x616 – 0x621

And from the app note AVR1300, the value should be:

RES = (Vinp – (-deltaV)) / VRef * GAIN * TOP
where in my case,
Vinp = 0.3308
deltaV ~= 0.05
VRef = 1
No Gain
Top = 4095
so (0.3308 + 0.05) * 4095 = 0x617

As long as my math is correct, then the ADC output values appear to be in the ballpark.

Our main issue with temperature readings were inconsistency. Ambient temperature varied quite dramatically from one measurement to the next. And I'm wondering JC, how did you determine that ambient was 23C for you?

We tried to generate the equation for the slope by heating/cooling the chip slowly with a heat gun and freeze spray while checking chip temperature with a thermocouple attached to the atmel chip and although I admit that the internal temp will differ somewhat from the outside chip temp, what else can you do?
We did do the fridge/freezer test but again, the temperature we read varied dramatically. So in general it appears to be too inaccurate to be used.

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

Quote:
And I'm wondering JC, how did you determine that ambient was 23C for you?

That was the easy part... an SHT71 and a DS18B20 sitting adjacient to the board. I didn't put a sensor on the uC's body to get a read on that, (yet).

JC

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

wcm0050 wrote:

I have read the ADC Cal value from NVM and written to the CALL CALH registers (which appears funny since the value is 0x0FF for multiple xmegas).
It's funny, you got that right. My two 128a1 chips also have a calibration value of 0x0ff.

You wrote to CALL, but I bet you didn't write to CALH. I can't change CALH with software or JTAG. It seems to be permanently set to 0x00.

Changing CALL from 0xff to 0x00 changes the conversion count by 1 or 2.

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

I guess at this point, I can not be 100% sure about anything, however I do intend to write to both the low and high registers (CALL, CALH). I am using the sample ADC_Driver atmel provided and it grabs the values from NVM and writes CALL then CALH.

I just went back and checked my notes and I had received a response from an Atmel Field App Engineer who recommended reducing the sampling frequency to 50kHz and using signed mode, so I did do that but it didn't improve things. He also noted that calibration values of 0xFF are not correct and we need to investigate why this is the case. That is as far as it got.

Some additional info that he passed along was:

Factory Calibration:

TEMPSENSE1:TEMPSENSE0 are values captured at 85C and put into signature row, which can be used for single or multi-point temperature sensor calibration.

ADC Configuration used during calibration is Unsigned - 12 Bit with Internal 1V reference.

User Calibration:

The relationship is quite linear and hence the value of the sensor can be measured at a particular temperature (say 25C) as per your requirement and the steps / degree can be calculated from this. For a fairly accurate temperature reading we have to measure at a second temperature (for instance at 25'C) and use these two values to calculate a temperature coefficient.

Depending on the requirements to accuracy one or two point calibration should be used.

The temperature sensor has to be read using ADC. The assumption is that reading 0x000 on the ADC should approximately represent a temperature of 0K, while reading the value in the calibration row would represent a temperature of 358K (85C). While measuring the internal temperature sensor using ADC, the internal 1V reference has to be used as reference as the factory calibration values are derived at using the same.

Drawing a line from this point (0x000 on ADC, corresponding to 0K) and to the stored calibration value at 85 Celsius. This is what we call a one-point calibration.

Reference Documents:

Application Note AVR122: Calibration of the AVR's internal temperature reference provides more details on the calibration of internal temperature reference, though is not specific to ATxmega devices can be used as reference to calibration of the internal temperature sensor.

Application Note AVR1300: Using the XMEGA ADC explains on configuring and using ATxmega ADC

Point to be taken care of:

One thing to remember while using the internal temperature sensor as input to ATxmega ADC is that the maximum sampling rate for internal inputs is 100ksps for ATxmega ADC.

Accuracy of the Internal Temperature Sensor:

With 1 point calibration at 85C (factory calibration) the accuracy is about +/- 10C down to 0C and +/- 15C down to -45C.

With two point calibration at 85C and 25C it is possible to get +/- 3C accuracy within that range, but below 0C the accuracy will be up to +/- 6C.

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

You can write to CALH, but it doesn't do anything for me. CALH seems to be read only in my 128a1. That fact alone could explain why the factory calibration doesn't work. It also indicates the datasheet is wrong, because the datasheet says that register is writeable. Well I suppose it makes more sense to say the datasheet is right and the silicon is wrong.

I tried a quick and dirty test of the temperature sensor. The voltage seems to increase about 2 mv per degree Celsius.

Normally when I use silicon diodes to measure temperature, the voltage decreases about 2 mv per degree Celsius. I wonder why the sensor in the AVR reverses this.

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

I have problems with the temperature measurement also.

I have a seperated thread on this

https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=700980

My plan is to end the other thread. If you have some though on my problems, feel free to comment in this current thread.

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

Just did try another board. I should measure 22 Celsius.
It then measures 22 Celsius and sometimes jump to 37 Celsius.

Here again the error measure is always around 37 Celsius.

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

It seems that there areas that the measurement do not fails. F.eks on the first board things did fail around 22 Celsius, but does NOT fails when the temperature increase.

Also it does seems that it not fails when the measuring in Signed mode. But how can I know, might be in an measure range that it does not fails?

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

I haven't looked at this in a while. I think there is a problem with unsigned mode so I always use signed mode. As you probably know, there is a lot of jitter in the readings so I take 9 readings. I throw away the first and average the rest.

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

I am a new user and this is my first post in AVRFreaks.

I tested XMEGA internal temperature sensor and I saw the following results:

ADC value due to internal temperature sensor=2431
Calibration value read by programmer=2795

These results lead to the temperature of
((358)* 2431)/2795)-273=38.37 degrees celcius
ambient temperature was about 30-32 degrees celcius.
test was done on ATXMEGA64A3.

Ozhan KD
Knowledge is POWER

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

One thing that I think we need to include in the equation is the ADC's deltaV in unsigned mode. The datasheet says that theoretically if the temperature is 0°K, the output is 0. But the ADC's null in unsigned mode is around 200 (Figure 25-11 of the datasheet).

So a more accurate equation would be:

Temperature in °C = (358*(ADC-200))/(tempCal-200) - 273

But even with this adjustment I think my measurements are still off, the temperature is above of what it should be.

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

I did some new tests in same conditions:

---------------------------------------------
chip = ATxmega64a3
ADC = ADCA
clkper = 2MHz
clkADC = 15.625KHz
Temp sensor calibration value = 0xACC = 2764
Convertion mode = Unsigned single ended
Resolution = 12bit
Reference = internal 1.00v
Result(64 point average) = 2355
Temp=358*(2355 - 200) / (2764 - 200) - 273 = 27.89'C
-----------------------------------------------------
chip = ATxmega64a3
ADC = ADCA
clkper = 2MHz
clkADC = 15.625KHz
Temp sensor calibration value = 0xACC = 2764
Convertion mode = Unsigned single ended
Resolution = 12bit
Reference = internal Vcc/1.6 (Vcc= 3.3V)
Result(64 point average) = 1236
=>
Delta_V = 200 * Vref / 4096 = 0.0488 * Vref
=> Vsensor = (1236 * (3.3/1.6) / 4096) - Delta_V = 0.521
=> Result(scaled to 1.00v reference)=(0.521+0.0488)* 4096= 2333.9
Temp=358*(2333.9 - 200) / (2764 - 200) - 273 = 24.94'C
-----------------------------------------------------

*Note : Using ADCB for internal temprature sensor measurement shows very unstable results.

Ozhan KD
Knowledge is POWER

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

I don't know about the XMEGA but a few months ago I bought a little IR thermometer for EUR20.

Very easy and quick to measure temperatures of all kind of solid objects.

But on some surfaces it does not work properly. For example, it works perfectly on a black anodized heatsink, but not on the shiny bright aluminimum heatsinks. But you get what you pay for.

Chose the best picture you like:
http://www.google.nl/images?q=ba...

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

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

A bit off-topic
@Paulvdh

Quote:
But on some surfaces it does not work properly. For example, it works perfectly on a black anodized heatsink, but not on the shiny bright aluminimum heatsinks. But you get what you pay for.

Some time ago I got interested in Melexis IR-temperature sensors. Look at p.43 in their datasheet for an explanation of the phenomena you're experiencing.
http://www.melexis.com/Assets/IR...

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

I haven't succeeded in getting sensible temperature readings over many different chips (xmega32A4) (yet)...

One thing eludes me, though.. Are the adc values specified by atmel (000 at 0K, CAL at 85C) the actual unsigned adc value or the values after subtracting the unsigned mode offset (~200) or a mix of both?

does anybody here know the exact answer to this?

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

hooverphonique wrote:
One thing eludes me, though.. Are the adc values specified by atmel (000 at 0K, CAL at 85C) the actual unsigned adc value or the values after subtracting the unsigned mode offset (~200) or a mix of both?

It is the actual value without substracting offset

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

electronic.designer wrote:
Reference = internal Vcc/1.6 (Vcc= 3.3V)

The calibration value in the signature row according to the AN AVR1300 was measured using the 1.0V reference so results are only "guaranteed" on this configuration.

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

wow old thread

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

electronic.designer wrote:
I did some new tests in same conditions:

---------------------------------------------
chip = ATxmega64a3
ADC = ADCA
clkper = 2MHz
clkADC = 15.625KHz
Temp sensor calibration value = 0xACC = 2764
Convertion mode = Unsigned single ended
Resolution = 12bit
Reference = internal 1.00v
Result(64 point average) = 2355
Temp=358*(2355 - 200) / (2764 - 200) - 273 = 27.89'C
-----------------------------------------------------
chip = ATxmega64a3
ADC = ADCA
clkper = 2MHz
clkADC = 15.625KHz
Temp sensor calibration value = 0xACC = 2764
Convertion mode = Unsigned single ended
Resolution = 12bit
Reference = internal Vcc/1.6 (Vcc= 3.3V)
Result(64 point average) = 1236
=>
Delta_V = 200 * Vref / 4096 = 0.0488 * Vref
=> Vsensor = (1236 * (3.3/1.6) / 4096) - Delta_V = 0.521
=> Result(scaled to 1.00v reference)=(0.521+0.0488)* 4096= 2333.9
Temp=358*(2333.9 - 200) / (2764 - 200) - 273 = 24.94'C

Ozhan KD
Knowledge is POWER

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

Perhaps a bit late...
but anyway, here is the answer:

http://www.mcselec.com/index2.ph...

Regards
/Per

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

I can confirm it works, and it seems like there is a constant offset error but otherwise the sensor is fairly linear over 20-35C.

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

This is an old thread. But according to my posts I think XMEGA internal temperature sensor with +-15C accuracy is only appropriate for 85C over temperature detection and activating alarm, fault ,... condition.

Ozhan KD
Knowledge is POWER

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

I've used it for some very basic clock correction. I calibrate it at room temperature with an IR thermometer in a computer controlled environment. It's still only +/-3C in my quick tests but the result is an RTC that is better than 1 second per day.

 

It's not great but not totally useless either.

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

I was just reading through and got interested...

Which Xmega chip did you use?

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

128A3U. I've used the sensor on the 32E5 with the factory calibration values (they have an additional room temperature calibration value) but have not really tested it much.