2016-09-26 03:57 AM
Hi, I use quadrature encoder connect to stm32f103 timer which I set to encoder mode and its work properly. I count to 1632 - its full wheel rotary, but I dont know how to calculate a current speed from this data. How I should do this?
2016-09-26 04:54 AM
If you understand the distance covered by a full rotation, you can measure the time it takes to do that, and thus the velocity. You can also measure the time between pulses, and thus a fractional rotation.
2016-09-26 03:59 PM
ENCODER_READ_FREQUENCY)
to 1000.0f. You could sample at any frequency so long as the counters do not overflow between reads.
The code looks a bit like this sample extracted from a larger application. Note there will be some quantisation effects at low speed but it works out just fine for me.float
encodersRead (
void
)
{
// return speed in mm per second
static
int16_t Encoder;
static
int16_t oldEncoder;
oldEncoder = Encoder;
Encoder = TIM_GetCounter (ENC_TIMER) ;
int16_t Count = Encoder - oldEncoder;
return
(
float
) Count * ENCODER_READ_FREQUENCY * MM_PER_COUNT;
}