cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G474: ADC Offset Compensation really not possible with Hardware Oversampling?

TwelveSquared
Senior

Regarding the ADC, with Gain Compensation, Offset, and Hardware Oversampling:

Reference manual (RM0440 Rev 5) page 647 and also page 664 say:

"Offset correction is not supported in oversampling mode. When ROVSE and/or JOVSE bit is set, the value of the OFFSETy_EN bit in ADC_OFRy register is ignored (considered as reset)."

However, by mistake I programmed oversampling x256 mode together with gain and offset, and I think the offset is being applied in hardware, even though Reference Manual says it is not supported.

Is this mistake in the Reference Manual?

More details: I am initializing ADC5 like this:

	/* Configure ADC */
	hadc5.Instance = ADC5;
	hadc5.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
	hadc5.Init.Resolution = ADC_RESOLUTION_12B;
	hadc5.Init.DataAlign = ADC_DATAALIGN_RIGHT;
	hadc5.Init.GainCompensation = (uint32_t) GainParam;
	hadc5.Init.ScanConvMode = ADC_SCAN_DISABLE;
	hadc5.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
	hadc5.Init.LowPowerAutoWait = DISABLE;
	hadc5.Init.ContinuousConvMode = DISABLE;
	hadc5.Init.NbrOfConversion = 1;
	hadc5.Init.DiscontinuousConvMode = DISABLE;
	hadc5.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T6_TRGO;
	hadc5.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
	hadc5.Init.DMAContinuousRequests = ENABLE;
	hadc5.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
	hadc5.Init.OversamplingMode = ENABLE;
	hadc5.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256;
	hadc5.Init.Oversampling.RightBitShift = LL_ADC_OVS_SHIFT_RIGHT_8;
	hadc5.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
	hadc5.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE;
	if (HAL_ADC_Init(&hadc5) != HAL_OK) {
		...
	}
 
	/* Configure Regular Channel */
	sConfig.Channel = ADC_CHANNEL_TEMPSENSOR_ADC5;
	sConfig.Rank = ADC_REGULAR_RANK_1;
	sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5;
	sConfig.SingleDiff = ADC_SINGLE_ENDED;
	sConfig.OffsetNumber = ADC_OFFSET_1;
	sConfig.Offset = (uint32_t) OffsetParam;
	sConfig.OffsetSign = ADC_OFFSET_SIGN_NEGATIVE;
	sConfig.OffsetSaturation = DISABLE;
	if (HAL_ADC_ConfigChannel(&hadc5, &sConfig) != HAL_OK) {
		...
	}
 
	if (HAL_ADCEx_Calibration_Start(&hadc5, ADC_SINGLE_ENDED) != HAL_OK) {
		...
	}

1 REPLY 1

> I think

Don't think: try.

Was the offset applied to individual measurements, to the sum, or to the shifted result? You can distinguish these cases by setting the final shift to a different value than log2 of oversampling ratio.

It may be a problematic feature, e.g. causing overflows at corner cases.

JW