cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo-U575ZI-Q running the ADC_SingleConversion_TriggerSW_IT shows wrong ADC results as soon I activate oversampling ?!

TomNiederl
Associate

Init-Sequnece:

hadc1.Instance = ADC1;

 hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;

 hadc1.Init.Resolution = ADC_RESOLUTION_12B;

 hadc1.Init.GainCompensation = 0;

 hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;

 hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

 hadc1.Init.LowPowerAutoWait = DISABLE;

 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.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;

 hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;

 hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;

 hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;

 hadc1.Init.OversamplingMode = ENABLE;

 //hadc1.Init.OversamplingMode = DISABLE;

 hadc1.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_2;

 hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_1;

 hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;

 hadc1.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_RESUMED_MODE;

 if (HAL_ADC_Init(&hadc1) != HAL_OK)

 {

  Error_Handler();

 }

with 'hadc1.Init.OversamplingMode = DISABLE;' everything works as expected ..

2 REPLIES 2
TomNiederl
Associate

solution found:

this is bug in parameter defines in oversampling. Please find reported bug in Github will be fixed in next release.

https://github.com/STMicroelectronics/STM32CubeU5/issues/18

ADC1 oversampler is specific and there is no sampling ration step like 2,4,8,16....

But it's smoother 0,1,2,3,...

as a hot fix you can use direct access register

//SET_BIT(ADC1->CFGR2, ADC_CFGR2_ROVSE);

MODIFY_REG(ADC1->CFGR2, ADC_CFGR2_OVSR_Msk, ADC_CFGR2_OVSR_0); //Ratio 2

MODIFY_REG(ADC1->CFGR2, ADC_CFGR2_OVSR_Msk, ADC_CFGR2_OVSR_1|ADC_CFGR2_OVSR_0); //Ratio 4

STee.3
Associate II

Can you provide the whole solution. And explain more?