Interrupts being triggered by AC Load when pull resistor is connected

pranav
Posts: 6
Joined: Mon Jun 05, 2017 9:41 am

Interrupts being triggered by AC Load when pull resistor is connected

Postby pranav » Tue Jul 25, 2017 8:36 am

Hello everyone.
I am facing a very troubling issue here.
I use a very simple code that has an interrupt attached to a button, and toggles the state of the relay when an interrupt is fired on the button.
To debounce the button, I have tried using both external and also internal pulldowns/pullups

The interesting/troubling issue I am having is, when there is a pull resistor in place, (internal or external) , whenever I plug something into a nearby AC source or switch on/off a plugpoint, an interrupt is being triggered.

If I do not add a pull resistor, the AC does not interfere, but obviously there are loads and loads of random interrupts being fired . I do have a software debounce in place that does not process false interrupts, but there are too many interrupts being fired and it is not a good behaviour.

So tl;dr with pull resistor, AC load triggers interrupt , and I wanted to know if anyone else had faced or know any solutions for this.
I am posting the code I have used here below.

Code: Select all

#define BUTTON 16
#define RELAY  17

volatile unsigned long int interrupt,last_interrupt = 0;
volatile bool state = 0, change = 0;

void IRAM_ATTR buttonPressHandler(){
  interrupt = millis();
  if(interrupt - last_interrupt > 200){
    state = !state;
    digitalWrite(RELAY, state);
    change = 1;
  }
  last_interrupt = interrupt;
}

void setup(){
  Serial.begin(115200);

  pinMode(BUTTON,INPUT_PULLUP);
  attachInterrupt(BUTTON, buttonPressHandler, RISING);

  pinMode(RELAY, OUTPUT);
  digitalWrite(RELAY, state);
}

void loop(){
  if(change){
    Serial.println("Set relay to : " + String(state));
    Serial.println("Last ISR at : " + String(last_interrupt));
    change = 0;
  }
}


ESP_Sprite
Posts: 9772
Joined: Thu Nov 26, 2015 4:08 am

Re: Interrupts being triggered by AC Load when pull resistor is connected

Postby ESP_Sprite » Tue Jul 25, 2017 10:24 am

Fyi, a pullup or pulldown does not debounce a button, you need an extra capacitor for that. That being said, AC load triggering signals usually is because your input line is too high-impedant. What value of pullup do you use?

pranav
Posts: 6
Joined: Mon Jun 05, 2017 9:41 am

Re: Interrupts being triggered by AC Load when pull resistor is connected

Postby pranav » Tue Jul 25, 2017 11:32 am

ESP_Sprite wrote:Fyi, a pullup or pulldown does not debounce a button, you need an extra capacitor for that. That being said, AC load triggering signals usually is because your input line is too high-impedant. What value of pullup do you use?
Hi.
I didn't know that we needed a capacitor too. I used the connection shown as per image here
Also, i use a 10K resistor to pull.

I've also tried using the internal pull (as shown in code above) , when I use internal, I don't attach anything else to button. I believe the internal pulls are also 10k ?

I've also tried using a simple RC Low pass filter with cutoff 49 Hz and also a high pass filter with cutoff 72 Hz (50 Hz supplies here, I'm not an electrical engineer, so not experienced but I assume the noise coming from ac load would also be 50 Hz) Both did not work. So I must've done something conceptually wrong.

Is there anything I can do to prevent the ac triggers?

ESP_Sprite
Posts: 9772
Joined: Thu Nov 26, 2015 4:08 am

Re: Interrupts being triggered by AC Load when pull resistor is connected

Postby ESP_Sprite » Tue Jul 25, 2017 11:46 am

10K is still on the high side: it will work but is pretty high-impedant. Suggest changing that to e.g. 1K or even 470 ohm and your problems should disappear if the AC load EMC isn't crazy-bad.

pranav
Posts: 6
Joined: Mon Jun 05, 2017 9:41 am

Re: Interrupts being triggered by AC Load when pull resistor is connected

Postby pranav » Tue Jul 25, 2017 12:16 pm

