Search code examples
microcontrollerstm32stm32f4discoverystm32f4stm32f0

Right formula for calculating temperature sensor using STMF401RE Nucleo?


I'm using STM32F401RE Nucleo board to measure the ambient temperature. After the sampling process, I receive a digital value from ADC_CHANNEL_TEMPERATURE and I want to convert this digital value into C°. I searched on the internet for this and I found two different methods:

Method 1: Page 226 in http://www.st.com/content/ccc/resource/technical/document

Temp(degree) = (V_sense - V_25)/Avg_slope + 25

Method 2: Page 251 in http://www.st.com/content/ccc/resource/technical/document

Temp(degree) = ( ( (110 - 30)*(TS_DATA - TS_CAL1) ) / (TS_CAL_2 - TS_CAL_1) ) + 30
Where:
    - TS_CAL2: temperature sensor calibration value at 110 C°
    - TS_CAL1: temperature sensor calibration value at 30 C°
    - TS_DATA: temperature sensor output from ADC

It confuses me which one is the correct formula for calculating the temperature in C°. Although Method 1 is from reference manual of STM32F401, the temperature result doesn't look correctly. While Method 2 from reference manual of STM32F0 series, it looks more reasonable.

Still I don't know which formula should I apply when using STM32F401RE Nucleo board?


Solution

  • Method 1 Temp(degree) = (V_sense - V_25)/Avg_slope + 25 is a simplified version where calibration is presumably done by pre-measuring the value at 25° and assigning it to V_25. In this context, Avg_slope is probably taken from datasheet - but it could be also a result of some calibration.

    Method 2 Temp(degree) = ( ( (110 - 30)*(TS_DATA - TS_CAL1) ) / (TS_CAL_2 - TS_CAL_1) ) + 30 uses TWO calibration points, at 30° and 110°, and is more correct. Note that also method 1 can use two calibration points (used to calculate average slope). Also, method 2 would let you to take your calibration points anywhere (presumably, in the range where you are more interested in).

    Both the methods, however, suffer from non-linearity (if any) of the sensor. I suppose that some non-linearity is present, because method 1 tells about "average slope". If you want greater precision, you can take several calibration points and interpolate between them.