JesperMP said:
If you measure ONLY pulses within a fixed time, then you will get quantisation errors (is that the right term ?), because even at a constant flowrate, there will be differences for each sampling.
That is the right term. When ever you sample analog data and convert it to digital there is quantizing. Sample quantizing makes what should be like a linear ramp look like a stair step response. The finer the resolution the smaller the 'steps' are and the closer it approximates the linear ramp.
If you have for example 20.2 pulses within a time, then you will measure 20-20-20-21-20-20-20-20-21-20-20-20-20-21 etc. Again, it would require a low-pass filter.
With my method you do not need the low-pass filter.
You are assuming that you can measure the time between two events and that your sample time is arriving a constant intervals. News flash everybody. There are times when interrupts are turned off. Interrupts do not happen at equal intervals but that is another thread.
Bryan G's method is good but doesn't answer the question. Both Bryan G's and JesperMP's method rely on sampling over time or many counts to reduce sample error. Basically he is measuring the time between many pulses.
I do simulations on this topic. I use linear ramps and sine waves as the ideal velocity. I add two types of 'noise'. One is the quantizing error, the other is sample jitter. In our FPGAs the sample jitter is in the nanosecond range but for a PLC it is much different.
resolution:=0.0001;
jitter:=0.0000000001
y(t)= Trunc(v(t+rnorm(jitter,0),resolution)
the t+rnorm(jitter,0) term is the current time plus the sample jitter with an offset 0 and a standard deviation of jitter.
The Trunc( ,resolution) term adds the quantizing.
I am assuming there isn't any true analog noise in the formula above. There is just sample jitter and quantizing.
I think Jesper's method provides the closer measurement since the actual time (to the accuracy of the time base) for the number of pulses in the sample period (not the sample period time itself) is used to determine the rate.
Show me/us the numbers.
Keith is right about really needing hardware to do this right. If you sample by time then how do you know the next count is about to occur? If you record time difference over a number of counts you are assuming the time you are latch is the time at which the last count just changed. There will be an error. In JesperMP's example the speed is 20 20 20 20 21 20 20 20 20 21 for a true speed of 20.2. One can compute the standard deviation of error or the maximum error of 21-20.2=0.8.