the pulse rate can be derived without knowledge of the CPU clock speed. To achieve the pulse rate from your sensor input you can do two things:
- count the pulses dn within a certain (i.e. fixed) interval T of time) or
- measure the time dt between two pulses.
I'll come back later on this concerning accuracy.
To measure time, you can use the function millis(). This function returns you the milliseconds since bootup as an integer upon calling it. Method 2 is rather simple to implement.
- Setup three global integers a, b and c.
- At the end of setup set a to current millis();
- In your ISR set b to current millis();
- Also in ISR: set a=b;
- calculate c=b-a (i.e. your dt);
c holds your current full wave pulse length in milliseconds, which is updated every pulse. You can derive your flow then from it.
The first method uses a counter as demonstrated in your suggestion. You then need a timer outside your ISR, two variables d and e. Either you poll millis() in your main "loop()" or you install a timer interrupt, both will work here.
- At the end of setup set d to current millis();
- If your predefined time T is passed (by comparing d with millis(),
- save your counted pulses to e=pulseCount
- reset: pulseCount=0
e holds your pulse count during interval T, from which you can derive your pulse rate.
Method 1's accuracy increases with higher T and higher flow speeds. Therefore the update rate of your measurement is low. By changing T you can easily increase accuracy on cost of responsiveness. This is perhaps a good idea, if you have pulsating flows in your tubings, or the sensor is a bit rattling.
Method 2's accuracy increases with lower flow speeds. It is best to measure very low flow speeds. Update frequency is minimal (1/dt).
Regarding this sensor you should calibrate it yourself. It is a cheap and rugged device (I'm using it, too), but its output depends on several parameters like mounting position, fluid viscosity and so on. Make sure, there are no bubbles, foam or contaminants in your fluid systems as they garble the results effectively.
n.b.: make sure to take care of an overflow of millis().