2022-01-12 11:05 AM
2022-01-12 12:25 PM
Encoders are independent, so using 3 is fundamentally the same as using 1 except that you set it up on 3 different timers.
You can have up to 4 encoders on the STM32F103C8 by configuring each of TIM1/TIM2/TIM3/TIM4. CubeMX will happily generate the startup code for you.
2022-01-12 10:38 PM
Or you can use one timer for sampling interrupt and check GPIO states , this way you can use AB encoders Numfreegpio/2
2022-01-13 03:30 AM
for 1 encoder works just fine. i use HAL_TIM_IC_CaptureCallback for haldle some variables and turn te count into the position. But for 3 encoders doesnt work in the same way.
my code for 1 encoder:
uint32_t counter = 0;
int16_t count = 0;
int16_t position = 0;
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
counter = __HAL_TIM_GET_COUNTER(htim);
count = (int16_t)counter;
position = count/12; // encoder resolution 12 counts/mm
}