2024-05-16 04:53 PM
I am attempting to set up an encoder on STM32G431RB using Tim 2 which is 32bit but it is only counting up to a 16bit value and going negative. I looked at the register through SFR and only the first 16 bits are active, is there another setting I need to change to use the full 32 bits?
Solved! Go to Solution.
2024-05-17 01:07 PM
I just tested on the same Nucleo-G431RB and I can get the TIM2->CNT to show 32 bit values. There was nothing special needed to be done.
When i turn the encoder clockwise, you can see that CNT goes up starting from zero state.
And when I turn the encoder in reverse it is in the 32 bit values
2024-05-16 07:11 PM
Why do you need more than 16bits for an encoder?
2024-05-16 07:35 PM
I don't absolutely need it, I can work around it with software, but my main concern is that there should be 32bits available and I'm a bit stumped as to why I only have 16 bits. Overall, just want to know if I have something setup incorrectly for future reference.
2024-05-17 01:07 PM
I just tested on the same Nucleo-G431RB and I can get the TIM2->CNT to show 32 bit values. There was nothing special needed to be done.
When i turn the encoder clockwise, you can see that CNT goes up starting from zero state.
And when I turn the encoder in reverse it is in the 32 bit values
2024-05-18 01:07 AM - edited 2024-05-18 01:13 AM
> I am attempting to set up an encoder on STM32G431RB using Tim 2 which is 32bit but it is only counting up to a 16bit value and going negative
How do you observe that, exactly?
> I looked at the register through SFR and only the first 16 bits are active
Your screenshot of regsiters does not indicate this; I see all zeros there.
Show us a screenshot which demonstrates that only 16 bits of TIM2_CNT are active.
OK now I see why, the IDE probably does not have capability to display both variants of the register layout (for DITHEN = 0 and DITHEN = 1, see TIMx auto-reload register (TIMx_ARR)(x = 2, 5) in RM) so it resorted to an entirely incorrect way to display it as a 16 bits and a 1 bit field. This may be CubeIDE's limitation/flaw; so, as @Karl Yamashita said above, you may want to look at TIMx_CNT through the variable view in this particular case.
JW
2024-05-20 04:38 AM
This answered my question along with @waclawek.jan contribution. I can visualize the 32 bit variable through the live expression but not through the SFR.
Thank you.