Skip to main content
Ejunior007
Associate II
January 12, 2022
Question

How to implement 3 encoders using encoder mode in STM32F103C8?? the operation need to be in parallel in the same time.

  • January 12, 2022
  • 2 replies
  • 1551 views

..

This topic has been closed for replies.

2 replies

TDK
January 12, 2022

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.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Ejunior007
Associate II
January 13, 2022

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

}

MM..1
Chief III
January 13, 2022

Or you can use one timer for sampling interrupt and check GPIO states , this way you can use AB encoders Numfreegpio/2