So there is this pretty generic part of my project that involves triggering an ISR that will flip a boolean value. I have set up the software side like so:
void setup() {
attachInterrupt(digitalPinToInterrupt(2), displayConvergence, FALLING);
}
void loop() {
if(flashConvergence) {
//Do stuff that takes several seconds
delay(3000);
flashConvergence = false;
}
}
void displayConvergence() {
if (!flashConvergence) {
flashConvergence = true;
}
}
The schematic is as follows:
simulate this circuit – Schematic created using CircuitLab
But the behavior of my circuit surprised me as the pin interrupt would get triggered randomly at a frequency at (guessing here) 3 times a second.
Weird, I thought. I fiddled around and found that when the boost converter's 180V is not connected to any load, the interrupt service triggers as expected, as in it starts working correctly. So I thought perhaps the issue was some noise introduced by the boost converter.
I modified the circuit by adding a capacitor across the switch:
I tried 1 uF at first, but that didn't help and neither did 10 uF. However, when I tried 100 uF (I thought decoupling capacitors are usually 0.1uF to 1 uF, is the value I am using too big?), things seem to be working as expected with the exception that when I hold the switch in the closed position for a long time, then let it go back in the open position, the interrupt service can be triggered randomly for a short period right after I let go of the switch.
Is my initial assumption that the ISR is triggering randomly due to EMI from the boost converter correct? Perhaps there are other causes I am not looking at? Is there a way to make this work 100% (as in solve the issue right after the switch is put in the open position)?
Thanks for the help!