cancel
Showing results for 
Search instead for 
Did you mean: 

Issue in readings of internal Temperature Sensor

himasagar reddy
Associate II
Posted on February 23, 2018 at 14:03

Hi Guys,

am using STM32f429, trying to read internal temperature sensor which is configured to ADC1  ADC_CHANNEL_18,

am able to read temperature readings,but  my device is giving 70 deg/C .

am not able to find why the  device is giving temperature that much high, following is the code which am using,

#define ADC_CHANNEL_DIFFERENCIATION_TEMPSENSOR_VBAT 0x10000000U

#define ADC_CHANNEL_TEMPSENSOR  ((uint32_t)ADC_CHANNEL_18 |ADC_CHANNEL_DIFFERENCIATION_TEMPSENSOR_VBAT)

#define ADC_CHANNEL_VREFINT ((uint32_t)ADC_CHANNEL_17)

#define ADC_CHANNEL_VBAT ((uint32_t)ADC_CHANNEL_18)

void TempINIT(void){

ADC_ChannelConfTypeDef sConfig;

AdcHandle.Instance = ADC1;

AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;

AdcHandle.Init.Resolution = ADC_RESOLUTION12b;

AdcHandle.Init.ScanConvMode = DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */

AdcHandle.Init.ContinuousConvMode = DISABLE; /* Continuous mode disabled to have only 1 conversion at each conversion trig */

AdcHandle.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */

//AdcHandle.Init.NbrOfDiscConversion = 0;

AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Conversion start trigged at each external event */

AdcHandle.Init.ExternalTrigConv = ADC_SOFTWARE_START;//ADC_EXTERNALTRIGCONV_T1_CC1;

AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;

AdcHandle.Init.NbrOfConversion = 1;

AdcHandle.Init.DMAContinuousRequests = DISABLE;

AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

if (HAL_ADC_Init(&AdcHandle) != HAL_OK)

{

/* ADC initialization Error */

Error_Handler();

}

/*##-2- Configure ADC regular channel ######################################*/

sConfig.Channel = ADC_CHANNEL_TEMPSENSOR ;

sConfig.Rank = 1;

sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;

if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK)

{

/* Channel Configuration Error */

Error_Handler();

}

ADC->CCR &= ~ADC_CCR_VBATE;

}

uint8_t GetTempValue(float *TempValue_degC) {

unsigned short int count;

uint32_t Adc_Value =0;

uint32_t Adc_Value2 =0;

float vsense=0;

float samples =0;

float Temp;

TempINIT();

for(count=0;count<20;count++) {

HAL_ADC_Start(&AdcHandle);

if (HAL_ADC_PollForConversion(&AdcHandle, 1) == HAL_OK) {

Adc_Value = (uint16_t)HAL_ADC_GetValue(&AdcHandle);

Adc_Value2 =Adc_Value;

samples+=Adc_Value;

}

else {

Adc_Value = 0;

return ERROR;

}

HAL_ADC_Stop(&AdcHandle);

}

samples = samples/20;

vsense = ((samples)*(3300))/4096;

Temp = (((vsense) - (760))/(2.5)) + 25;

*TempValue_degC = Temp;

Adc_Value = 0;

samples = 0;

return SUCCESS;

}

/**

Thanks In Advance

with regards,

Himasagar.

1 REPLY 1
Posted on February 27, 2018 at 02:37

sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;

I don't think this is enough - look into the datasheet for sampling time requirement for the temperature sensor.

Also note, that the internal temperature will be higher than the surface temperature of the chip, especially if it runs at the maximum supply voltage (is VDD really 3.3V?) and maximum system clock. Some 30 degrees difference between surface and chip is not surprising at all.

JW