Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to add up analogue inputs to average them?

Status
Not open for further replies.

Zoe313

New 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!
 
With no digital treatment?
 
To use a sum function you would need to store the readings with some digital processing.
If you want the the average without any digital processing, then you could use an analog low-pass filter, which gives a running average.
The lower the filter corner frequency, the longer the averaging time.
How long to take the 20 readings?
 
Having a little relevant google search, reveals there is more forum and tutorials covering this device with multiple measuring points.

Maybe there exist a device similar, but with multiple set of input/outputs ?

Otherwise, an analog mux/demux combined with some sort of blocking device, using relays to only let the signal current you monitor.
 
Why not simply read via a low-pass RC filter, or use the bandwidth setting pin on the device to slow down its response so it directly produces a time-averaged value?
 
Why not simply read via a low-pass RC filter, or use the bandwidth setting pin on the device to slow down its response so it directly produces a time-averaged value?
As I understand the OP, there are multiple current loops (sources), but only one IC, and OP need to select what current source to measure from.
 
As I understand the OP, there are multiple current loops (sources), but only one IC, and OP need to select what current source to measure from.
No.
He just wants to average multiple readings from one sensor.
 
Depending on the maths functions available in your software, dividing by 20 may be awkward if using assembler.

If that is the case, try adding just 16 samples and dividing by 16.
Dividing by 16 in assembler is easy, just shift the value to the right four times.

JimB
 
I can even provide an example of this in assembler to run on a PIC16F18446 if the OP is interested. This code averages the last 16 reading. It works by writing the readings into a ring buffer. The location that the next reading is written to is just incremented from the last one. when the end location is reached the next reading is written into the first location of the buffer. Actually each location is two bytes so the address pointer is incremented twice for each reading.

Les.
 
One way of having a sort of moving average with a lot less memory is this:-

Have an accumulator, which needs to have 4 more bits than the signal.
Each time there is a reading, divide the accumulator value by 16 and subtract that from the accumulator (leaving the accumulator at 15/16 of its value)
Add the new reading to the accumulator.

The accumulator will end up an average of 16 times the reading.

That will work with any divide, as long as the accumulator is large enough. Power of 2 divides are simple in assembly and there is only one accumulator needed.

This simulates a simple RC analog filter.
 
Components cost money, and take up PCB space - software is free and takes no space - and in this case is extremely trivial anyway. Many modern PIC's even do it in their hardware.
That's assuming he already has a micro in the system, which he has not stated.
 
software is free and takes no space
Because he now has to measure the voltage 16X faster he needs a faster ADC, and because the data takes 16x more "space" he needs a micro with more RAM, and because the math is more complicated he must upgrade to the next faster CPU, and that new CPU only cones in the next bigger package, and the code just ran off the end of PROM, and now none of it fits on the old PCB, and free is not free.

Maybe you are lucky and free really is free.

I like the RC idea but......
 
Whatever ZOE313 want to use he need something to Display the measurement.
The easyest would be an analog panel Meter with Pointer.
That needle is dampded so there should be no average.

With an digital Panalmeter there has to be a Low Pass filter inserted - Like said a few posts before.
Additional it had to be calibrated e.g. with Voltage dividers to show the real Values.

When the knowledge is present, I would use a Microcontroller too.
The measurement can be done by A/D Converter ( Most Microcontroller has them integrated ).
The averaging can be done by simply Additions.
And when make it clever with simple shift operations.

The measured Voltages must be computed to the real measuring values.
You can use the averaged results to feed the Computing of real values without any additional step.

To have the results always present, I would measuring always.
Expected the start, the ring buffer is always filled with actual data.
So You never had to wait for the averageing.

Additional the actual data can be weightened.
The actual Data can be written more than 1 time into the ring buffer.
That will make the masurement faster and give the last measurement more influence.

When Space is the Problem You can add more Measurements in one register and divide it with the numbers of Additions.

To display Your data You have nearly free Choice.
For a lot of Displays You can find free librarys in the Internet.
My favorites for now and that solutions are OLED Displays.
 
I think the most suitable method depends VERY MUCH in the time between the samples We have no idea if the samples a 1 us apart or 1 year apart.
The OP needs to define the question better.

Les.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top