cancel
Showing results for 
Search instead for 
Did you mean: 

using TS_CAL1 value on STM32C011 seems to make calculated temp less accurate

danmcb
Associate III

I'm using the internal temp sensor on a C011 chip *actually the STM32C0116 dev board) and trying to  get an approximate reading in C, using __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS macro.

I understand that this won't be very accurate, but it seems that when I use the T_CAL1 value stored in ROM the result actually gets significantly worse. Here is my code:

#define VDDA_APPLI                     ((uint32_t) 3300)
#define TEMPSENSOR_TYP_CAL1_V          (( int32_t)  760)
#define TEMPSENSOR_TYP_AVGSLOPE        (( int32_t) 2530)
#define TEMPSENSOR_CAL_VREF            ((uint32_t) 3000)


int32_t get_last_temp_reading(void)
{
	uint16_t t_cal1 = *TEMPSENSOR_CAL1_ADDR;
 return (int32_t)__LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(TEMPSENSOR_TYP_AVGSLOPE,
         //TEMPSENSOR_TYP_CAL1_V,
		 t_cal1,
         TEMPSENSOR_CAL1_TEMP,
         VDDA_APPLI,
		 raw_value,
         LL_ADC_RESOLUTION_12B);
}

 

My raw_value is 787. When I use the typical datasheet value of 760, I get a result of -20. If I use t_cal1 (which has a value of 1048) I get -134

What is going on? OK, I don't expect much accuracy, but using the internal cal value should at least make things better not worse?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
danmcb
Associate III

indeed, I think sampling time was the issue. I went back into CubdeMX, slowed down the ARC clock and the sampling setting to about 10us, and now I get results of about 70 degrees, which are believable.

I still cannot make sense of the supplied macro in the library, but if I do it myself, I get these numbers now.

Thanks very much for your help.

View solution in original post

6 REPLIES 6
RobK1
Associate III

What temperature are you expecting to see?

 

The t_cal1 value is an ADC reading, not the value in mV. Multiply by 3000, the divide by 4096 to get the voltage.

danmcb
Associate III

I expect to see somewhere near ambient - 25 to 30.

I am just plugging numbers into the macro. In all honesty I spent a good hour trying to relate the macro to the datasheet without success. it is not even clear to me what reference is used internally for the temp sensor.

danmcb
Associate III

using the datasheet and trying to do it manually (screenshot below):

 

Avg Slope Code = 2.53 x 4096/3000 = 3.45

sense data = 787 x 3.3 / 3 = 866

TS_CAL_1 = 1048

 

Temp = ((866 - 1048) / 3.45) + 30 = -23

 

I am just putting the numbers into the equation, exactly as described, so something is incomplete or unclear here.

 

 

stm32_temp.jpg

 

RobK1
Associate III

Well, the 787 you quote as raw value does indeed correspond to -20°C, according to the calculations given in the manual. Using the t_cal1 value it's -22.8

I would expect to see an ADC count of around 1030 at 25°C

 

  • Are you meeting the required minimum sampling time of 5µs?
  • Are you meeting the required start-up times given in the datasheet?

In addition to these:

  • Are you calibrating the ADC on startup, before it is used?
If you feel a post has answered your question, please click "Accept as Solution".
danmcb
Associate III

indeed, I think sampling time was the issue. I went back into CubdeMX, slowed down the ARC clock and the sampling setting to about 10us, and now I get results of about 70 degrees, which are believable.

I still cannot make sense of the supplied macro in the library, but if I do it myself, I get these numbers now.

Thanks very much for your help.