2017-07-25 09:04 AM
Hi all,
I am try to use
STM32F407VG discovery kit to read 5 encoder. I use TIM_HandleTypeDef and TIM_Encoder_InitTypeDef lib to read one encoder successfully. When I use the same code to read two encoders, I found that it doesn't work. Do anyone know that can I use this lib to read multiple encoder? Do anyone have any example code.
Thank you.
Solved! Go to Solution.
2017-07-26 02:24 AM
Hello!
The encoders use TIM1, TIM2, TIM3, TIM4, TIM5 timers to work.
Every timer is separate inialised as encoder.
So when you want to use each one encoder , must call the same function ofcourse with the appropriate previously initialised TIM_HandleTypeDef as parameter!
TIM_HandleTypeDef htim1, htim2...;// at global scope
//inside your funtion (main or other)
TIM_Encoder_InitTypeDef
enci;////fill the structures wiith proper data
htim1.Instance = TIM1;
.....
enci.EncoderMode = TIM_ENCODERMODE_TI1;
.......
HAL_TIM_Encoder_Init(&htim1, &enci);//initialisation..
htim2.Instance = TIM2;
...
enci.EncoderMode = TIM_ENCODERMODE_TI1;
....
HAL_TIM_Encoder_Init(&htim2, &enci);//initialisation..
//after initialisation , start all encoders
HAL_TIM_Encoder_Start(&htim1, TIM_CHANNEL_1) ;//start each encoder
HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_1) ;
....
2017-07-26 02:09 AM
When I use the same code to read two encoders, I found that it doesn't work.
Post details.
Note that not all timers support the encoder mode.
JW
2017-07-26 02:24 AM
Hello!
The encoders use TIM1, TIM2, TIM3, TIM4, TIM5 timers to work.
Every timer is separate inialised as encoder.
So when you want to use each one encoder , must call the same function ofcourse with the appropriate previously initialised TIM_HandleTypeDef as parameter!
TIM_HandleTypeDef htim1, htim2...;// at global scope
//inside your funtion (main or other)
TIM_Encoder_InitTypeDef
enci;////fill the structures wiith proper data
htim1.Instance = TIM1;
.....
enci.EncoderMode = TIM_ENCODERMODE_TI1;
.......
HAL_TIM_Encoder_Init(&htim1, &enci);//initialisation..
htim2.Instance = TIM2;
...
enci.EncoderMode = TIM_ENCODERMODE_TI1;
....
HAL_TIM_Encoder_Init(&htim2, &enci);//initialisation..
//after initialisation , start all encoders
HAL_TIM_Encoder_Start(&htim1, TIM_CHANNEL_1) ;//start each encoder
HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_1) ;
....
2017-07-26 08:55 AM
Thank you