Interrupt external signal noisy

What i can do for have less noise in the interrupt pins(2 and 3) of an Arduino Uno attached to pushbuttons?
Insteed of one interrupt each push I get a train of that (2, 3 or more).
I put the 10kohm resistor to 5v and the pushbutton tho ground as in the circ-07 ...
maybe i can put a condenser (but i don't know the value)? i tried alredy with delay (as in the program attached) but i did'n get important resoult.

int speackerPin = 11;
int ledpin = 13;
int ledpin1 = 12;
volatile int Stato = 900;

void setup() {
pinMode(ledpin, OUTPUT);
pinMode(ledpin1, OUTPUT);
pinMode(speackerPin, OUTPUT);
attachInterrupt(0, Cambia, RISING);
attachInterrupt(1, Cambia1, RISING);
Serial.begin(9600);
}
void loop() {
for (long i = 0; i<100; i = i + 1) {
digitalWrite(speackerPin, HIGH);
delayMicroseconds(Stato); // 1136 nota La
digitalWrite (speackerPin, LOW);
delayMicroseconds(Stato);
}
digitalWrite(ledpin, HIGH);
delay(100);
digitalWrite (ledpin, LOW);
delay(100);
digitalWrite(ledpin1, HIGH);
delay(100);
digitalWrite (ledpin1, LOW);
delay(100);
Serial.println(Stato);
}

void Cambia() {
Stato = Stato - 30;
detachInterrupt(0);
delay(1000);
attachInterrupt(0, Cambia, RISING);
}

void Cambia1() {
Stato = Stato + 30;
detachInterrupt(1);
delay(1000);
attachInterrupt(1, Cambia1, RISING);
}

Please help
Grazie

I put the 10kohm resistor to 5v and the pushbutton tho ground as in the circ-07 .

Yes well you can do it properly instead.

The button goes between the input and ground and the pull up from input to +5V.
This means you can make the pull up resistor lower, in your case try 1K.
Also putting a 0.1uF cap across the input would help as well.

Grazie Grumpy_Mike!
I'll try (i have to go buy the 1kohm resistors and 0.1uF condensers).
by software i think that there is no something else i can try, right?

Because the signal is generating an interrupt then it is best dealt with before the interrupt is triggered. However you could try and look at the pin in the ISR to see if the transient is short and if it is abandon the ISR. But I would not recommend this as you do tie up a lot of CPU time in an ISR unnecessarily, which is not a good idea.

marcodefilippis:
Grazie Grumpy_Mike!
I'll try (i have to go buy the 1kohm resistors and 0.1uF condensers).
by software i think that there is no something else i can try, right?

The interrupt will be generated by the contact bounce, no matter what. However, you can look at "time since last interrupt" and just ignore it if it's less than, say, 50 milliseconds.

Also: why would a 10k pull-up not be sufficient for driving a digital input pin? I thought they were high impedance?

why would a 10k pull-up not be sufficient for driving a digital input pin?

I never said it would not be sufficient to drive a digital pin, but 1K is better for noise immunity which is the OP's problem.

The interrupt will be generated by the contact bounce, no matter what. However, you can look at "time since last interrupt" and just ignore it if it's less than, say, 50 milliseconds.

Yes that is what I said.

marcodefilippis:
I'll try (i have to go buy the 1kohm resistors and 0.1uF condensers).
by software i think that there is no something else i can try, right?

The internal pull-up is likely to be suffcient and so no need to use external resistor/cap at all if you use the following techinque:

Disable the pin-interrupt from within the ISR and then reenable it in your loop after a few milliseconds. The first button press will register whereas subsequent pin toggles will be ignored until re-enabled by your sketch. Save a copy of millis to a global variable in the ISR and use this as a button press indicator and base time for when to re-enable.

Disable the pin-interrupt from within the ISR and then reenable it in your loop after a few milliseconds.

Good in theory but how does the loop know that the ISR has been triggered. It would have to look at the interrupt enable bit but even then it would have no idea on how long it was since it was triggered.
It is much better to cure the problem at source rather than try and put sticking plaster software over it.

Well, the real right way to do this at the switch would be to debounce the close as well as the open of the contacts and do a few calculations based on the device specs. The attached schematic works very reliably on an Arduino and takes into account the Atmega328 logic low and logic high thresholds and assumes a bounce time of 20ms or less.

debounce.jpg

Grumpy_Mike:
Good in theory but how does the loop know that the ISR has been triggered. It would have to look at the interrupt enable bit but even then it would have no idea on how long it was since it was triggered.
It is much better to cure the problem at source rather than try and put sticking plaster software over it.

The loop will know the ISR triggered from you saving a copy of millis in the ISR to a global variable (value <> zero). In the loop you calculate the difference of millis and this global variable to determine when to re-enable. Set the variable to zero when you’re done.

It is much better to cure the problem at source rather than throw useless hardware at it. :wink:

Different schools, different solutions.

The loop will know the ISR triggered from you saving a copy of millis in the ISR to a global variable (value <> zero).

Get a grip.
It will only know this if you make this copy of millis() and check it often enough that you defeat the point of having an ISR in the first place.

The ISR is there to make sure you never miss a key-press make event. Required key-press response time defines the minimum loop time which is quite modest for manual input in microcontroller terms. Software de-bouncing is reliable, cost effective and as simple as it gets in terms of digital filtering.

It’s not simply a matter of hardware vs. software, but combining the best of both worlds. The trick is to consider both and know when to apply what. If as a hardware engineer you don’t respect or realize the potential of software engineering, you will be out of business and the reverse is true as well.