Skip to main content
Visitor II
October 15, 2019
Solved

How to do ADC averaging in STM32H7 MCU using hardware over sampling

  • October 15, 2019
  • 1 reply
  • 3760 views

hello everyone i am using stm32h7 MCU, i want averaged ADC data using  hardware over sampling. how can get this.

    This topic has been closed for replies.
    Best answer by Imen.D

    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

    • For Oversampling ratio x4, you can add this lines before calling HAL_ADC_Init
    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 */

    • For oversampling ratio x2, update these lines:
    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

    1 reply

    Imen.DAnswer
    Technical Moderator
    October 24, 2019

    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

    • For Oversampling ratio x4, you can add this lines before calling HAL_ADC_Init
    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 */

    • For oversampling ratio x2, update these lines:
    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

    RShar.9Author
    Visitor II
    October 30, 2019

    hii

    thanks for your reply.

    i have questions.'

    1. ratio x4 means, adc will give averaged of 4 adc data?
    2. ratio x2 means, adc will give averaged of 2 adc data?

    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.

    Technical Moderator
    October 30, 2019

    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