2025-06-29 9:59 PM
Hello,
I'm using LPTIMR1 to wake up from STOP2 mode and then use ADC to read battery voltage range from 10 - 15 V. The wakeup to use ADC is random as per user input (in seconds, minutes or hours).
static void MX_ADC1_Init(void)
{
ADC_ChannelConfTypeDef sConfig = {0};
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = ENABLE;
hadc1.Init.LowPowerAutoPowerOff = ENABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_79CYCLES_5;
hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_79CYCLES_5;
hadc1.Init.OversamplingMode = DISABLE;
hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_4;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
}
And once LPTIMR wakeup, I do this to re-init and re-calibrate ADC
ReInit_ADC1();
HAL_StatusTypeDef status = HAL_ADCEx_Calibration_Start(&hadc1);
if(status)
{
//Log error
}
HAL_ADC_Start_IT(&hadc1);And it works fine, no error.
It has accuracy of +-50v, sometimes it looks stable and then in between get (+-) spike of 50mv. I have already calibrate using lookup table, along with averaging or mean techniques.
1. Does it is mandatory to re-init ADC every time?
2. Does it have inbuild function to stable the result, as I need this accuracy to +-10mv
Give me any solution which has discussed or available to refer.
Thanks,
Nitin
2025-07-01 1:07 AM - edited 2025-07-01 1:07 AM
Hi @npatil15,
>>1. Does it is mandatory to re-init ADC every time?
Yes, the ADC is powered off in STOP2 mode (check table 22 in RM), however, re-calibration is not necessary unless the calibration factor is lost (e.g., due to ADC power-off or Standby mode)
>>Does it have inbuild function to stable the result, as I need this accuracy to +-10mv
You can try to implement an analog watchdog to monitor converted voltages and can generate interrupts when values fall outside programmed thresholds.
Could you specify if this is a custom board or not?
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.