Pages: [1]   Go Down
Author Topic: Algorithm question: how to tell when RPM is zero (motor stopped)  (Read 330 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am reading RPM from a hall effect sensor in a flow meter using interrupts and a moving average (I may adopt a better algorithm to smooth the bumps later on).  Everything works great, but I'm a but unsure how to detect when the RPM has hit zero.  The first problem is that if the thing stops turning, there are no more interrupts so the RPM calculation stops.  I fixed that by having another function that can be run periodically to do the calculation and adjust the average RPM downward if there's a clear slowing trend.  This helps the RPM number fall off a lot more rapidly, but it won't quite hit zero in a timely manner.  Since the lowest practical speed I'll ever see is just over 50 RPM, if the calculation falls below that point (it's basically a timeout), my helper function just makes the RPM zero. These two techniques make it work pretty well, though not perfectly.

Is there a better way to do this?  Is there a standard technique or algorithm for doing this sort of calculation.  I can think of dozens of cases where commercial products are calculating a rate based on discrete signals over intervals.  How do they calculate it such that it detects a zero speed in a timely manner?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 642
Posts: 50366
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the interrupt handler that counts pulses, record when the interrupt occurred, too.

Then, when computing RPM, if the last interrupt was a while ago, you know the speed is 0. Of course, the definition of "a while ago" is up to you.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes that's exactly what I'm doing (I didn't describe that well in the original post).  Sounds like I'm doing things about how others would, then. 

I'll play with the timeout value a bit and try to find something that works reasonably well.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 503
Posts: 19089
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In loop, if you reset the count to zero periodically (say, every second) then it will be clear if the RPM is zero because the count will still be zero next time you check, a second later. This has the side-effect of giving you RPS (revolutions per second).
Logged


Pages: [1]   Go Up
Jump to: