cancel
Showing results for 
Search instead for 
Did you mean: 

dual encoders

JCEngineer
Associate II

Hello everyone I am looking for some support with using 2 encoders on an STM32F303CB. I am able to select in the Motor Control workbench to have an encoder on Tim3 (pins B4 and B5) or on Tim2 (pins A5 and B3). I need to use 2 encoders for a project. Is there a way to enable encoders on both of these at the same time? 

5 REPLIES 5
Gael A
ST Employee

Hello jcorcoran01,

Could you please tell me what board you are working on, or if it is a custom board ?

In any case, you can't enable 2 encoders on a same motor drive via workbench. On ST boards, only one input is available for Hall/Encoder (except for dual drive boards), so even if you manually enable two encoders you will have to worry about connection to your MCU, especially the pins you are talking about.

If you agree with my answer, please consider accepting it by clicking on 'Accept as solution'.

Hope this will help,
Gaël A.
JCEngineer
Associate II

It is a custom board so I have access physical access to the pins> I am looking for support on how to actually enable the timers and interrupts in order to use both sets of pins as encoders. Thanks

Hello jcorcoran01,

In that case you could create two projects, one using Tim3 and the other Tim2. You will then need to manually add the missing parameters from one of them to the other. This can be done via CubeMX too. This way, both your timers will be set up for your encoders. However, we do not provide any code for the use of two simultaneous encoders, so you will have to figure that on your own depending on what you want to do. Speaking of which, out of curiosity, what is the purpose of using two encoders on a same drive ?

If you agree with my answer, please consider accepting it by clicking on 'Accept as solution'.

Hope this will help,
Gaël A.
JCEngineer
Associate II

It is essentially a load position control where the motor has an encoder for feedback and the load has an encoder. I need to be able to control the motor using the encoder feedback in or to have the load hit a specific position. I have been able to have either encoder correctly initialize individually using the motor control work bench. I have then tried to manually enable the second one in the CubeMX by setting the TIM3 pins to the correct channel and put into "Encoder mode TI1 and TI2". This seems to generate the correct code to initialize the second timer for use with the second encoder. Where I am having trouble is setting up the correct sw to have a variable that is the count of the second encoder 

cedric H
ST Employee

Hello @JCEngineer ,

Thank you for sharing with us your use case. The principle of the encoder is to have a timer that count up to the number of pulses contained into a mechanical rotation. The angle is then directly linked to the timer value. l advise you to analyse the function ENC_CalcAngle from the file encoder_speed_pos_fdbk.c 

Your use case with two encoders is very specific and goes far beyond the scope of our development kit. I hope you will succeed to achieve your goal.

Best Regards

Cedric