2017-01-05 01:43 AM
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...
2017-04-21 01:17 PM
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.
2017-04-21 03:07 PM
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