cancel
Showing results for 
Search instead for 
Did you mean: 

Ecternal interupt occurs 2 times?

Arman Ilmak
Senior
Posted on February 19, 2018 at 22:58

Hello guys.

I've started working with stm32f217zg series and i have a problem with external interupt.

I have programmed the mcu and after i push the button the interupt occurs two times instead of one.

I use cube mx to generate the code.

I attached the code so you can see it.

12 REPLIES 12
AvaTar
Lead
Posted on February 20, 2018 at 09:26

Being no friend of Cube, I don't browse through megabytes of autogenerated code.

But I suspect you configured an EXTI interrupt on both transitions (HL and LH), thus two interrupts.

For push buttons, I would use only the interrupt applying to the release event.

Andrew Neil
Chief II
Posted on February 20, 2018 at 10:19

You do realise that mechanical switch contacts bounce - don't you?

See:

https://community.st.com/0D50X00009XkXPNSA3

Posted on February 20, 2018 at 21:51

AvaTar wrote:

But I suspect you configured an EXTI interrupt on both transitions (HL and LH), thus two interrupts.

For push buttons, I would use only the interrupt applying to the release event.

I've set it for just falling edge.

Posted on February 20, 2018 at 21:55

Andrew Neil wrote:

You do realise that mechanical switch contacts bounce - don't you?

See:

https://community.st.com/0D50X00009XkXPNSA3

I've put a 500 ms delay after the interrupt occurs.This delay should fix this matter,doesn't it?

Posted on February 20, 2018 at 22:53

Does it fix the problem?

Posted on February 21, 2018 at 01:24

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

 

Article for you

Andrei

Posted on February 21, 2018 at 08:41

The bounce depends on the mechanical design. I came across switches that exhibited no bounce at all.

But for a normal sized button, 500ms is too much IMHO, one could do multiple presses during this time period.

I found 30 .. 50ms more appreopriate in my applications.

Posted on February 21, 2018 at 10:34

 ,

 ,

http://www.ganssle.com/debouncing.htm

 , ,

https://en.wikipedia.org/wiki/Switch ♯ Contact_bounce

 ,
Arman Ilmak
Senior
Posted on February 21, 2018 at 12:29

Thank you guys.Yeah the problem was the bounce of the push button i used.

I put that delay after all the codes in the EXTI interrupt routine so when i used push button the bounce make the interrupt happens again.I just needed to put a 30 ms before clearing the exti flag clears.