Skip to main content
New.Fish
Associate III
November 10, 2022
Solved

STM32 ADC 16bits resolution

  • November 10, 2022
  • 4 replies
  • 9172 views

STM32 MCU has 12 bits ADC resolution, but some MCU claim "up to 16-bit with hardware oversampling". When I setup ADC in STMCubeMX, no option for "hardware oversampling", how to achieve 16-bit ADC resolution?

This topic has been closed for replies.
Best answer by LCE

If it's in the hardware, then it's probably described in the reference manual.

You shouldn't trust Cube anyway.

And my experience: as soon as you're really working (and not just "playing around") with the STM32, you need some deeper understanding, which means you should do lots of register reads and writes directly, and Cube and HAL functions mostly only serve as some setup, or a base for finding out what's going on.

4 replies

S.Ma
Principal
November 10, 2022

True for a specific subset of newer STM32 parts.... check the STM32G4 or U5 first.

New.Fish
New.FishAuthor
Associate III
November 10, 2022

From the STM32Cube, I can find several STM32 family MCU have this feature, such as: STMG0, G4....

My question is how to setup "hardware oversampling"?

LCE
LCEAnswer
Principal II
November 10, 2022

If it's in the hardware, then it's probably described in the reference manual.

You shouldn't trust Cube anyway.

And my experience: as soon as you're really working (and not just "playing around") with the STM32, you need some deeper understanding, which means you should do lots of register reads and writes directly, and Cube and HAL functions mostly only serve as some setup, or a base for finding out what's going on.

AScha.3
Super User
November 10, 2022

+ some have 16 b converters... i have here stm32H743 ->

0693W00000WHyQQQA1.png

"If you feel a post has answered your question, please click ""Accept as Solution""."
Piranha
Principal III
November 11, 2022

Just for an information... There has been reports saying "it's just noise", but I can not agree. I'm capturing a good quality signal on L43x with it's 12-bit ADC in 256x oversampling mode and a 16-bit output. And, by analyzing the captured values, I can see that the noise is just a few LSB, which means the effective resolution is pretty close to 16-bit.

New.Fish
New.FishAuthor
Associate III
November 11, 2022

Hi Piranha,

It's nice to hear your experience, this is what exactly I want to know.

Two questions:

  1. You setup the A/D setting manually or by STMCube?
  2. 256X oversampling, that means sampling 256 times for each conversion, that will slow down the sample rate, how much is the final sample rate?

Regards

Sam

Piranha
Principal III
November 15, 2022

I'm not using HAL/Cube broken bloatware at all.

Of, course, oversampling slows down the whole conversion, but it still significantly depends on a sampling time:

Fadcclk / (Tsmpl + Tsar) / 256

80 MHz / (2,5 + 12,5) / 256 = 20833 Hz

80 MHz / (640,5 + 12,5) / 256 = 478 Hz

For my particular project even the slowest one is fine, because that device samples with an even lower frequency anyway.

raptorhal2
Lead
November 11, 2022

(Edited)

The configuration is done in the ADC handle initialization. Here is an L4 example:

/* Configuration of ADC Oversampling. Available for L4 Series

   * Oversample Ratios are 2,4,8,16,32,64,128,256 */

 AdcHandle.Init.Oversampling.Ratio   = ADC_OVERSAMPLING_RATIO_256;

 /* Right shift sample sums are 0 to 8 */

 AdcHandle.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_4;