cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L011K4T - MCU ADC Temperature

Nolan L
Associate III
Posted on February 06, 2018 at 01:23

Hi,

I would like someone to confirm that the temperature I am getting is somewhat in the ballpark to be expected. If it isn't, could someone check my values that I am using from the datasheet?

I am currently getting 11 C which seems low for ambient room temperature.I know that the ADC internal temperature measures junction temperature. I expected +/- 5 C swing, not -14 C.

I can also confirm my ADC is working with DMA as I am using it to read internal voltage and various other analog measurements.

For this particular micocontroller, the values are taken off the datasheet and are designed to spec:

0690X00000609cnQAA.png

I am usingthelow level driver function to determine temperature:

/**
 * @brief Helper macro to calculate the temperature (unit: degree Celsius)
 * from ADC conversion data of internal temperature sensor.
 * @note Computation is using temperature sensor typical values
 * (refer to device datasheet).
 * @note Calculation formula:
 * Temperature = (TS_TYP_CALx_VOLT(uV) - TS_ADC_DATA * Conversion_uV)
 * / Avg_Slope + CALx_TEMP
 * with TS_ADC_DATA = temperature sensor raw data measured by ADC
 * (unit: digital value)
 * Avg_Slope = temperature sensor slope
 * (unit: uV/Degree Celsius)
 * TS_TYP_CALx_VOLT = temperature sensor digital value at
 * temperature CALx_TEMP (unit: mV)
 * Caution: Calculation relevancy under reserve the temperature sensor
 * of the current device has characteristics in line with
 * datasheet typical values.
 * If temperature sensor calibration values are available on
 * on this device (presence of macro __LL_ADC_CALC_TEMPERATURE()),
 * temperature calculation will be more accurate using
 * helper macro @ref __LL_ADC_CALC_TEMPERATURE().
 * @note As calculation input, the analog reference voltage (Vref+) must be
 * defined as it impacts the ADC LSB equivalent voltage.
 * @note Analog reference voltage (Vref+) must be either known from
 * user board environment or can be calculated using ADC measurement
 * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
 * @note ADC measurement data must correspond to a resolution of 12bits
 * (full scale digital value 4095). If not the case, the data must be
 * preliminarily rescaled to an equivalent resolution of 12 bits.
 * @param __TEMPSENSOR_TYP_AVGSLOPE__ Device datasheet data: Temperature sensor slope typical value (unit: uV/DegCelsius).
 * On STM32L0, refer to device datasheet parameter ''Avg_Slope''.
 * @param __TEMPSENSOR_TYP_CALX_V__ Device datasheet data: Temperature sensor voltage typical value (at temperature and Vref+ defined in parameters below) (unit: mV).
 * On STM32L0, refer to device datasheet parameter ''V130'' (corresponding to TS_CAL2).
 * @param __TEMPSENSOR_CALX_TEMP__ Device datasheet data: Temperature at which temperature sensor voltage (see parameter above) is corresponding (unit: mV)
 * @param __VREFANALOG_VOLTAGE__ Analog voltage reference (Vref+) voltage (unit: mV)
 * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal temperature sensor (unit: digital value).
 * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature sensor voltage has been measured.
 * This parameter can be one of the following values:
 * @arg @ref LL_ADC_RESOLUTION_12B
 * @arg @ref LL_ADC_RESOLUTION_10B
 * @arg @ref LL_ADC_RESOLUTION_8B
 * @arg @ref LL_ADC_RESOLUTION_6B
 * @retval Temperature (unit: degree Celsius)
 */
#define __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(__TEMPSENSOR_TYP_AVGSLOPE__,\
 __TEMPSENSOR_TYP_CALX_V__,\
 __TEMPSENSOR_CALX_TEMP__,\
 __VREFANALOG_VOLTAGE__,\
 __TEMPSENSOR_ADC_DATA__,\
 __ADC_RESOLUTION__) \
 ((( ( \
 (int32_t)((((__TEMPSENSOR_ADC_DATA__) * (__VREFANALOG_VOLTAGE__)) \
 / __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__)) \
 * 1000) \
 - \
 (int32_t)(((__TEMPSENSOR_TYP_CALX_V__)) \
 * 1000) \
 ) \
 ) / (__TEMPSENSOR_TYP_AVGSLOPE__) \
 ) + (__TEMPSENSOR_CALX_TEMP__) \
 )
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

My Code:

// Values derived from datasheet STM32L011x4
#define ADC_TEMP_AVG_SLOPE 1610
#define ADC_TEMP_TYP_CALX_V 670
#define ADC_TEMP_TYP_CALX_TEMP 130
#define ADC_TEMP_REF_VOLTAGE 3300
int16_t adc_get_temperature_internal(void)
{
 // Get Active Buffer (Opposite End of What the DMA is Filling) 
 // Covert Values Into a Voltage.
 if(adc_active_buffer)
 {
 return __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(ADC_TEMP_AVG_SLOPE,
 ADC_TEMP_TYP_CALX_V,
 ADC_TEMP_TYP_CALX_TEMP,
 ADC_TEMP_REF_VOLTAGE,
 data[ADC_DMA_LOWER_TEMPERATURE_INTERNAL],
 LL_ADC_RESOLUTION_12B);
 }
 else
 {
 return __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(ADC_TEMP_AVG_SLOPE,
 ADC_TEMP_TYP_CALX_V,
 ADC_TEMP_TYP_CALX_TEMP,
 ADC_TEMP_REF_VOLTAGE,
 data[ADC_DMA_UPPER_TEMPERATURE_INTERNAL],
 LL_ADC_RESOLUTION_12B);
 }
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Thanks!

4 REPLIES 4
martin.a
Associate

​Hi!

Sorry to bother you after so long, but were you able to resolve this issue?

I have run into the same problem myself, and I'm looking for solutions.

Thanks and with best regards,

Martin

S.Ma
Principal

There have been many post about ADC for Vref/Vbat/Temp.

I think there are code examples in Nucleo library.

Otherwise, ADC calibration must be performed, VDDA vs MCUVdd must be checked (is it 3V?), and remember that what is measured is the silicon temperature. If the chip is "hot" the temp will be higher than ambient.

martin.a
Associate

​Hi KIC8462852 EPIC204278916,

Thanks for your fast reply!

"There have been many post about ADC for Vref/Vbat/Temp.

I think there are code examples in Nucleo library."

I agree, but sadly I couldn't find an example which calculates the absolute temperature based on the factory calibration for the STM32L011F4. This µC does not use the typical two step calibration values.

Otherwise, ADC calibration must be performed, VDDA vs MCUVdd must be checked (is it 3V?), and remember that what is measured is the silicon temperature. If the chip is "hot" the temp will be higher than ambient.

Thank you for the good hints. ADC calibration is already included and executed before my application starts. I am also calling the macro function mentioned above, which to my understanding should also compensate for the different supply voltage (3.3V instead of 3V used for calibration).

As you also mentioned, the die temperature of the chip will be measured, therefore I would expect it to be always above the ambient temperature.

Rpatt.1
Associate

I was having a similar issue. Trying to read ADC temperature on a STM32L011k4 using the  __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS function and getting some strange values.

To fix it, I had to do 2 things:

  1. Make sure you are sampling the ADC for a minimum of 10 microseconds. You can adjust ADC Clock Prescaler and Sampling Time to this end.
  2. After the MX_ADC_Init() but before reading from the ADC, perform calibration like this:

  LL_ADC_StartCalibration(ADC1);

 while (LL_ADC_IsCalibrationOnGoing(ADC1) != 0);