cancel
Showing results for 
Search instead for 
Did you mean: 

ADC Oversampling issue with STM32G474RE

IJo.1
Associate III

Hi all,

I am currently trying to implement ADC Oversampling so I can get 16-bit resolution of ADC result rather than 12-bit.

the dual simultaneous mode is used for ADC, ADC1 and ADC2 conversion, and the following is my STM32CubeIDE Setup:

0693W00000JOXafQAH.png 

ADC1 Ch 6 and ADC2 Ch 7 are used for the application.

(The application is for a motor control, and two ADCs are used for sensing the phase current from Gate IC)

basically, it was fully functional with 12-bit ADC without ADC oversampling mode.

but I wanted a higher resolution of the result, by using 16 bit result, to get nicer conversion results.

So I set both ADC to 16x of oversampling ratio as above.

However, the result was quite weird. the motor controller was not stable and it seemed the AD conversion is not properly oversampled. 

Did I set something wrong?

I found following from its datasheet but quite not sure how it works.

0693W00000JOXjDQAX.png 

And if n is the number of conversions, and N is Oversampling ratio,

how N can be 256x? STM32G4 supports only 16 times of number of conversion.

Kinda mixed up..

or, is ADC oversampling not for the application I am trying to?

Please help me out!

Bests,

IJo

7 REPLIES 7
Uwe Bonnes
Principal III

The summation register can have 20 bits, but the result is only 16 bits. A shift can be applied, but has to be considered too.

yes i got 16 bits result, but it seemed not right.

is the cubeide setting correct?

looks only 16 times of single conversion..?

TDK
Guru

What's not right about the result? Be precise. We don't know what "quite weird" and "not right" mean. What value do you get when you connect it to a known voltage source?

Yes, "Oversampling ratio 16x" is the correct setting to do 16x oversampling.

If you feel a post has answered your question, please click "Accept as Solution".
IJo.1
Associate III

You are right. I am even not sure what I should ask. :( 

speaking of the setting, I am wodering if the number of conversion shouldnt 1 since the conversion results will be summed from the first (n=0) to the end(n = Number of conversion -1) and N should 16 if I want to get 16 bits result with the 16x oversampling ratio according to the equation above.

and also the ADCs are using only one channel each, ADC1 CH6 and ADC2 CH7, 

I wanted to get much nicer result than 12 bit ADC.

with this circumstance, can ADC Oversampling achieve it?

BTW, I always appriciate TDK :) 

best

IJo

Philippe Cherbonnel
ST Employee

hello,

The issue could also come from timing: is there enough time to perform 16 ADC conversions between each trigger ?

To ensure oversampling is working correctly and is the right time frame of your FW:

Can you try the oversampling configuration of averaging:

- keep you FW settings using conversion data of 12 bit resolution

- use the ADC configuration to have 12 bit resolution averaged data of 16 conversions:

 - ratio 16x

 - right shift 4

If it works, you can then debug the FW progressively:

ratio 16 with right shift 2 (equivalent resolution 14 bit)

ratio 16 with right shift 0 (equivalent resolution 16 bit)

About the comment "STM32G4 supports only 16 times of number of conversion": not sure to get it, this is a probably confusion with sequencer length (16 channels can be set in ADC group regular sequencer). Oversampling and sequencer are independent.

Best regards

Philippe

Hi Philippe!

thank you so much!

I am confused the naming, the number of conversion which can be set 1 to 16 in the cubeide configurator. you can find it in the image above.

Is Conversion(tn) in the equation above the conversion result of t0 to t(N-1)?

 where N is the nimber of conversion?

for example,

using ADC1 CH6, ADC CH7 with

dual regular simultaneous mode and

I set the number of conversion as 1, and the over sampling ratio as 16x, and the right shift as 0.

then according the equation, M will be 1,

and during the summation from n = 0 to 15,

Conversion(tn) will be the same result since the ADconversion is excuted only once? (Number of conversion is 1)

then the result will be just 16 times of the first sample result...

or just by setting up like above,

ADC conversion will automatically sample 16 times

like conversion(t1) = 1024

conversion(t2) = 1022

.

.

.

conversion(t15) = 1027

and return the summation of all conversion results?

I think I am confused somewhete you pointed..

speaking of the time frame, i tried the same thing you told, the time frame was okay and I got result.

but thing is, when I use 12 bit ADC without the oversampling works fine but it doesnt when 12 bit ADC(oversampling 16x, 4 bitshift) is used.

So I thought the oversampling is not implemented properly...

Bests

Ijo

Hello,

The oversampling returns one data (summation and shift of all conversion data), you don't have access to intermediate computation done by ADC peripheral.

In your setup, can you quantify the erroneous data versus expected data ? (proportional error ? offset error ? ratio x2 shift 1 has same error as ratio x4 shift 2 ? ... )

Some idea for debug:

You can run a known functional example from STM32G4 FW package (using with LL driver):

...\Firmware\Projects\NUCLEO-G474RE\Examples_LL\ADC\ADC_Oversampling_Init

Then, by customizing it or inserting it in your program, does it work ?

Best regards

Philippe