Skip to main content
EPopr
Associate
May 23, 2019
Solved

STM32L011 Temperature sensor calibration (Possible bug in library)

  • May 23, 2019
  • 10 replies
  • 4918 views

Hi all,

I am trying to use internal temperature sensor on Nucleo L011K4 and using macro from LL library (__LL_ADC_CALC_TEMPERATURE_TYP_PARAMS) I get complete garbage.

STM32Cube_FW_L0_V1.11.2

STM32CubeMx 5.0.1

LL libraries used, no HAL

ADC is running in DMA mode with HW oversampling by 8, 12.5 clock S&H time (should be enough for TEMP sensor) and each ADC EOS this value again averaged in SW.

When I looked closely to datasheet and reference manual I wrote my code without this macro and I still getting nonsense data out of it. I found that TS_CAL2 value from Factory Option bytes is far different than expected value, so when I used 670 constant instead - and I got something real temperature finally.

Question 1: why at production calibration value is like 1.5 times bigger than supposed to be?

Question 2: Is there a bug in LL macro? It looks like there one unnecessary multiply by 1000

Question 3: Do I need to recalibrate temp sensor at 130C or can use different temperature?

Question 4: Can I store calibration value in option bytes and how?

Question 5: Is TS_CAL1 value can be used if I calibrate it by myself? I want measure temperature using 2 points calibration.

This topic has been closed for replies.
Best answer by Alex R

TS_CAL2 = 0x3A2 = 930decimal

As per the datasheet, Section 6.3.16, the temperature sensor is calibrated using Vdd=3V.

With the 12-bit ADC (4096 ADC counts), the equivalent millivolts would be: (3V / 4096)*930 = 0.6811mV

That this the mV measurement at 130C.

What is the value of TS_CAL1?

10 replies

Alex R
Associate II
May 23, 2019

Note that TS_CAL2 is the raw ADC data values, with VDDA=3V, and not volts (or millivolts, as the constant 670 seem to indicate)

If you have a different VDDA voltage than 3V, then you need to scale the ADC measurements accordingly.

Did you check the example code in the Reference Manual Section A.8.17?

Do you need absolute or relative temperature measurements?

You can do your own calibration, and store the calibration values in the Flash Memory. It would be different locations that the TS_CAL1 and TS_CAL2 (you would need to define your own locations). Note, however, that this may be a very time-consuming process, as you need to make sure that the chip reaches the desired temperature for each measurement, and you would need to calibrate every single unit during manufacturing.

EPopr
EPoprAuthor
Associate
May 24, 2019

Looks like you are right regarding TS_CAL2 unit. I will try that.

Is TS_CAL values not writable?

I have a background in characterization to calibrate temperature sensor.

Alex R
Associate II
May 24, 2019

I believe TS_CALx are not writable, The Reference Manual indicates that they are in the "system memory".

However, if you are using your own calibration, then you can use the regular Flash to store the calibration values.

raptorhal2
Lead
May 23, 2019

Calibrate at each power on at the usage temperature.

See the data sheet normal operating conditions section for the temperature sensor.

Did you allow for the 10 usec startup time?

The minimum sampling time for accuracy is 10 usec. 12.5 clocks are not not enough.

Cheers, Hal

EPopr
EPoprAuthor
Associate
May 24, 2019

I think there is quite some time for startup, I have a long boot sequence.

I understand that temperature sensor need long sampling time, I have 16Mhz ADC frequency and 16 divider, so with 12.5 clokcs for S&H it should be 12.5us sampling time.