sqrt3
Posts: 9
Joined: Thu Jan 17, 2013 2:52 pm

74HC595 EMC(EMV) problems

Wed Jan 30, 2013 1:15 pm

I'm using a 74HC595 to switch some relays. The input pins of the shift register are directly connected to the GPIO pins of the raspberry. Output pins are directly connected to a ULN2003A which drives the relays. The 74HC595, ULN2003A and seven relays have a separate 5V power source which means that there's no connection to either the 5V or 3.3V rails on the raspberry.
The OE-Pin of the 74HC595 is pulled up via a 4.7k resistor to prevent output while switching on and booting.
The whole setup works very well so far. But if i switch on or off a completely independent power supply or my laser printer starts printing the 74HC595 seems to loose its latch register contents. Almost always most or all bits go to zero. If i connect the power supply to another outlet in the wall (in a different circuit) everything is fine.

What could this be?

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: 74HC595 EMC(EMV) problems

Wed Jan 30, 2013 2:13 pm

Welcome to mains borne interference, (EMI) you need to filter your power supply output to the ULN2803 and 74HC595. The power supply is not rejecting mains noise effectively enough, this causes a dip in the power reseting the 74HC595.

Power supply filter to be at least a large cap of 10uF or larger. OIther types of filter could be used.

Also add a decoupling capacitor on the power rails of the two chips (each chips VCC to GND) as close as possible to the chip. Values of 10n or 100n are quite normal for this.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

sqrt3
Posts: 9
Joined: Thu Jan 17, 2013 2:52 pm

Re: 74HC595 EMC(EMV) problems

Wed Jan 30, 2013 3:00 pm

Thanks for your answer. I thought of this also. 100n capacitors are present near the chips. I also tried to add a 47uF capacitor near the entry point of the power rails on the relay board. Didn't change anything. Even suppling power from a 12V battery to the relay board over a L7805 regulator does not help.

The raspberry in this case is still powered from the mains. Can i power it from the battery bypassing the micro-usb plug (since i don't have one)?

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: 74HC595 EMC(EMV) problems

Wed Jan 30, 2013 4:00 pm

Sounds like the spikes are either coming in through Pi or from some cabling run and proximity.

Yep find a way to supply your Pi in a way that removes the spikes or worst case put transient suppressors on the rails.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

aortiz557
Posts: 2
Joined: Fri Oct 05, 2012 12:29 pm

Re: 74HC595 EMC(EMV) problems

Mon Feb 04, 2013 8:06 pm

do you have the ground from the 74hc595 connected to the ground of the pi? a lot of people forget that you need a common ground.

sqrt3
Posts: 9
Joined: Thu Jan 17, 2013 2:52 pm

Re: 74HC595 EMC(EMV) problems

Tue Feb 05, 2013 2:21 pm

Ground was connected, i did the same experiment with an Arduino, same result. Another attempt was to connect a single 74HC595 to the raspberry on a breadboard with no other parts or power supply involved. The result is even worse. The shift register not only looses it's contents it also does not shift the next few bits correctly. Of course i tried to use another device without success.

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: 74HC595 EMC(EMV) problems

Tue Feb 05, 2013 2:53 pm

Not knowing your circuit, I have a simple question. What is the connection to /MR? My first thought reading your problem description is that the reset is seeing a pulse due to EMI. I would recommend a strong pullup to Vcc.

Enjoy!
Bill

Conner Labs
Posts: 45
Joined: Fri Jan 11, 2013 2:45 pm
Location: Glasgow
Contact: Website

Re: 74HC595 EMC(EMV) problems

Tue Feb 05, 2013 3:10 pm

Do you have a cable between the Pi and the 74HC595? If so, make sure all the conductors are twisted together (a shielded cable is even better, connected to ground at both ends) and you can also try adding a ferrite ring to it.

Brute force solution: Add a RC filter to the 74HC595's clock pin, to reject spikes. Something like 1k and 100pF.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: 74HC595 EMC(EMV) problems

Tue Feb 05, 2013 3:11 pm

I agree with bgreat. It's CMOS, therefore it will fail in mysterious ways if any inputs are left floating, even those that should not matter.

One of the first apocryphal stories I ever got told, when my then boss was just starting out he finished building a CMOS circuit and called his boss over. It stopped working. His boss went away. It started working. In further experimentation they discovered that if the boss stood on carpet tile A it worked, but if he stood on carpet tile B it didn't. The fault was that not all the gates of a quad-NAND were being used, and the inputs of the unused gates were left floating.

Conner Labs
Posts: 45
Joined: Fri Jan 11, 2013 2:45 pm
Location: Glasgow
Contact: Website

Re: 74HC595 EMC(EMV) problems

Tue Feb 05, 2013 3:42 pm

That too... :)

