Unexpected Interrupts Triggering

Thread Starter

christakis

Joined Jul 30, 2019
9
Hello Everyone,

I'm having some trouble with interrupts triggering unexpectedly when operating a relay, presumably due to some noise or bluntly put bad/poor circuit design due to lack of experience. Any help to resolve this is greatly appreciated. Detailed explanation below.

I'm trying to make my existing house alarm system 'smart' using an ESP32 based dev board. The idea is to read SET indication (know when the alarm is armed/disarmed) and monitor when the BELL (Siren) triggers off my alarm control panel and send the status of these inputs to my phone . I've configured the inputs as interrupts rather than "constantly read" signals for stand-by mode future proofing. Finally, I can remotely arm, disarm or stop an alarm though a Remote Key Switch (RKS) feature again through the phone.

The interrupt of the SET signal used to behave as expected, triggering only once, as expected both when going HIGH or LOW.

The BELL interrupt was a little more problematic as it was associated with a relay and triggered a few times for each change. I assumed that was a result of the relay contacts debouncing so I dealt with that problem through software via time-barring the interrupt. Okay so far.

The problem I'm having now though, is when I operate the RKS relay I see both the SET and BELL interrupts trigger several times without any real reason to do so. The BELL signal more so than the SET signal.

I attach a schematic of my current circuit for your review. Any obvious ideas on what would cause this behavior? I'm hoping it's something blaring obvious but open to any suggestions.

Let me know if you have any queries, comments or improvement suggestions on the rest of the circuit (as simple or complex as they may be).

Thanks in advance,
Christakis
 

Attachments

Thread Starter

christakis

Joined Jul 30, 2019
9
Unfortunately I only have 100pF unpolarised caps. I'll try and get some tomorrow to give it a go and get back to you.
 

JohnInTX

Joined Jun 26, 2012
4,787
You probably want to add catch diodes across the coils of the relays. Any time you turn off a coil like that, it will generate a nasty spike often many times the supply voltage. 1N4001 - 1N400x will do it, banded end to to the + supply.

If the contacts are switching inductive loads, consider a snubber across the contacts to suppress arcing or if possible a catch diode across that load.

You don't show a PCB layout but the relay coil circuit should not share power or ground runs with the processor. Return each to the power supply with its own pair of wires. Decouple the power supply where they all meet.

You might consider using optos for the interface to the alarm system. Phototransistor or MOSFET outputs should handle switching.

You might want to reconsider using interrupts for edge detecting, they're fast and won't reject glitches like polling will. If you want a wake-on-change function, use the interrupt to wake it up then resume polling, noise rejection from there. If noise hits, the damage is limited to running the processor a bit then sleeping it again.

The .pdf describes suppressing the spikes with diodes and optional zeners.
Good luck!
 

Attachments

Last edited:

Thread Starter

christakis

Joined Jul 30, 2019
9
You probably want to add catch diodes across the coils of the relays. Any time you turn off a coil like that, it will generate a nasty spike often many times the supply voltage. 1N4001 - 1N400x will do it, banded end to to the + supply.

If the contacts are switching inductive loads, consider a snubber across the contacts to suppress arcing or if possible a catch diode across that load.

You don't show a PCB layout but the relay coil circuit should not share power or ground runs with the processor. Return each to the power supply with its own pair of wires. Decouple the power supply where they all meet.

You might consider using optos for the interface to the alarm system. Phototransistor or MOSFET outputs should handle switching.

You might want to reconsider using interrupts for edge detecting, they're fast and won't reject glitches like polling will. If you want a wake-on-change function, use the interrupt to wake it up then resume polling, noise rejection from there. If noise hits, the damage is limited to running the processor a bit then sleeping it again.

The .pdf describes suppressing the spikes with diodes and optional zeners.
Good luck!
Many thanks for the further tips. I will add the diodes and decouple the supplies. The latter is a bit of a novel concept for me; I work in the HV electricity industry and it's embedded in our brains that EVERYTHING should be grounded at the same potential, hence my reasoning of coupling the grounds. We don't like 'floating' circuits.

I know the G2RL is an overkill and looking to replace that with a suitable opto but I prefer to use a latching relay for the R6KS as I want to be able to preserve both states with no power for long periods.

Re interrupts, I currently kind-of use a hybrid method. The interrupt only updates status flags and the main program 'polls' the signals based on the flags. What you say makes sense but I need to see how this plays with the power stand-by philosophy when I get round it.
 

