Array
(
    [content] => 
    [params] => Array
        (
            [0] => /forum/index.php?threads/hwo-do-i-add-up-analogue-inputs-to-average-them.13893/
        )

    [addOns] => Array
        (
            [DL6/MLTP] => 13
            [Hampel/TimeZoneDebug] => 1000070
            [SV/ChangePostDate] => 2010200
            [SemiWiki/Newsletter] => 1000010
            [SemiWiki/WPMenu] => 1000010
            [SemiWiki/XPressExtend] => 1000010
            [ThemeHouse/XLink] => 1000970
            [ThemeHouse/XPress] => 1010570
            [XF] => 2021270
            [XFI] => 1050270
        )

    [wordpress] => /var/www/html
)

Hwo Do I add up analogue inputs to average them?

Eva713

Member
Hi,
I would like to read a sensor (acs712) a number of times (20), add them all up, then divide them by the number of reads. So I can get an average. to give me a sort of analogue "debounce". Am I guessing the sum function?

I sincerely appreciate any advice you can all give me, I'm incredibly excited about learning all of this!
 

Daniel Payne

Moderator
Does your system have and A2D converter for the sensor? If so, then you have 20 digital values that can be averaged by a MCU, CPU or GPU.
 

Eva713

Member
Using a microcontroller, this will average packets of 20 values each. Another is a moving average (or rolling average), which will give an output for every input, also averaged over e.g. 20 values. Is that right?
 

fliptron

New member
Hi Eva, there are many ways to average a signal, which will meet your reduce the amount of bouncing around, but also limit the ability to accurately measure short duration spikes. If you want to stay with a non-microprocessor solution, the data sheet shows that the ACS712 has a filter pin (6), and you can just add a capacitor to this pin to adjust bandwidth and noise. If you are going to be reading the sensor with a microprocessor anyway as part of your design, you can just add up the analog-to-digital (ADC) values of 20 samples, and then divide by 20. If you do this, remember that when you add values like this the number gets bigger and the variable that holds the sum must be big enough. For example, if the ADC is a 12 bit one, the maximum value is 4095. 20 * 4095 is 81900. This is too big to hold in a 16 bit variable.
Moving/rolling averages is another approach and gives results more often, but needs more calculations (usually). You might find that https://www.eevblog.com/forum/index.php is a better place to have this discussion.
 
Top