Open va3hr opened 2 years ago
I'm in exactly the same position with the same problem...
Same problem here. Lib is not working at my side. Any solutions yet?
maybe you should add function HAL_TIM_Encoder_MspInit, which can be generated by cubemx like this `void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef* tim_encoderHandle) {
GPIO_InitTypeDef GPIO_InitStruct = {0}; if(tim_encoderHandle->Instance==TIM2) { / USER CODE BEGIN TIM2_MspInit 0 /
/ USER CODE END TIM2_MspInit 0 / / TIM2 clock enable / __HAL_RCC_TIM2_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**TIM2 GPIO Configuration
PA0-WKUP ------> TIM2_CH1
PA1 ------> TIM2_CH2
*/
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/ USER CODE BEGIN TIM2_MspInit 1 /
/ USER CODE END TIM2_MspInit 1 / } else if(tim_encoderHandle->Instance==TIM3) { / USER CODE BEGIN TIM3_MspInit 0 /
/ USER CODE END TIM3_MspInit 0 / / TIM3 clock enable / __HAL_RCC_TIM3_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**TIM3 GPIO Configuration
PA6 ------> TIM3_CH1
PA7 ------> TIM3_CH2
*/
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/ USER CODE BEGIN TIM3_MspInit 1 /
/ USER CODE END TIM3_MspInit 1 / } }`
I using arduino 1.8.13., have installed the STM32encoder library and have the correct board selected, My issue is when I compile, upload the example sketches, the interrupts do not appear to be working, I get no output. I am using version STM32encoder 0.9.7
The board I am using is a clone "blackpill". My EC11 encoder is connected to A1 and A0 with the common pin connected to 3.3V, this provides positive pulses, out of phase, as expected, when I rotate the encoder. I am doubtless missing something, there doesn't appear to be a way to select a timer channel and pins.
When I installed the library, I was asked if I wanted all dependencies installed, I said yes but got a "no protocol" error message. Perhaps the problem lies there?
Anyway, please help me get this library working with my code
Thanks
Peter #include "STM32encoder.h"
STM32encoder enc(TIM2); // create a managed encoder by TIM2. // You have to use TIM input pin to connect encoder to. // i.e. for STM32F103 TIM2 has PA0 and PA1 inputs. See device documentation for other TIMs input pins
int16_t myVar = 0;
void setup() { Serial1.begin(57600); enc.bind(&myVar, 1, -10, 20); // bind myVar to encoder by inc/dec ratio of one and limit to [-10, 20] range of values }
void loop() { if (enc.isUpdated()) { Serial1.printf( "pos:%5ld dir:%2d myVar:%3d\n" , enc.pos() , enc.dir() , myVar ); } } My output..
Same here im using it with stm32f407vgt6 and arduino2.1.1 it gets compiled and uploaded to the board successfully but it always return 0 when call enc.pos() im using tim3 and encoderAB is connected to PA6 and PA7
Same issue here, not working with a BlackPill F411 using TIM2 on PA0 and PA1. I've tried pullup and pulldown resistors without success. Enc.pos() returns 0
I hope I could help, but my knowledge is quite limited right now...
Thanks @haozhou-wong it works with a BlackPill F411 (TIM2 & TIM3)
Works on F103 in full quad mode.
STM32encoder enc(TIM2,0,0);
But not work on F407 and F411 in full quad
STM32encoder enc(TIM2,0,0);
it only work in half quad mode
STM32encoder enc(TIM2,0,1);
for F4 series i have used @haozhou-wong init lines.
so the problem is htim.Init.Period = 0 wont work.
any suggestion how to make F4 work in full quad mode?
I using arduino 1.8.13., have installed the STM32encoder library and have the correct board selected, My issue is when I compile, upload the example sketches, the interrupts do not appear to be working, I get no output. I am using version STM32encoder 0.9.7
The board I am using is a clone "blackpill". My EC11 encoder is connected to A1 and A0 with the common pin connected to 3.3V, this provides positive pulses, out of phase, as expected, when I rotate the encoder. I am doubtless missing something, there doesn't appear to be a way to select a timer channel and pins.
When I installed the library, I was asked if I wanted all dependencies installed, I said yes but got a "no protocol" error message. Perhaps the problem lies there?
Anyway, please help me get this library working with my code
Thanks
Peter
include "STM32encoder.h"
STM32encoder enc(TIM2); // create a managed encoder by TIM2. // You have to use TIM input pin to connect encoder to. // i.e. for STM32F103 TIM2 has PA0 and PA1 inputs. See device documentation for other TIMs input pins
int16_t myVar = 0;
void setup() { Serial1.begin(57600); enc.bind(&myVar, 1, -10, 20); // bind myVar to encoder by inc/dec ratio of one and limit to [-10, 20] range of values }
void loop() { if (enc.isUpdated()) { Serial1.printf( "pos:%5ld dir:%2d myVar:%3d\n" , enc.pos() , enc.dir() , myVar ); } } My output..