1

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:

schematic

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:

schematic

simulate this circuit

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!

  • You could try; lowering the pull-up resistor. Moving the button away from the boost converter and it's wires. Move the pull-up nearer to pin 2. Use a pull-down system (by swapping R1 and SW1), instead of pull-up. PS the capacitor isn't used for decoupling here, but as a low-pass-filter. – Gerben Dec 27 '15 at 13:58
  • Why would a pull-down system have more noise immunity than a pull-up system? – Alex H Dec 27 '15 at 22:38
  • I'm not sure if it would, but might be worth a try. – Gerben Dec 29 '15 at 14:27
0

If you don't have any bulk capacitance (100uF or so) on your logic supply you will have noise problems. You should also use some smaller (1uF and 0.1uF) to provide bypass for higher frequency noise in the power supply system.

Glenn

-1

An alternative approach is to detach the interrupt handler and use the internal pullup instead of external resistor (and capacitor).

const int BUTTON = 2;
volatile bool flashConverage = false;

void setup() 
{
  setmode(BUTTON, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(BUTTON), displayConvergence, FALLING);
}

void loop() 
{
  if (!flashConvergence) return;

  // Do stuff that takes several seconds 
  delay(3000);
  flashConvergence = false;
  attachInterrupt(digitalPinToInterrupt(BUTTON), displayConvergence, FALLING);       
}

void displayConvergence() 
{
  detachInterrupt(digitalPinToInterrupt(BUTTON));
  flashConvergence = true;
}

The processing ("stuff that takes several seconds") will debounce the button (or at least ignore it :).

Cheers!

  • The problem isn't (only) switch bounce. It's false triggers. This code won't help with that. – Gerben Dec 27 '15 at 13:53
  • Well we have provided a few solutions to test. I do agree that the noise from the Converter might be the issue. Moving the 100 uF capacitor to filter noise on the power (5V) might also help. – Mikael Patel Dec 27 '15 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.