ESP_Sprite wrote:10K is still on the high side: it will work but is pretty high-impedant. Suggest changing that to e.g. 1K or even 470 ohm and your problems should disappear if the AC load EMC isn't crazy-bad.
Thank you. I appreciate the help. I will try and get back to you.

tele_player
Posts: 90
Joined: Sun Jul 02, 2017 3:38 am

Re: Interrupts being triggered by AC Load when pull resistor is connected

Postby tele_player » Wed Jul 26, 2017 1:43 am

Is the assumption that this is caused by electromagnetic interference, and NOT by noise or sag in the power line?

brocas
Posts: 2
Joined: Mon Jul 31, 2017 3:17 am

Re: Interrupts being triggered by AC Load when pull resistor is connected

Postby brocas » Mon Jul 31, 2017 3:36 am

I have very similar issues only worse.

I built ESP32 AP system, battery operated, in a metal box.

If in the vacinity, I turn on an appliance, eventually something fails in the esp32. Most sensitive is the I2C interface. The serial interface also fails. Ocasionally WIFI fails too.

It does not matter the appliance, some are worse than others. First time I noticed through the make monitor serial interface that it dropped the connection at the exact time I turned my soldering iron on, I have been chasing this issue ever since. I am not a novice when it comes to EMI issues, I spent many months locked in rooms until EMI issue resolved in my long career. My prognosis so far is the the ESP32 is extremely susceptible to EMI. I have never seen a product so sensitive as this. If you put it in a metal box and ground the box, any small load on the same circuit branch will cause failure. Even dropping a battery in the box and disconnecting the live and neutral, leaving only the ground wire will cause failures.

It may turn out that there is some subsystem that is the culprit, but at this time I'm struggling to make any progress whatsoever.

ESP_Sprite
Posts: 9772
Joined: Thu Nov 26, 2015 4:08 am

Re: Interrupts being triggered by AC Load when pull resistor is connected

Postby ESP_Sprite » Mon Jul 31, 2017 6:31 am

Brocas: That may be a different issue, and your post contains not much info that we as engineers can use to replicate the issue. What hardware are you using (devboard, type of power supply / battery / ...) and do you have code and/or a setup we can use to replicate the issue?

brocas
Posts: 2
Joined: Mon Jul 31, 2017 3:17 am

Re: Interrupts being triggered by AC Load when pull resistor is connected

Postby brocas » Tue Aug 01, 2017 7:30 am

I was not looking for help, merely letting the OP know that the issue he sees is not unusual (my system is extremely sensitive to AC mains transients even when completely isolated using battery power, indicating radiated EMI). OP's issue may simply be power supply issues due to the AC load switching. But it may also be EMI issue (as in my case).

All systems have EMI susceptibility, some more than others. I have noticed that the particular system I'm using that includes ESP32 is very sensitive to EMI, in particular I see that the I2C interface is the most sensitive of the ESP32 (at least the sections I am using). This is not surprising since the I2C is a major externally exposed interface, and also this interface is susceptible to EMI due to its high impedance design. I have been able to address my issue using ferrite beads, but as usual with EMI "fixes", there is always some uncertainty, was it enough or will the problem re-occur? The issue was particularly critical for me because the I2C interface failed in "lockup" state not merely in transfer errors. This required a complete restart to recover the interface.

For the OP, after you are able to rule out all possibilities with power supply issues i.e use battery power to rule out power supply issues such as droop due to AC transients, and conducted EMI coming from AC mains. Then you are left only with radiated EMI. There is a whole process to solve such issues and you need to familiarize yourself with it. If you are able to solve the problem by lowering impedance on the interrupt I/O that that will be great.

feredy2011
Posts: 10
Joined: Mon Aug 14, 2017 8:47 pm

Re: Interrupts being triggered by AC Load when pull resistor is connected

Postby feredy2011 » Tue Aug 22, 2017 8:25 am

I want use esp32 for 12 channel relay with key.and connect AC load to all channel ! so with this issue , this board is not for industrial use?

Who is online

Users browsing this forum: No registered users and 53 guests