2023-05-31 07:49 AM - edited 2023-11-20 04:17 AM
I have a custom PCB with a STM32F429ZIT6 on, I am using CubeMX and STM32CubeIDE.
The board generates encoders signals with TIM1 & TIM3 in Output Compare mode.
I can scope and see the correct encoder signals being generated by both timers.
Then, I also want to read those signals.
To do so, I am using TIM2 and TIM5 as Encoder Mode.
TIM5 has no issue return encoder count with htim5->Instance->CNT
However, TIM2 doesn't return anything.
Looking into SR (Status Register) of TIM2
I can see CC1IF & CC1OF bits to be reset for TIM2.
CCR1 & CCR2 of TIM2 are also empty when making the read instruction to CNT.
Reading into CC1IF Descriptions:
"If channel CC1 is configured as input:
[...]
0: No input capture occured
1: The counter value has been captured in TIMx_CCR1 register (An edge has been detected on IC1 which matches the selected polarity)"
As far as I know, putting the Timer in Encoder Mode is configuring CC1 and CC2 as input.
And, I can scope encoder signals coming into PA5 (TIM2_CH1) & PB3 (TIM2_CH2).
Any Idea where to look?
Thank you for the support.
2023-05-31 11:57 AM
CH1 is not working.
Read out and check/post relevant GPIO registers content.
Measure directly on mcu's pins (think of bad solder joints). Alternatively, set the given pin(s) as GPIO outputs, toggle them and observe.
JW
PS. Decimal printout of registers is not that useful.
2023-06-01 11:56 AM
Thank you for the comments;
I have checked for bad solder joint by setting PA5 & PB3 as GPIO output instead of TIM2_CH1 & TIM2_CH2. (Great Idea by the way).
I toggle both PA5 & PB3 and can see the associated signal on scope.
It's an issue with my firmware.
There's a bunch of other peripherals setup (Other timers, PWM generation with DMA, many many EXTI (8), USB) and my hypothesis is there is conflict between one of them and TIM2.
For binary/hex content of SR registers;
TIM5->SR = 0b11000011111 = 0x619
TIM2->SR = 0b10000011101 = 0x41d
2023-06-01 12:30 PM
TIM5->SR = 0b11000011111 = 0x619
TIM2->SR = 0b10000011101 = 0x41d
2023-06-01 12:39 PM
TIMx SR are ok.
Read out and check/post relevant GPIO registers content.
JW
2023-06-06 02:31 PM
It was a hardware issue, we resoldered another STM32F429 onto the custom PCB and everything works!