2020-03-01 03:33 AM
int16_t GetTim4Encoder(){
Tim4Encoder = __HAL_TIM_GET_COUNTER(&htim4);
//__HAL_TIM_SET_COUNTER(&htim4,0);
return Tim4Encoder;
}
2020-03-01 09:18 PM
That's 'counter period'-field in CubeMX.
2020-03-01 10:26 PM
Counter period was 65535 from the beginning.
2020-03-02 09:56 AM
The counter counts from zero to ARR and then wraps back to zero. If you turn the decoder in other direction, if first wraps to ARR and then goes to zero.
When you use integers, you just interpret the value such that it's -ARR/2 to ARR/2. It's easy, if your counter is 16-bit and you use int16 as the data type. It automatically matches. That's the beauty of 2's complement. If your ARR is 0x7F, the counter increments to 0x7F (127) and then goes to zero.
2020-03-02 10:26 AM
Then something amiss with your printing routine or the encoder/settings. The ARR / Period value should be constraining the wrap point of the counter.
//sizeof(TxMessages) has a problem
Perhaps use strlen() when appropriate, and NUL terminate the strings.
Consider itoa() to convert integers to strings.
Show the initialization code. Ideally make a clear, simple, complete implementation of the test code, and post that. Would save a look of time trying to understand what exactly is broken, without needing to guess at what you have done.
Not sure it has yet been established which "STM32" is involved, the make/model of encoder, or how it is attached to anything.
#UphillSkiing