2019-10-15 01:54 AM
hello everyone i am using stm32h7 MCU, i want averaged ADC data using hardware over sampling. how can get this.
Solved! Go to Solution.
2019-10-24 02:23 AM
Hello @RShar.9 ,
The example ADC_OverSampler available in the STM32CubeH7 package will help you to configure and use the ADC to convert an external
analog input combined with oversampling feature:
STM32Cube_FW_H7_V1.5.0\Projects\STM32H743I-EVAL\Examples\ADC\ADC_OverSampler
hadc1.Init.OversamplingMode = ENABLE; /* Oversampling enabled */
hadc1.Init.Oversampling.Ratio = 3; /* Oversampling ratio */
hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_2; /* Right shift of the oversampled summation */
hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER; /* Specifies whether or not a trigger is needed for each sample */
hadc1.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE; /* Specifies whether or not the oversampling buffer is maintained during injection sequence */
hadc1.Init.Oversampling.Ratio = 1; /* Oversampling ratio */
hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_1; /* Right shift of the oversampled summation */
Hope this helps you.
Best Regards,
Imen
2019-10-24 02:23 AM
Hello @RShar.9 ,
The example ADC_OverSampler available in the STM32CubeH7 package will help you to configure and use the ADC to convert an external
analog input combined with oversampling feature:
STM32Cube_FW_H7_V1.5.0\Projects\STM32H743I-EVAL\Examples\ADC\ADC_OverSampler
hadc1.Init.OversamplingMode = ENABLE; /* Oversampling enabled */
hadc1.Init.Oversampling.Ratio = 3; /* Oversampling ratio */
hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_2; /* Right shift of the oversampled summation */
hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER; /* Specifies whether or not a trigger is needed for each sample */
hadc1.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE; /* Specifies whether or not the oversampling buffer is maintained during injection sequence */
hadc1.Init.Oversampling.Ratio = 1; /* Oversampling ratio */
hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_1; /* Right shift of the oversampled summation */
Hope this helps you.
Best Regards,
Imen
2019-10-30 03:36 AM
hii
thanks for your reply.
i have questions.'
i am using dma in adc. will i get averaged data in dma buffer?
can you please tell me what are features of hardware oversampling in stm32h7, i never used it in any other MCU.
Actually my ADC signal is very noisy , how can filter it.
2019-10-30 03:57 AM
Hi @RShar.9 ,
1. 2. Yes
The output of ADC Data register will contain the average of the data. And it will be transferred by DMA.
So yes, your DMA buffer data has already the average data.
This is done purely in hardware without having the need to have a software for the averaging (less power consumption + less CPU load).
You can add an RC low pass filter before your ADC input in order to filter noise + use oversampling.
To remove noise, you can use differential mode , but this require that your input signal is fully differential.
Regards,
Imen
2019-10-30 04:41 AM
Thanks..
2019-10-30 06:04 AM
hadc1.Init.Oversampling.Ratio = 1; /* Oversampling ratio */
what is the purpose of over sampling ratio to set 1 or 3 ?
2019-10-30 06:12 AM
when i saw in ADC_OverSampler example , i found that by that it will increase the resolution of adc data.
so that after get the 18 bit adc value i have to divide that by 4 to get actual 16 bit averaged adc data?
2024-04-18 02:33 PM - edited 2024-04-18 03:20 PM
Trying to understand the above post values?!
The docs state that Ratio values are 0 - 1023, setting the number of additional oversamples, per sample. 2x(Ratio=1),4x(Ratio=3),8x(=7),16x(=15),32x(..),64,128,256,512,1024,2048 which matches to -> ADC_RIGHTBITSHIFT_1 - ADC_RIGHTBITSHIFT_11
RightBitShift is the shift (division) required for averaging, binary, so stepping in power2, 1=div2,2=div4,etc, 11 values allowed, so max. us 2^11 = 2048, in this case 1024 samples per sample!
So Ratio cannot be any value from 1-1023, but 1, 3, 7, 15, etc. Is that correct?
Is this so obvious that the ST docs skipped mentioning it?
hadc1.Init.Oversampling.Ratio = 3; /* Oversampling 3x */ hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_2; /* Divide result by 4 to average? */
Shouldn't it be /* Oversampling 4x , not 3x */ :-
hadc1.Init.Oversampling.Ratio = 3; /* Oversampling 4x */
hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_2; /* Divide result by 4 to average */