sqrt3
Posts: 9
Joined: Thu Jan 17, 2013 2:52 pm

Re: 74HC595 EMC(EMV) problems

Tue Feb 05, 2013 6:58 pm

I would recommend a strong pullup to Vcc.
I always connected /MR to VCC directly. Concerning the cables. They're breadboard like which means of course nothing twisted. I'll give that a try.

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: 74HC595 EMC(EMV) problems

Tue Feb 05, 2013 7:14 pm

After all the other comments I am wondering something..
sqrt3 wrote:I'm using a 74HC595 to switch some relays......The OE-Pin of the 74HC595 is pulled up via a 4.7k resistor to prevent output while switching on and booting.
Random thought are you sure it is 74HC595? As the 74*594 is almost identical but instead of it having an OE (Output Enable) It has a RCLR (Register Clear) which will clear the output register to zeros.
The whole setup works very well so far. But if i switch on or off a completely independent power supply or my laser printer starts printing the 74HC595 seems to loose its latch register contents. Almost always most or all bits go to zero. If i connect the power supply to another outlet in the wall (in a different circuit) everything is fine.
In most cases I would consider the 4k7 adequate pull up, but would be intereseted in the full circuit diagram around the 74*595. There is something weird about this setup and have used 594 and 595 in many applications, and not experienced this sort of issue on stripboard/schmartboard or PCB layouts. In one case the devices are on one of 7 different power rails in the small system, whilst the input signals are on a different power rail driver. Let alone the multiple ground planes I had to contend with.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: 74HC595 EMC(EMV) problems

Tue Feb 05, 2013 7:19 pm

sqrt3 wrote:
I would recommend a strong pullup to Vcc.
I always connected /MR to VCC directly. Concerning the cables. They're breadboard like which means of course nothing twisted. I'll give that a try.
Unless you get a glitch on the shift register clear during an actual serial load it should not make a difference.

Trouble is you could have glitches on the Register clock, clocking in random data

Personally I would like scope traces when this other kit starts of all input signals and one during a serial load sequence.

Also you coiuld have an intermittent breadboard connection.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

pgman
Posts: 22
Joined: Sun Jan 06, 2013 8:34 pm

Re: 74HC595 EMC(EMV) problems

Tue Feb 05, 2013 10:47 pm

I'm working on a similar project on the Arduino. In my case switching 16 relays (2 8way boards from China, with opto-isolation). I used 2 * 74HC595 with shared clock and data lines and one enable line per chip, plus a 3rd chip for a LCD display. Everything worked fine until I made contact with the relay boards or relay contacts, and then each chip randomly loaded a new pattern.

I tried tying the lines to 0v, isolating the relay coil power from the processor power, but nothing cured it. As the boards are to be connected to mains lights this was a non-starter. It seems that if you get noise on clk, data and enable pins at the same time, then the ouputs will be set at random. Eliminating noise from simple stripboard is quite a difficult thing to do.

So I've done away with 74HC595 and instead gone for PCF8574 I2C to parallel chips. These only need 2 lines to drive them, and you can have 8 of each chip each bus. They are really stable, and they will only change their outputs when exactly the right signal is sent to them. Plus you can also use them for input or even mixed (some pins input, some output). Cost is about £1.60 each in the UK, but can be bought from china at 5 for £3. So they are about 3 times the cost of the 595 chips, but if you only need 2 or 3, its not a massive increase.

