STM32encoder icon indicating copy to clipboard operation
STM32encoder copied to clipboard

STM32encoder

Open va3hr opened this issue 3 years ago • 7 comments

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.. encoder_output

va3hr avatar Jul 06 '22 21:07 va3hr

I'm in exactly the same position with the same problem...

shaoyuancc avatar Jul 21 '22 06:07 shaoyuancc

Same problem here. Lib is not working at my side. Any solutions yet?

Lenz89 avatar Oct 26 '22 09:10 Lenz89

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 */ } }`

haozhou-wong avatar May 23 '23 04:05 haozhou-wong

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.. encoder_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

S-A-L-M-A-N-A-N-S-A-R-I avatar Aug 04 '23 19:08 S-A-L-M-A-N-A-N-S-A-R-I

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...

dmarman avatar Oct 11 '23 18:10 dmarman

Thanks @haozhou-wong it works with a BlackPill F411 (TIM2 & TIM3)

stache3000 avatar Jun 11 '24 20:06 stache3000