cancel
Showing results for 
Search instead for 
Did you mean: 

STM2F7 internal temperature sensor

1991red1991
Associate III

I would like to know more about the internal temperature sensor. The RM says: Precision: ±1.5 °C. And the Note section says: “The temperature sensor output voltage changes linearly with temperature. The offset of this linear function depends on each chip due to process variation (up to 45 °C from one chip to another)"

That is, at an actual temperature of 25 °C, I will see 2.5-47.5 °C on different chips? However, this function will be linear. Do I understand correctly?

Also my microcontroller runs at maximum frequency and because of this it gets very hot. I took two measurements at -40, I got -17.5°C, and at +80, I got +91°C. The measurement was made with power on and operation for at least 30 minutes.

I need to change the signal level linearly depending on the temperature, but it turns out that with this sensor I cannot do this. I thought that I could measure the temperature in 1 minute after turning it on, when the microcontroller is already warm (it will give me a deviation from the real temperature) and know the actual temperature with the precision of 1.5°C and the deviation due to the heating of the microcontroller.

7 REPLIES 7

Which STM32, exactly? There is no STM2F7.

You can eliminate the chip-to-chip difference simply by using the TS_CAL1 and TS_CAL2 values stored into system FLASH during manufacturing.

"deviation due to the heating of the microcontroller" is not a constant temperature difference, it depends on the power consumption (i.e. power supply voltage, number of transistors switching and their frequency, which means the computation the mcu performs, the current drawn from its pins; and also on the many details how heat is dissipated from the package, e.g. what is the thermal conductivity of the tracks through which the heat is drawn from the chip, whether there are other heat sources in the vicinity of the chip, whether there is forced or natural air movement around it, etc.

If you need to measure ambient temperature, use an external temperature sensor.

JW

I don't understand how to use TS_CAL1 and TS_CAL2… What do these numbers mean? Can you give an example?

"deviation due to the heating of the microcontroller" - if I always use the same board with the same software, then I think this value will tend to a constant number.

Piranha
Chief II

AN3964 is applicable for L series microcontrollers. In F7 series, the temperature is calculated as follows:

Temperature (in °C) = {(VSENSE – V25) / Avg_Slope} + 25

Perhaps I can do this: (110-30)*( TS_CAL2- TS_CAL1). I will get a coefficient by which I must multiply the resulting temperature in order to know the real one.

Piranha
Chief II

That formula from the reference manual is for the case without the calibration values and, by the way, uses voltages, not ADC units. Anyway, all of those formulas are just a simple proportions with an offset and represent the same principle. The slope is (TS_CAL2 - TS_CAL1) / (110 - 30) in ADC units per °C. Take the formula from the reference manual, put this slope fraction in place of the "slope" variable, replace the voltages with ADC units, replace the offset degrees and you've got the formula from the AN3964. How are you going to develop a software, if you cannot operate with such a basic math?

#define DIVS_ROUND(n, d)    ( (((n) < 0) ^ ((d) < 0)) ? (((n) - (d) / 2) / (d)) : (((n) + (d) / 2) / (d)) )
 
#define TEMP_MULT 10
 
int32_t n = ((int32_t)ADC1->DR - *TEMPSENSOR_CAL1_ADDR_CMSIS) * (110 - 30) * TEMP_MULT;
int32_t d = (int32_t)*TEMPSENSOR_CAL2_ADDR_CMSIS - *TEMPSENSOR_CAL1_ADDR_CMSIS;
int32_t temp = DIVS_ROUND(n, d) + 30 * TEMP_MULT;

Here is a code exactly for F7, which does everything correctly with integer-only math. TEMP_MULT returns the result multiplied by some constant without losing the resolution. Leaving it to 10 means that the value 321 represents 32,1 °C. Take a note that the ADC resolution itself limits the temperature resolution to 0,3 °C, so it's not worth increasing it even more.

That is, if I use the formula "{(VSENSE - V25) / Avg_Slope} + 25", then I will get a ±45°C spread from chip to chip as indicated in RM, since it does not use calibrated values. I understand correctly?

The example you gave is applicable only if the voltage of the reference source is 3.3V, since the calibration values obtained by ST are at a voltage of 3.3V. Right?

> The example you gave is applicable only if the voltage of the reference source is 3.3V, since the calibration values obtained by ST are at a voltage of 3.3V. Right?

Yes, you have to scale the temperature sensor reading by ratio between your reference voltage and reference voltage used by ST at factory calibration. You can include measurement of your reference voltage indirectly by measuring the internal reference VREFINT and then using that divided by the calibration value of that internal reference, as factory calibration of VREFINT and temperature sensor is taken probably in all STM32 models at the same reference voltage.

[shameless self-advertisement] Some writeup of this same issue (in abstract form, i.e. without the rounding Piranha provided) here. [/shameless self-advertisement]

JW