cancel
Showing results for 
Search instead for 
Did you mean: 

Measure speed of rotation of 2 DC motors

mmeisl9
Associate
Posted on February 06, 2011 at 16:59

Measure speed of rotation of 2 DC motors

2 REPLIES 2
picguy2
Associate II
Posted on May 17, 2011 at 14:24

You may be better off timing one revolution using a timer at 72MHz.  If needed you can extend a 16-bit timer using RAM location you increment in the timer’s ISR.  Interrupt at low->high (or the other way around) on one encoder pulse.  It’s generally better to let the timer run without modification.  I.e. don’t reset it on the encoder pulse.  Subtract to get the difference.  

(If using an extended counter in RAM make your encoder pulse ISR the same priority as the timer ISR.  In your encoder ISR use the timer’s UIF to account for timer FFFF->0000 wraparound.)

I would recommend using background (non-ISR) code to subtract and produce RPM or whatever output you want.  I would build a circular list in the ISR then depending on your needs do a little smoothing before output.

BTW, is your motor connected to a quadrature encoder?  See http://en.wikipedia.org/wiki/Rotary_encoder These often have multiple pulses per revolution.

Smoothing:

S = smoothed value

R = raw input value

N = smoothing factor

S = (R + S*N)(N+1)  -or-  S = (R + S*(N-1)/N

Unless S is large you would do well to use floating point or keep extra unreported bits in the low end of S.  The second form is handy because if you set N at some reasonable power of 2 the divide can be done in a single shift and Cortex multiply is fast.

Two motors: Two encoder ISRs or use one and determine which encoder made the ISR.  Still only one timer needed.
mmeisl9
Associate
Posted on May 17, 2011 at 14:24

Thank you for your fast answer,

I think about it, but I have this problem:  I dont now how I differentiate pulse from first and second encoder. So, Is there possibility set the TIMER to incrementing 2 variables in dependence on first or second  encoders?

I am sorry for my bad english:-(

Thank you.