cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f429 rotary encoder external interrupt

er3481
Senior
Posted on January 05, 2017 at 10:43

Hi,

I am using rotary encoder with two input i/o and i want to read the encoder pinA and pinB values with external interrupt. I am using callback function for two input PA0 and PA1. My functions are below:

In stm32f4xx_it.c:

void EXTI0_IRQHandler(void)

{

  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0); 

}

void EXTI1_IRQHandler(void)

{  

  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);

}

and in main.c:

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

{

       if(GPIO_Pin == GPIO_PIN_0)

         {   

            //do something

          }

       if(GPIO_Pin == GPIO_PIN_1)

         {   

            //do something

          }

}

When i turn the encoder it does not works clearly, and when i debug the code, the call back function is called more than once. How can i fix it? Any adivse...

2 REPLIES 2
Bumsik Kim
Senior
Posted on April 21, 2017 at 22:17

Hi,

The handler and callback look good without any problem IMHO. I think there should be a problem in other areas, such as GPIO setting and NIVC settings. How did you initialize GPIO and Interrupt?

Apart from your question, why not using the rotary encoder interface embedded in every timer peripheral? This is not interrupt driven so it will be much more efficient in high speed rotary encoder.

Bumsik.

Posted on April 22, 2017 at 00:07

You could be getting bounce on your quadrature input signals. You might need some capacitors to take out the pwang in the signals.

Plus, use the timers instead of interrupts. They are designed for this purpose.

http://embedded.fm/blog/2016/11/10/discovery-debouncing

 

Andrei