cancel
Showing results for 
Search instead for 
Did you mean: 

help needed to acquire STM32G474VET6 internal temperature

phdm
Associate

Hello community,

I am new to stm32, and I need to read the temperature from the internal sensor of a stm32g4vet6.

I am at the point where I have read many things and have discovered that not all stm32's internal temperature sensors must be used the same way.

Currently I have asked to connect vref and temperature sensor to ADC5, asked for calibration of ADC5, and configured high values for the sampling time, and I can read adc-measured values for vref and temperature.

I can compute a temperature with

temperature = (130 - 30) * (Adc.Raw[0] * 33 / 30 - *TEMPSENSOR_CAL1_ADDR) / (*TEMPSENSOR_CAL2_ADDR - *TEMPSENSOR_CAL1_ADDR) + 30;

and I get plausible but unstable values.  (the nominal value of my Vref is 3.3 V)

However I wonder if I should use the value of Vref measured by the ADC, and *VREFINT_CAL_ADDR,  to get more stable values, and how ?

 

3 REPLIES 3
TDK
Super User

Consider adding more details here. In what way are the values both plausible and unstable?

If this is a custom board, duplicate the issue on known good hardware such as a nucleo board.

If you feel a post has answered your question, please click "Accept as Solution".
phdm
Associate

Thank you for your answer.

I work with a custom board, and unfortunately I do not have a 'known good hardware such as a nucleo board'.

My board is running at room temperature and in cruise mode, doing nothing else currently than measuring temperature.  With the above formula, the temperatures I get, measured every seconds, are between 27 and 37 C,

with sudden jumps from 27 to 37 or conversely.  After some more time, temperatures are between 29 and 41 C, with again sudden jumps.  Temperature are plausible, but the jumps are not.

 

Could measuring vref and using ^VREFINT help getting a more stable measure ? How ?


@phdm wrote:

Could measuring vref and using ^VREFINT help getting a more stable measure ? How ?


Yes. The temperature sensor is calibrated at a specific supply voltage (read datasheet for the correct value, it's not always the same for all processors, it's not always in the header file). By measuring the supply voltage using VREFINT you can get better accuracy. I use it.

  1. Convert temperature sensor calibration values to a formula from voltage to temperature. You only have to do this once during boot.
  2. Make sure the ADC is calibrated (if you use LL it's LL_ADC_StartCalibration()). You only have to do this once during boot.
  3. measure VREFINT and use that to calculate VREF+
  4. measure temperature sensor (make sure you use enough cycles as specified in datasheet)
  5. Use raw ADC value + calculated VREF+ to calculate temperature sensor voltage
  6. convert temperature sensor voltage to temperature 
Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.