On Saturday 17 April 2010 07:09:14 pm Joe Dee Kay wrote:
> I have an interrupt triggered a certain number of
times each revolution of
> a motor. I was thinking I could use that to calculate the rotating speed of
> the motor, but everything I've tried doesn't work.
It might help if you described what "doesn't work" means.
> Does anyone have a good
> way of calculating the rate an interrupt is triggered?
I've just did a project where speed is needed. The basic issue is how
do you need to know the motor speed? When the motor is speed falls to the
point where there are no sensor pulses during the interval between
calculations then the motor speed is typically assumed zero.
One way that works well is to--
1) Save the time of the motor sensor interrupt (most likely this will have to
be the input capture timer time plus the extension with the timer overflow to
give 32 bits).
2) Also maintain a running count of the interrupts.
3) Periodically, (and this has to do when how often do you need to know the
speed), compute the speed by--
if ((n1 - n0) > 0)
Speed= (n1 - n0)/(t1-t0)
Speed = 0;
n1 = latest sensor interrupt count
n2 = sensor interrupt count at previous computation
t1 = latest time of sensor interrupt
t2 = previous time
Speed then needs to be scaled to whatever units you wish, e.g. rev/min,
rev/sec, radians/sec, etc., and of course the number of interrupts per
revolution figure into this.
It helps to set up a spread sheet so that one can see the ranges of numbers
that are generated (unless one has computing power and memory to burn and
takes the lazy way out by using floating point).
Donald E Haselwood