Skip to main content
Associate II
May 16, 2024
Solved

G431RB 32 Bit Timer

  • May 16, 2024
  • 5 replies
  • 2982 views

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? SFRSFRConfigConfig

This topic has been closed for replies.
Best answer by Karl Yamashita

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.

KarlYamashita_2-1715976333436.png

 

When i turn the encoder clockwise, you can see that CNT goes up starting from zero state.

KarlYamashita_0-1715976033640.png

And when I turn the encoder in reverse it is in the 32 bit values

KarlYamashita_1-1715976146115.png

 

5 replies

Karl Yamashita
Principal
May 17, 2024

Why do you need more than 16bits for an encoder?

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
Associate II
May 17, 2024

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. 

Karl Yamashita
Karl YamashitaBest answer
Principal
May 17, 2024

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.

KarlYamashita_2-1715976333436.png

 

When i turn the encoder clockwise, you can see that CNT goes up starting from zero state.

KarlYamashita_0-1715976033640.png

And when I turn the encoder in reverse it is in the 32 bit values

KarlYamashita_1-1715976146115.png

 

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
Associate II
May 20, 2024

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. 

waclawek.jan
Super User
May 18, 2024

> 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