Go Down

Topic: Arduino Due fires Interrupt when i get out of my chair or people move in room (Read 7604 times) previous topic - next topic

MaxBlitz

Hi.

I have to check a button with a FALLING interrupt. It works great when the button is pressed. The problem is that when i get up from my chair or move around in the room or close the door, the interrupt will fire too. When i attach the oscilloscope to the interrupt input pin, i see very short peaks during those events. I need to get rid of those interferences, can you please help?

The pin is connected via 10 kOhm resistor to 3.3V (pull-up). I also tried various pull-ups from 470 Ohm to 80 kOhm, with no success.

The button pulls the pin to GND when pressed. Pretty standard setup...

My code:

Code: [Select]
#define SWITCH_1 10
volatile boolean interrupt_occured = false;

void setup() {
Serial.begin(19200);
attachInterrupt(SWITCH_1, switchPressed, FALLING);
}

void loop() {
if (interrupt_occured)
{
Serial.println("Switch pressed");
}
}

void switchPressed()

    interrupt_occured = true;
}

septillion

Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

polymorph

Clearly, that is not all your code.

Have you done this:

Code: [Select]
pinMode(2,INPUT_PULLUP);

Or are you using an external pullup resistor? If so, what value?

What layout are you using? It sounds like you may be picking up static electricity. Are your wires really long? Is the pullup resistor really high value? Try shorter wires, using twisted pair, and a 1k pullup resistor.

We need more information to help you.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

KeithRB

He said he used a 470 ohm pullup, which should be low enough, for sure.

MarkT

A lesson in just how sensitive floating inputs are to ambient static electricity or
capacitive coupling to mains.    And an interrupt pin will detect pulses as short
as a few tens of nanoseconds just to make things worse...
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

MaxBlitz

Clearly, that is not all your code.

Have you done this:

Code: [Select]
pinMode(2,INPUT_PULLUP);

Or are you using an external pullup resistor? If so, what value?

What layout are you using? It sounds like you may be picking up static electricity. Are your wires really long? Is the pullup resistor really high value? Try shorter wires, using twisted pair, and a 1k pullup resistor.

We need more information to help you.
Thanks for the reply, but read my initial post. I am using an external pull-up resistor. I tried varioius values (for example: 470 Ohm, 1 kOhm, 5.6 kOhm, 10 kOhm, 18 kOhm, 33kOhm, 82kOhm). Did not solve the problem.

I attached the button to 2m of wire and on an other experiment just a couple of centimeters of wire directly at the breadboard. Did not solve the problem either.

Btw: That is all of my code. I dont think you need more for an interrupt.

MaxBlitz

A lesson in just how sensitive floating inputs are to ambient static electricity or
capacitive coupling to mains.    And an interrupt pin will detect pulses as short
as a few tens of nanoseconds just to make things worse...
Is there a technical (maybe hardware) solution to filter this ultra-short static pulses? I have some serious equipment and electronic parts here, so i could built some circuits if that helps...

polymorph

This is what I get for reading 6 threads at the same time...  :smiley-red:

I'd be using some form of anti-bounce.

In hardware, this could be just a 0.01uF capacitor from the input pin to ground.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

dlloyd

This hardware filter will provide a 10ms fall, 20ms rise filter that will make the D10 interrupt input immune to noise and AC signal pickup.

Time Constant Calculator

Note that alternatively, with some register level programming of the D10 input, the hardware debouncing feature in the SAM3X can be used.

Note that there is a difference as to how a typical debouncer and a filter work:
A debouncer will respond instantaneously to a signal transition then have a time-out interval.
A filter slows the rise and fall time of the signal.
The average response time for a person to react and press a button is around 1/4 second.

nickgammon

Please post technical questions on the forum, not by personal message. Thanks!

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

polymorph

dlloyd's solution looks like a good one to try. I also use twisted pair if going any distance.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

MaxBlitz

This hardware filter will provide a 10ms fall, 20ms rise filter that will make the D10 interrupt input immune to noise and AC signal pickup.

Time Constant Calculator

Note that alternatively, with some register level programming of the D10 input, the hardware debouncing feature in the SAM3X can be used.

Note that there is a difference as to how a typical debouncer and a filter work:
A debouncer will respond instantaneously to a signal transition then have a time-out interval.
A filter slows the rise and fall time of the signal.
The average response time for a person to react and press a button is around 1/4 second.
Hey Thanks!

Your circuit works very good in my firt test. It only triggered one false positive and that was when i touched the door handle nearby and got zapped bystatic electricity ( I did not have physical contact with any part of the circuit at that point, so it mustve transmitted through the air).

I had another circuit used in hardware debouncing of interrupts by Jeremy Blum using an inverted schmitt trigger and an rc circuit. This reduced the bouncing but didnt help with the eletrostatic noise / false positives whatsoever.

MaxBlitz

That was the circuit i used before (only the lowest of the 3 depictured):


dlloyd

Quote
Hey Thanks!

Your circuit works very good in my firt test. It only triggered one false positive and that was when i touched the door handle nearby and got zapped bystatic electricity ( I did not have physical contact with any part of the circuit at that point, so it mustve transmitted through the air).
As per your Thomas Edison quote, an improvement might be to add 1K series resistance in the ground wire to the switch and clhange the capacitor to 2.2µF.

MaxBlitz

As per your Thomas Edison quote, an improvement might be to add 1K series resistance in the ground wire to the switch and clhange the capacitor to 2.2µF.

Haha, yeah you got me on that one...can you please explain why the change of the capacitor and the resistor should bring improvement? I am not from an electronics background.

Go Up