Pages: [1]   Go Down
Author Topic: when intterupt hangs arduino  (Read 736 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 128
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Offline Offline
Full Member
***
Karma: 0
Posts: 128
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot.

I will try.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 437
Posts: 23652
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
Logged

Pages: [1]   Go Up
Jump to: