Go Down

### Topic: Algorithm question: how to tell when RPM is zero (motor stopped) (Read 847 times)previous topic - next topic

#### torriem

##### Feb 04, 2013, 08:27 pm
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?

#### PaulS

#1
##### Feb 04, 2013, 08:30 pm
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.

#### torriem

#2
##### Feb 04, 2013, 08:33 pm
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.

#### nickgammon

#3
##### Feb 04, 2013, 08:36 pm
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).
Please post technical questions on the forum, not by personal message. Thanks!