cancel
Showing results for 
Search instead for 
Did you mean: 

ADC accuracy after STOP2 wakeup

npatil15
Associate III

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

 

 

0 REPLIES 0