JohnInTX

Joined Jun 26, 2012
4,787
The latter is a bit of a novel concept for me; I work in the HV electricity industry and it's embedded in our brains that EVERYTHING should be grounded at the same potential, hence my reasoning of coupling the grounds. We don't like 'floating' circuits.
It doesn't necessarily mean that one side has to float. The two systems, alarm and your board, can still be referred back to ground but the connection will be way back at the power source and not running around on the boards. You can probably get away with careful power routing such that the noisy relay loads are not powered by the same wiring that powers the processor and logic but optos relieve you of things like ground offsets, ground noise etc.

I've done a lot of stuff like this and that's what I've adopted over the years which is where the interrupt advice comes from as well.

But give it a whirl and let us know how you're getting along.

Welcome to AAC BTW.
 

Thread Starter

christakis

Joined Jul 30, 2019
9
It doesn't necessarily mean that one side has to float. The two systems, alarm and your board, can still be referred back to ground but the connection will be way back at the power source and not running around on the boards. You can probably get away with careful power routing such that the noisy relay loads are not powered by the same wiring that powers the processor and logic but optos relieve you of things like ground offsets, ground noise etc.

I've done a lot of stuff like this and that's what I've adopted over the years which is where the interrupt advice comes from as well.

But give it a whirl and let us know how you're getting along.

Welcome to AAC BTW.
Thanks and I will do! I understand what you mean about the circuit supplies.
 

Thread Starter

christakis

Joined Jul 30, 2019
9
Just spent some fruitless time trying to find their respective ESR performance,
no luck so far.......I am losing my marbles, components with no specs in their
datasheets.......


Regards, Dana.
AH! Don't worry, I went for the cheap ones for now and will revisit later if necessary.
 

Thread Starter

christakis

Joined Jul 30, 2019
9
Hello everyone, just a bit of an update to say a big thank you for your help. All your tips have really made the difference and the circuit is now working like a charm! Both hardware and software performing as expected so really appreciate your help!

Summary of tips for future reference if anyone is having the same/similar problems:
1.) Added decoupling capacitors to power supply, 0.1uF and polarised 10uF in parallel to power supply. - Thanks Xavier drc_567 & and danadak!
2.) Added 10k pull down resistors to transistors bases. - Thanks Xavier!
3.) Added catch diodes across relay coils (banded end to to the + supply). - Thanks JohninTX!
4.) Changed relays to photo-couplers where possible - Thanks JohninTX!
5.) Uncoupled supplies grounds. - Thanks JohninTX!
 

TeeKay6

Joined Apr 20, 2019
573
Just spent some fruitless time trying to find their respective ESR performance,
no luck so far.......I am losing my marbles, components with no specs in their
datasheets.......


Regards, Dana.
@danadak
The Aerovox TAP series data sheet shows ESR=2ohms for 10uF/35V.
The Kemet datasheet link also gives ESR=2Ω.
 

BobaMosfet

Joined Jul 1, 2009
2,110
Hello Everyone,

I'm having some trouble with interrupts triggering unexpectedly when operating a relay, presumably due to some noise or bluntly put bad/poor circuit design due to lack of experience. Any help to resolve this is greatly appreciated. Detailed explanation below.

I'm trying to make my existing house alarm system 'smart' using an ESP32 based dev board. The idea is to read SET indication (know when the alarm is armed/disarmed) and monitor when the BELL (Siren) triggers off my alarm control panel and send the status of these inputs to my phone . I've configured the inputs as interrupts rather than "constantly read" signals for stand-by mode future proofing. Finally, I can remotely arm, disarm or stop an alarm though a Remote Key Switch (RKS) feature again through the phone.

The interrupt of the SET signal used to behave as expected, triggering only once, as expected both when going HIGH or LOW.

The BELL interrupt was a little more problematic as it was associated with a relay and triggered a few times for each change. I assumed that was a result of the relay contacts debouncing so I dealt with that problem through software via time-barring the interrupt. Okay so far.

The problem I'm having now though, is when I operate the RKS relay I see both the SET and BELL interrupts trigger several times without any real reason to do so. The BELL signal more so than the SET signal.

I attach a schematic of my current circuit for your review. Any obvious ideas on what would cause this behavior? I'm hoping it's something blaring obvious but open to any suggestions.

Let me know if you have any queries, comments or improvement suggestions on the rest of the circuit (as simple or complex as they may be).

