I know this seems like a very trivial question (and hopefully it is) but I’m trying to figure out the best way to get accurate RPMs from Hall effect sensor readings. Through my scope, I can see a fairly clean square wave and I’ve determined that I’m getting two highs for every revolution. So, from the scope using the time interval I think I can very accurately calculate the RPMs. However, using software to count the interrupts I’m not able to get quite the same number. I’ve tried two different approaches and I’m curious to know if there are others that might yield better results. The results of these two approaches can differ by as much as a couple hundred RPMs and neither match my calculated result.
- Add an interrupt handler that increments a static variable on every fire of the sensor.
- Setup a Timer that fires every second.
2a. Calculates RPMs as count * 60.
2b. Resets counter.
Problem with Approach #1: Based on Timer which is not guaranteed to be accurate.
- Add an interrupt handler that calculates RPMs on every fire based on time since last interrupt.
1a. Calculate ms since last interrupt.
1b. Calculate RPMs based on 1a.
1c. Store “last time” for 1a calc on next fire.
Problem with Approach #2:
- I feel like there’s too much going on in every call.
- I’m not sure that using the DateTime difference for one interrupt gives me enough precision to accurately calculate RPMs based on one revolution. I’d rather have a larger sample.
What other approaches are people using? Or am I just crazy and approach #2 is really good enough? Sorry for not providing exact measures & code samples. I’ll dig those up this evening if needed. I’m really more interested in conceptual ideas at the moment.