cancel
Showing results for 
Search instead for 
Did you mean: 

ADC temperature dependence. Broken or defective?

OMaks.1
Associate

Our company has developed a thermostat based on a microcontroller STM8L151K4T6. Many thermostats from the manufacturer were rejected. The analysis showed that the microcontroller does not correctly measure the voltage at the external terminals. The measured voltage is highly dependent on the temperature of the microcontroller.

For example: + 20С - ADC_DR = 0x07A6, and +50C - ADC_DR = 0x0600 (at supply voltage 3.2В).

A change in temperature has almost no effect on the measurement of the internal voltage reference.

After replacing the microcontroller with a new one everything comes back to normal and the temperature does not affect the measurement.

Init

/* High speed internal clock prescaler: 1 */

 CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);

 /* Select HSE as system clock source */

 CLK_SYSCLKSourceSwitchCmd(ENABLE);

 CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);

  

 CLK_LSEConfig(CLK_LSE_ON);

 /* Wait for LSE clock to be ready */

 while (CLK_GetFlagStatus(CLK_FLAG_LSERDY) == RESET);

 /* wait for 1 second for the LSE Stabilisation */

 LSE_StabTime();

  

 /* Select LSE (32.768 KHz) as RTC clock source */

 CLK_RTCClockConfig(CLK_RTCCLKSource_LSE, CLK_RTCCLKDiv_1);

void init_ADC(void)

{

 CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);  

 ADC_DeInit(ADC1);

 ADC_Cmd(ADC1, ENABLE);

 ADC_Init(ADC1, ADC_ConversionMode_Single, ADC_Resolution_12Bit, ADC_Prescaler_2);

 ADC_DMACmd(ADC1, DISABLE);

 CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, DISABLE);

 ADC_VrefintCmd(ENABLE);

 ADC_TempSensorCmd(DISABLE);   

 ADC_SchmittTriggerConfig(ADC1, ADC_Channel_0, DISABLE);

 ADC_SchmittTriggerConfig(ADC1, ADC_Channel_1, DISABLE);

 ADC_SchmittTriggerConfig(ADC1, ADC_Channel_2, DISABLE);

 ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);

 ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_96Cycles);

 ADC_SamplingTimeConfig(ADC1, ADC_Group_FastChannels, ADC_SamplingTime_96Cycles); 

 ADC_AnalogWatchdogConfig(ADC1, ADC_AnalogWatchdogSelection_Vrefint, ((uint16_t)(((unsigned long int) 3000)*(0x600 + Factory_VREFINT)/U_CPU_POWER_MIN)), (uint16_t)1305); 

 return;

}

3 REPLIES 3
WilkoL
Senior

When you say that replacing the microcontroller fixes the problem, it makes me think that the other one was defective. But I don't quite understand the code. It seems to be missing the enabling of the channels, this is how I have two channels and the VREFINT and TEMPERATURE sensor working (with DMA)

static void ADC_config(void)
{
	CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
	
	GPIO_Init(GPIOB, GPIO_Pin_7, GPIO_Mode_In_FL_No_IT);		//floating input
	GPIO_Init(GPIOB, GPIO_Pin_6, GPIO_Mode_In_FL_No_IT);		//floating input
	
	ADC_DeInit(ADC1); 
	
	ADC_Init(ADC1, ADC_ConversionMode_Single, ADC_Resolution_12Bit, ADC_Prescaler_2);
	ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_192Cycles);
	ADC_SamplingTimeConfig(ADC1, ADC_Group_FastChannels, ADC_SamplingTime_192Cycles);
 
	ADC_SchmittTriggerConfig(ADC1, ADC_Channel_11, DISABLE);
	ADC_SchmittTriggerConfig(ADC1, ADC_Channel_12, DISABLE);
	
	ADC_TempSensorCmd(ENABLE);
	ADC_VrefintCmd(ENABLE);
 
	ADC_ChannelCmd(ADC1, ADC_Channel_11, ENABLE);
	ADC_ChannelCmd(ADC1, ADC_Channel_12, ENABLE);
	ADC_ChannelCmd(ADC1, ADC_Channel_Vrefint, ENABLE);
	ADC_ChannelCmd(ADC1, ADC_Channel_TempSensor, ENABLE);
 
	ADC_DMACmd(ADC1, ENABLE);
	ADC_Cmd(ADC1, ENABLE);
}
 
 
 
static void DMA_Config(void)
{
	CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, ENABLE);
  
	SYSCFG_REMAPDMAChannelConfig(REMAP_DMA1Channel_ADC1ToChannel0);	
 
	DMA_Init(DMA1_Channel0, 
		adc1_buffer_address,
		adc1_data_register,
		ADC_BUFFER_SIZE,
		DMA_DIR_PeripheralToMemory,
		DMA_Mode_Normal,
		DMA_MemoryIncMode_Inc,
		DMA_Priority_High,
		DMA_MemoryDataSize_HalfWord);
 
	DMA_ClearITPendingBit(DMA1_IT_TC0);	
	DMA_ITConfig(DMA1_Channel0, DMA_ITx_TC, ENABLE);
	DMA_Cmd(DMA1_Channel0, ENABLE);
	DMA_GlobalCmd(ENABLE);
}

OMaks.1
Associate

Functions GPIO_Init I have above.

This defect has already appeared on 14 pieces out of 50 pieces.

WilkoL
Senior

GPIO functions are one thing, enabling the ADC-Channels is another. I meant things like these:

ADC_ChannelCmd(ADC1, ADC_Channel_11, ENABLE);

Where did you buy those microcontrollers? In the past I have bought some STM32 controllers via Ebay, they were all either used parts of simply fake. Now I only buy via Farnell and Mouser and I haven't had a problem since. If you have bought them from a reputable source, complain with them, no doubt they will replace them.