Thanks in advance,
Christakis
Considerations (even though it's now working). I'm just going by the originally posted schematic.

Look at your schematic. Look at how you have the 2N2222 wired. That is wrong. You do NOT put a resistor on the emitter. This is a common-emitter design. The emitter MUST be tied to ground. By putting a resistor on Ground, you're creating a ground-loop, and elevating the ground level on your 'pinSet'. You're pinset needs a resistor in series with it. To limit the input to your MCU on that pin to 1mA. 1mA is sufficient to deal with virtually all noise situation you'll likely encounter, without drawing too much current.

Couple of things. Figure out how much current 'Ic' (collect current) you're going to put through the 2N2222. Then set your base resistor (Rb) appropriately- don't just set it to a random 10K, that's wrong. Gain on this transistor, depending on what you're trying to do is 30 to 300 times the current on the base (Ib), per the Datasheet. Vbe is is variable, but usually you can go with ~6-7mA.

Lastly- You need a resistor as a pull-down on your base (that is on the order of 100K Ohm). You just want something to weakly pull the base to ground to keep the BJT zeroed, not using too much current to do so when the MCU pin on the base is low (unpowered), and easily overcome by the MCU pin when it's high.
 

cmartinez

Joined Jan 17, 2007
8,220
Hello everyone, just a bit of an update to say a big thank you for your help. All your tips have really made the difference and the circuit is now working like a charm! Both hardware and software performing as expected so really appreciate your help!

Summary of tips for future reference if anyone is having the same/similar problems:
1.) Added decoupling capacitors to power supply, 0.1uF and polarised 10uF in parallel to power supply. - Thanks Xavier drc_567 & and danadak!
2.) Added 10k pull down resistors to transistors bases. - Thanks Xavier!
3.) Added catch diodes across relay coils (banded end to to the + supply). - Thanks JohninTX!
4.) Changed relays to photo-couplers where possible - Thanks JohninTX!
5.) Uncoupled supplies grounds. - Thanks JohninTX!
Good as all the changes you've made are, I strongly suggest you add the following circuit to your circuit's power input. Believe me, I've been where you are, and done everything you've mentioned. And in some cases it still wasn't enough, specifically those in which switching inductive loads were involved. BTW, the larger the cap, the better. The 4,700 uF value is the bare minimum I suggest.

upload_2019-7-30_17-4-12.png
 
Last edited:

TeeKay6

Joined Apr 20, 2019
573
Considerations (even though it's now working). I'm just going by the originally posted schematic.

Look at your schematic. Look at how you have the 2N2222 wired. That is wrong. You do NOT put a resistor on the emitter. This is a common-emitter design. The emitter MUST be tied to ground. By putting a resistor on Ground, you're creating a ground-loop, and elevating the ground level on your 'pinSet'. You're pinset needs a resistor in series with it. To limit the input to your MCU on that pin to 1mA. 1mA is sufficient to deal with virtually all noise situation you'll likely encounter, without drawing too much current.

Couple of things. Figure out how much current 'Ic' (collect current) you're going to put through the 2N2222. Then set your base resistor (Rb) appropriately- don't just set it to a random 10K, that's wrong. Gain on this transistor, depending on what you're trying to do is 30 to 300 times the current on the base (Ib), per the Datasheet. Vbe is is variable, but usually you can go with ~6-7mA.

Lastly- You need a resistor as a pull-down on your base (that is on the order of 100K Ohm). You just want something to weakly pull the base to ground to keep the BJT zeroed, not using too much current to do so when the MCU pin on the base is low (unpowered), and easily overcome by the MCU pin when it's high.
@BobaMosfet
There is nothing inherently wrong with the original 2N2222 hookup. It is a common collector (aka emitter follower) config, not a common emitter config. Note1 of the schematic indicates that SET_SIGNAL has two states: 0V and 12V. When SET_SIGNAL=0V, the 2N2222 provides no current through the 330ohm resistor to ground and thus pinSet=0V. When SET_SIGNAL=12V, current through the 10K resistor will saturate the 2N2222, causing the emitter voltage to be very slightly less than the collector voltage (3.3V); this emitter voltage will be applied to pinSet and is an acceptable level for most microcontroller logic inputs. pinSet will not be driven higher than 3.3V (and in any case most logic inputs accept up to at least +0.3V overdrive, 3.6V).
 
Top