I cant say if coding for I2C is easy on the Pi, as on the Arduino its all done with libraries, but I have implemented an I2C clock on the Pi, and there are some good tools available for playing with the I2C busses.

sqrt3
Posts: 9
Joined: Thu Jan 17, 2013 2:52 pm

Re: 74HC595 EMC(EMV) problems

Wed Feb 06, 2013 10:35 am

I used the following circuits:
Circuit.png
Circuit.png (49.64 KiB) Viewed 6103 times
and also tried to introduce an ULN2003A between Raspberry and shift register, like this:
The attachment Circuit2.png is no longer available
I'd like to emphasize that both circuits work like expected, that's not the problem. But switching on a special power supply or printing with the laser printer in the same room changes the contents of the shift registers (being in a steady state not while shifting).
Attachments
Circuit2.png
Circuit2.png (59.17 KiB) Viewed 6103 times

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: 74HC595 EMC(EMV) problems

Wed Feb 06, 2013 11:17 am

Well nothing obvious there. Question is the 74HC595 driven by 5V from Pi or external 5V?
It was not obvious from your diagram.

I would power it from Pi 5V, to reduce noise on rail problems.

Also you can use SPI to drive these chips which could be easier on software and timing

Pi CE to STCP
PI SCLK to SHCP
Pi MOSI to DS

SPI mode in standard terms CLK PHASE 0, CLK POLARITY 0
Clock idles low, first edge clocks data into 74HC595
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: 74HC595 EMC(EMV) problems

Wed Feb 06, 2013 1:57 pm

I would place a 1K pulldown resistor to ground on STCP, DS, SHCP, and a 1K pullup resistor (to 3.3v) on /OE. This provides some additional noise immunity and gives a known level if the Raspberry Pi GPIO's are set as inputs.

Enjoy!
Bill

karman
Posts: 1
Joined: Wed Sep 25, 2013 7:20 am

Re: 74HC595 EMC(EMV) problems

Wed Sep 25, 2013 7:35 am

Hi,
I had exact same issue when I was turning on 3 x 240v florescent lights on my home automation system. (propeller chip as controller ==> 74hc595 ==> uln2003a ==> 12v relay's . I even run the Relays and Controller of separate battery's to make sure no EMF is getting in via power supplies but exact same issue. I tried snubbers on relay's etc etc etc etc. Nothing worked, I even dropped the SPI speed to 1hz (damn slow) to make sure no its not interference on SPI. I could not resolve the issue..

My eventual solution was to go with shop bought fully isolated RS485 I/O device. :ugeek:

Hope you find the issue as I'm busy developing new circuit that will controller pumps and heaters and not in mood to sit with this issue again :mrgreen:

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: 74HC595 EMC(EMV) problems

Wed Sep 25, 2013 9:20 am

One thing that has not been discussed here so far, is connecting the RaspPi GND to Earth. Almost all power supplies are isolated.

User avatar
Tage
Posts: 287
Joined: Fri May 24, 2013 2:29 am
Location: St Thomas, Ontario Canada

Re: 74HC595 EMC(EMV) problems

Wed Sep 25, 2013 1:08 pm

Have you tried to replace the CMOS circuit? I have seen occasions where there is damage to the IC or the power connection is broken, but the part still appears to be working - most of the time - as it receives power from one of the signal pins.

bandaangosta
Posts: 3
Joined: Tue Jun 14, 2016 4:57 pm

Re: 74HC595 EMC(EMV) problems

Sat Jul 06, 2019 8:23 am

For anyone coming with the same problem, I fixed it with a RC filter at RCLCK input (100 ohms, 100 nf). Based on https://hstech.ro/HC595/.
Saved my life!
Twitter: @bandaangosta

Return to “Interfacing (DSI, CSI, I2C, etc.)”