cancel
Showing results for 
Search instead for 
Did you mean: 

G431RB 32 Bit Timer

NoviceStm32
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions
Karl Yamashita
Lead II

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

 

View solution in original post

5 REPLIES 5
Karl Yamashita
Lead II

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

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
Lead II

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

 

> 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

 

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.