2025-05-25 4:08 AM
Hello!
Problem: I am using 3 timers in the Encoder function on the Nucleo F767ZI board. The timers are TIM1, TIM2, and TIM3. The encoder function on TIM1 works perfectly. However, the encoder function on TIM2 and TIM3 is not working. They just count up 1 pulse, then down 1 pulse, then up 1 pulse again.
What I have done: I checked the physical connection, and they were working fine. I also tried swapping TIM1 and TIM2, and TIM was still working fine, and TIM2 was still not working, so I think there might be some problem with the firmware or when I configure TIM2. The configuration file (.ioc) is attached to this post.
Could you please help me with this problem? Thank you very much!
Solved! Go to Solution.
2025-05-28 1:02 AM
Hello! Thanks for your help! I figured out the reasons why my code didn't work:
1/ The clock setup was okay, but when I copied the "SystemClock_Config" function to my custom code, I messed it up.
2/ However, after fixing the clock configuration, the code still didn't work. Then I figured out that I am reading the encoder too fast. After adding a little bit of delay, everything is ok now.
2025-05-25 8:22 AM
This behavior happens if one line isnt’t hooked up. Verify pinout is correct, pins are free, and are connected to the header you are using.
2025-05-26 12:42 AM
Hello! Thanks for your reply! I am using pins PA5 for channel 1 and PA1 for channel 2 of TIM2. I have checked and they are connected properly. I also removed the connection SB13. I tried to use TIM1 on the same encoder, and it worked fine. I am not sure what is wrong here.
2025-05-26 2:23 AM
In debugger, observe GPIOA_IDR for PA1 and PA5 inputs are changing while the encoder is moved slowly. Observe whether they change in the expected 00-01-11-10 pattern.
If they do, then read out and check/post TIM and related GPIO registers content.
JW
2025-05-26 2:57 AM
Above are the signals of CH1 and CH2 of TIM2, seem like they are not running in a wrong pattern. However when I used TIM1, the signals on CH1 and CH2 are in the correct pattern.
2025-05-26 5:14 AM
If the above printout does correctly display GPIO_IDR values for PA1 and PA5 (do they?), then read out and check/post content of TIM2 and GPIOA registers.
Also make sure that there are no other GPIO set to TIM2_CH1 and TIM2_CH2. The easiest thing to do in this regard is to write a minimal program (possibly as different project) doing nothing else but setting up PA1 and PA5 and TIM2.
JW
2025-05-26 5:08 PM - edited 2025-05-26 5:09 PM
Not real clear what output we're looking at here, but it's clear the encoder value is changing despite the channels staying the same, so I suspect encoder and channel output is not in sync, or is otherwise incorrect/unreliable.
Encoder value swapping precisely between 32768 and 32767 after every call suggests problems.
Perhaps SB13 isn't really gone, or other code issues are present.
IOC setup looks fine.
2025-05-28 1:02 AM
Hello! Thanks for your help! I figured out the reasons why my code didn't work:
1/ The clock setup was okay, but when I copied the "SystemClock_Config" function to my custom code, I messed it up.
2/ However, after fixing the clock configuration, the code still didn't work. Then I figured out that I am reading the encoder too fast. After adding a little bit of delay, everything is ok now.