cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L011 Temperature sensor calibration (Possible bug in library)

EPopr
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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?

View solution in original post

10 REPLIES 10
Alex R
Senior

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.

raptorhal2
Lead

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

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.

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.

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.

I got TS_CAL2 = 0x3A2. How to recalculate to mV required in macro? I am not sure that 3.3V reference was used for temperature sensor calibration.

I tried converting to mV assuming 3.3V reference was used and I got -28C. So it still looks to me like my calibration value is wrong.

 A.8.17 doesn't have any info that could help me.

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?

With 3V reference it makes much more sense!

For my L011 calibration is done for only one point, 130C. You solved this mystery, thanks a lot!

Last update, with 3V calib reference in mind I get 14C at room temp (23C or so). Can do nothing more, need to recalibrate it.