2019-05-23 08:35 AM
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.
Solved! Go to Solution.
2019-05-27 06:54 AM
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?
2019-05-23 01:12 PM
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.
2019-05-23 01:17 PM
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
2019-05-24 12:25 AM
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.
2019-05-24 12:30 AM
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.
2019-05-24 06:46 AM
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.
2019-05-27 12:49 AM
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.
2019-05-27 06:54 AM
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?
2019-05-27 07:20 AM
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!
2019-05-27 02:05 PM
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.