2010-08-19 11:12 AM
Speed measurement.
2011-05-17 05:03 AM
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, Hal2011-05-17 05:03 AM
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.2011-05-17 05:03 AM
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).
2011-05-17 05:03 AM
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.