2024-09-30 07:02 AM
Hello everyone,
I'm encountering a problem with the development of my timer on a STM32G474VE. I have to use the TIM2 in encoder mode + index. I'm using a custom board. I started with a cubeMX project, initialising the timer in encoder + index mode. Due to hardware specification i need to use pins PA0 for TIM2_ETR, PD3 for TIM2_CH1, PD4 for TIM2_CH2. Using these pins, i have a problem with my counter. I have too many resets on a mechanical turn of my encoder. I enable the index interrupt and it is called more than once per turn. I have already checked my signals on a scope and my signals A, B and Z from the encoder are perfectly clean and correct. I temporarily change the configuration to connect TIM2_CH1 to PA5. In this configuration, the timer is perfectly working, so i suppose that I haven't got any problem with my clock configuration or with my hardware since i haven't got any difference in the mapping of PA5 and PD3.
In the STM32G474 documentation I've seen that in the alternate function table, the PD3 AF2 is for TIM2_CH1 and for TIM2_ETR. This is why I'm wondering if PD3 need extra configuration. Is it possible that the microcontroller connects CH1 to ETR and that could lead to extra index call ?
Thanks in advance for your help
2024-09-30 07:07 AM
> Is it possible that the microcontroller connects CH1 to ETR and that could lead to extra index call ?
Yes.
JW
2024-09-30 07:11 AM
But if it's the case, how are you supposed to use this pin ? CH1 and ETR are two signals from the encoder. Their purposes are totally different so i don't understand how you can make thing working.
2024-09-30 07:18 AM
Well, you havePA0/PA5/PA15 where TIM2_CH1 and TIM2_ETR are on different AF (as you've already discovered).
This is not so in many older STM32, e.g. 'F4, where there's no separate TIM2_CH1 and TIM2_ETR.
I'm not ST so can't explain their pinout/GPIO matrix decisions.
JW
2024-09-30 07:41 AM
Well, firstly thank you for your time and answers !
Based on your advice, I tried looking for an example in cubeMX for the F4 family. The only examples available are quadrature encoder without ETR signal so I'm still confused on how to implement the encoder + index with the PD3 pin...
2024-09-30 07:58 AM - edited 2024-09-30 08:02 AM
What I wanted to say is that you are lucky that in 'G4 there are *some* pins where TIM2_ETR and TIM2_CH1 are separate; would you use 'F4 you wouldn't have such option.
While there is no encored+index mode in the F4 - it's a relatively new mode found only in new STM32 families - there are legitimate uses for the ETR+CH1 combination (e.g. external clock on ETR + capture on multiple channels including CH1) which thus are impossible in 'F4 for that inexplicable design choice.
In other words, you in 'G4 simply can't use PD3 for this purpose, but you still can choose to use two of the 3 pins on PA. Or maybe a different timer.
JW