cancel
Showing results for 
Search instead for 
Did you mean: 

Speed measurement.

lipin
Associate II
Posted on August 19, 2010 at 20:12

Speed measurement.

4 REPLIES 4
raptorhal2
Lead
Posted on May 17, 2011 at 14:03

I assume your problem is that at low speed, t2 is always overflowing between measurements. So why not use the t2 interrupt handler to count overflows? The total t2 count will then be 65536*(number of overflows since last sample) + (t2 new) - (t2 old). Four bytes will be needed for the t2 count. This way speed can be calculated at every encoder interrupt.

Cheers, Hal

Posted on May 17, 2011 at 14:03

Use the timer in counter mode to count the incoming pulses. Use another timer or systick to periodically check the timer/counter and compute the delta between the two measurements. You could also use the CPU instruction counter (SYSCLK) to time-stamp reading the counter if interrupt latency is an issue, or wanted to know the count over some more arbitrary period.

What is the min-max frequency for your incoming signal? Assuming DC to something.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lipin
Associate II
Posted on May 17, 2011 at 14:03

Ideally I would like to cover incremental encoders from 1000-32000 impulses per rotate so its 

1,6Hz to 3,2Mhz(speeds 100-6000rpm).

At high speeds there is no problem I could use normal encoder mode but low speeds kind of grind my gears I need to enhance somehow accuracy and idea of counting another fast counter is only one that comes to my mind (actually was recommended by my tutor).

Posted on May 17, 2011 at 14:03

The STM32 has a DWT_CYCCNT counter running off the system clock, at 50 MHz it wraps every 86 seconds. (2^32 / CPUFREQ)

http://infocenter.arm.com/help/topic/com.arm.doc.ddi0337g/BABJFFGJ.html#BABFDDBA

Use that as a timebase, evaluate the number of pulses you've received from your encoder in the last second, minute.

How quickly do you want to detect it is not moving? within 1 ms?

Want it quicker, sounds like you need a timeout/watchdog type timer that resets every time you get a pulse, and then fires if it expires without seeing one.

You could also check the time vs pulses in a tight foreground loop.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..