Go Down

Topic: when intterupt hangs arduino (Read 960 times) previous topic - next topic

ProfePaco

I have observed the following:

Pin 2 has an interrupt when shift to HIGH to LOW.

If I use a button to shift HIGH to LOW, or specially I connect a wire  from Pin 2 into ground line... the arduino hangs (many times).

If the the shift HIGH to LOW is produced by, for example, a sensor, this does not happen.

So it seems there is a debouncing problem when using attach interrupt. Why? How can I solve it? perhaps using a capacitor? How?

majenko

Yes, you will be having massive bounce with that arrangement.  If the interrupt routine takes longer to run than the period of the bounce, you may be nesting interrupts.  This is bad.

I usually do my debouncing in hardware, using this circuit:



but where the inverter is actually the input pin.  R1 = 10K, R2 = 470Ω, C = 100nF

ProfePaco


CrossRoads

You could also disable interrupts with the first interrupt, and not enable them until you are ready to process another interrupt.
That way a new interrupt does not interrupt the ongoing interrupt, so to speak.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Nick Gammon



Pin 2 has an interrupt when shift to HIGH to LOW.

If I use a button to shift HIGH to LOW, or specially I connect a wire  from Pin 2 into ground line... the arduino hangs (many times).



Show us your code? Did you use FALLING or LOW interrupt?


That way a new interrupt does not interrupt the ongoing interrupt, so to speak.


An interrupt does not fire while an interrupt is being processed, but certainly they may happen in quick succession if you don't debounce.

Another issue is that he might be trying to do too much in the ISR.

Posting code gives better answers.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up