You are currently viewing SemiWiki as a guest which gives you limited access to the site. To view blog comments and experience other SemiWiki features you must be a registered member. Registration is fast, simple, and absolutely free so please, join our community today!
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!
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?
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.