Possible mains interference on PCF8574 inputs

The circuit below is used to monitor the inputs of 8 switches.

However I have used standard shielded alarm 8 core cable to connect the switches which has been placed in the same plastic pipe as the single core mains cables. In other words it travels about 10m along the mains cables, in parallel.

[Now, this is a bad practice and also violates electricity wiring rules (low voltage cables in the same conduit as mains cabling), however I did it since there was no other choice!]

Now, apparently I am experiencing spontaneous, ie erratic readings on the output of the PCF chip. Some switches are wrongly detected to be spontaneously on. I am therefore suspecting that this is due to mains interference.

Please note that nearby mains cabling only carry very low currents for LED lighting, ie less than 0.2A and most times is even zero. Erratic operation happens regardless however.

In order to improve operation, I am now thinking to solder 0.1nf- 1uF caps across each of the diodes in the circuit.

  1. What do you think of my diagnosis above?
  2. Do you anticipate that adding the caps this will have any benefit?
  3. Can you suggest anything else?

Thanks !

I may assume there's a ninth wire - the ground return - to the switches? You don't mention this nor have it in your schematic.

10m is a long wire to pick up interference. Capacitors can help a lot - 100 nF is normally more than enough for that. Stronger pull-ups help as well, I see you already have 4k7 there. You may lower that value even more, to 2k2 or even 1k.

I may assume there's a ninth wire - the ground return - to the switches? You don't mention this nor have it in your schematic.

Yes the ground is of course connected as a common. In fact not all 8 inputs switches are required so i use the 8th wire as ground.

I will try the cap solution.
Even considering replacing the alarm cable with cat5 twisted pair..although is not an easy task

By the way diodes shown are zeners 5.1V.

The strange thing is that the setup above worked fine for about a month and only now i am experiencing this problem!

What if i were to increase the input resistors from 200R to say 1k in conjuction with the 100nf caps and leave pullups at 4k7?

What is the function of those zeners? It doesn't look useful to me. If you're afraid of spikes, use Schottky diodes as clamping diodes.

The input resistors should not be too large, as they form a voltage divider with the pull-up resistor, lowering the voltage at the pin.

What is the function of those zeners?

Yes the idea was for overvoltage protection.

Wrong component (no protection against negative spikes), wrong wiring.
You need two diodes, one to Vcc, one to GND. Here some more discussion on the subject.

In addition to the diodes you need to add capacitors from the input to ground as close to the IC as possible / practical.

Although you have a pretty good current going to the switches, such a long distance where coupling to the mains will cause significant pickup you still need some low pass filtering at the IC.

What is not clear by your schematic is the routing of the ground for the 8 inputs. There could be more corruption of the input signals if the switch ground is also subject to pickup in your conduit.

What is not clear by your schematic is the routing of the ground for the 8 inputs. There could be more corruption of the input signals if the switch ground is also subject to pickup in your conduit.

The ground is just one of the wires in the multicore cable and in addition the cqble shield is also grounded.

Although you have a pretty good current going to the switches, such a long distance where coupling to the mains will cause significant pickup you still need some low pass filtering at the IC.

What do you recommend?

What do you recommend?

Unless you need very fast response from you inputs, I would start with 0.1µF.

I won't comment about signal and mains in the same conduit, but if you could change the signal wires, I would suggest:

  1. Best foil shielded
  2. next woven shielded
  3. last twisted

When shielded: don't use the shield as conductor, instead connect it on one and only one side to ground. That gives the best possible shielding.

wvmarle:
The input resistors should not be too large, as they form a voltage divider with the pull-up resistor, lowering the voltage at the pin.

That is of course because they are wired wrongly.

The pull-ups go on the cable (switch) side of the series resistors. The series resistors - which are mounted close to the microcontroller - can be quite a high value - 10k or more. The diodes and capacitors go on the microcontroller side of the series resistors.

The point of protection diodes is to prevent voltages below about -0.3 or above Vcc+0.3V reaching the
pins of the chip. Vcc varies, its 0V when the chip is powered down but the protection should still work,
which is why schottky diodes to GND/Vcc are typically used, with a current limiting resistor to protect the
schottkys. Using 50 to 220 ohm series resistors also soaks up reflections on the wires, which is why such
values are typically used - especially for clocking signals where a double pulse would cause malfunction.

For low bandwidth signals all you actually need is a 10k series resistor and small cap to ground 10nF or 100nF,
the 10k resistor fully protects against spikes(*), the capacitor prevents RF and noise affecting the signal. Any
pull-up should be directly to the incoming wire before such a large series resistor.

(*) Protection diodes can handle a fraction of a mA OK, and unless you have a very rare CMOS chip with no protection diodes its inputs, this is the simplest protection for slow signals.

I won't comment about signal and mains in the same conduit, but if you could change the signal wires, I would suggest:

  1. Best foil shielded
  2. next woven shielded
  3. last twisted

Thanks for the info.

The signal cable is of the woven shielded type (copper wire shield)
Therefore there is no point in replacing the cable with cat5 twisted pair unless its of the STP type.

Using 50 to 220 ohm series resistors also soaks up reflections on the wires, which is why such
values are typically used - especially for clocking signals where a double pulse would cause malfunction.

Thats why I had the 220R series resistors but I understand that you are saying that the pullups should come before (from the switches side) the series resistors.

For low bandwidth signals all you actually need is a 10k series resistor and small cap to ground 10nF or 100nF,the 10k resistor fully protects against spikes(*), the capacitor prevents RF and noise affecting the signal.

Bit confused now. Is this 10k resistor instead of the 220R mentioned earlier?

When shielded: don't use the shield as conductor, instead connect it on one and only one side to ground. That gives the best possible shielding.

Thanks. Thats exactly what i did.

Update: I have now installed 100nF caps across each of the diodes.
The performance has dramatically improved.

I might still be getting a couple of triggers that shouldn't have been there, although I am not 100% sure if these were not legitimate operations.

So is this now the proposed schematic?

(caps across all diodes of course)

That looks about right to me.
Those zeners are not needed - if you want to protect against spikes you can do two things.
a) replace the 220R resistors by 10k ones, and let the Arduino's clamping diodes take care of it, normally this will do the job just fine.
b) add two Schottky diodes - one between signal and Vcc, the other between signal and GND.

For the remaining spurious readings: these are likely to be very short (a few milliseconds) and therefore easy to distinguish from a human pressing the button (who will struggle to press it for shorter than 100 ms). Modified debouncing should actually take care of most of those spikes: instead of ignoring presses for 50 ms or so after the first falling edge, register the button press only when it's been pressed for at least 50 ms. Of course that does mean your button has that long a reaction time after being pressed but you're not likely to notice this (50 ms is a very short time for a human).

a) replace the 220R resistors by 10k ones, and let the Arduino's clamping diodes take care of it, normally this will do the job just fine.

Remember that these inputs are connected to a port expander PCF8574, not the arduino μC.
Not sure if the PCF has input clamp diode... although there is a reference for "input diode clamp voltage" in the datasheet.
Thats why I installed zeners just in case...

See p.12 of [ur=http://www.ti.com/lit/ds/symlink/pcf8574.pdf]the data sheet[/url]: clamping diodes are there.