-1

I met a problem.

I used STM32F103. One EXTI line was used to check a button push-and-release. EXTI line was set to be triggered by both falling and raising edge.

I know there will be burr when I pushed the bottom. The question is , when I pushed and then released button, the count of interrupts are some times odd and some times even. As to my understanding, it should be even number since anyway, you will return to your original signal value(lets say HIGH). For example, if you have 2 burr in a push-release, you should have 4 times interrupts(HIGH(origin)->LOW->HIGH->LOW->HIGH). I could not understand why.

Thanks for your help!

yebii
  • 5
  • 2

1 Answers1

0

Handling an interrupt takes time. So if the next transition on the input pin occurs before the interrupt flag has been cleared, no additional interrupt is triggered. The event (transition) is lost.

You can slightly improve the situation if you clear the interrupt flag early in the interrupt handler. But it doesn't solve it completely if the transitions can occur in quick succession. And with a push button, they can. So you'll have to adapt your code accordingly.

Codo
  • 75,595
  • 17
  • 168
  • 206
  • Thanks for your reply. I use HAL provided by ST. The interrupt flag was cleared before calling interrupt callback in which the interrupts was counted. In the callback function, only have one line: count++; I don't know how much time count++ will take, maybe we need a hardware filter to ignore fast burr since anyway, MCU could not do less than just 'count++'.... – yebii Dec 22 '20 at 08:29
  • Don't forget the time it takes to save all registers before your interrupt handler is called. So `count++` will only be a minor part. Additionally, the EXTI interrupt handler call might be postponed because of another interrupt of the same or higher priority. – Codo Dec 22 '20 at 09:07
  • Thank you very much, Codo. Maybe a hardware filter is really needed to avoid meaningless short burr. – yebii Dec 22 '20 at 14:16