2021-11-25 07:21 PM
I read the example code of ll adc single conversion in stm32cube g0 package, and I have a doubt in a particular section of code:
/* Run ADC self calibration */
LL_ADC_StartCalibration(ADC1);
/* Poll for ADC effectively calibrated */
#if (USE_TIMEOUT == 1)
Timeout = ADC_CALIBRATION_TIMEOUT_MS;
#endif /* USE_TIMEOUT */
while (LL_ADC_IsCalibrationOnGoing(ADC1) != 0)
{
#if (USE_TIMEOUT == 1)
/* Check Systick counter flag to decrement the time-out value */
if (LL_SYSTICK_IsActiveCounterFlag())
{
if(Timeout-- == 0)
{
/* Time-out occurred. Set LED to blinking mode */
LED_Blinking(LED_BLINK_ERROR);
}
}
#endif /* USE_TIMEOUT */
}
/* Restore ADC DMA transfer request after calibration */
LL_ADC_REG_SetDMATransfer(ADC1, backup_setting_adc_dma_transfer);
/* Delay between ADC end of calibration and ADC enable. */
/* Note: Variable divided by 2 to compensate partially */
/* CPU processing cycles (depends on compilation optimization). */
wait_loop_index = (ADC_DELAY_CALIB_ENABLE_CPU_CYCLES >> 1);
while(wait_loop_index != 0)
{
wait_loop_index--;
}
/* Enable ADC */
LL_ADC_Enable(ADC1);
The code show me that should be a wait state when calibration process is finished and before enabling the adc. There is no information in datasheet related to this process.
Is a mistake on the code wait for enabling the adc after a adc calibration, and if the answer is yes, how can calculate this time.
2021-12-08 02:37 AM
Hi @Community member ,
I checked in the reference manual RM0454 that ADEN cannot be set if ADCAL is nt equal to 0 (see ADEN bit description).
But this doesn't explain the insertion of the wait loop before enabling the ADC as there is the previous wait to clear the ADCAL bit.
So, I'll check with development team the reason for a second wait before enabling the ADC and will be back to you.
-Amel
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.
2021-12-26 07:32 AM
It might be a good idea to compare the example code shown above with the code of HAL_ADCEx_Calibration_Start() in the stm32g0xx_hal_adc_ex.c file. I see no such wait loop there and no comment about it.
PS. However I see something that I believe is wrong in the description of HAL_ADCEx_Calibration_Start. It is written "Calibration factor can be read after calibration, using function HAL_ADC_GetValue()". However that function return the result from the adc. I believe it should be the HAL_ADCEx_Calibration_GetValue function instead.
Edit: I tested more and discover that both of these functions return the same value directly after calibration. They are read from different registers. The following is written in Reference Manual: "The calibration factor can be read from bits 6:0 of ADC_DR or ADC_CALFACT
registers"
2023-06-12 06:19 AM
I just had to insert that delay in a project on STM32H723 (whereas it wasn't needed in another project, maybe due to different clock settings). Without it LL_ADC_IsActiveFlag_ADRDY(ADC3) would never go high.