the subject I think is not really good chosen but it describes a bit my problem.
What shall be done:
The point is that I have a flow sensor which gives about 1 puls per 7 ml. approx 125 pulses per liter.
Now what I would like to do is to measure & calculate the average flow and send it over a can likely bus.
So far no problem. But the point is that the flow can vary from around 2-3 liter/hour to 70 liters/hour or even some more. The high flow rate does not generate any problem but the low once does as the flow sensor have so low pulses per second down there.
If I need now to send this updated value more often then, for example, every 10 second like every 3 seconds the problem is that I do not have accurate enough measurements from the flow sensor.
So for more accuracy, I could measure and calculate the time between two pulses and use this as the base for the calculation of the flow volume. Still, this is too bad accuracy as a difference of 1 puls per second would result in a very high change already.
So What I thought todo is now to start several measurements with may a second delay, let's say 5 and each measurement runs for 5 seconds. Now after for example 10 seconds, at this point all measurement jobs completed once, I could take the result and average them.
So far so good. Now I was looking for how to do this with the technically best way.
The main question is now for me how to store the values I get from each measurement. I read about circular buffer and arrays. From my logic, a circular buffer would fit here since the measurements should continuously update the variables I would use for averaging the results from the counters. If I understood the function of a circular buffer right every new value which will be store is causing that the first value which was stored will be dropped. This would be then already some kind of averaging.
What kind of technics could I use here?