Shift Register and Relays?

Using a 74hc595 shift register to a ULN2003 darlington array to control 7 relays, all controlled by an MSP430, connected via RJ11.  The relays are controlling LED Christmas light strings on and off.  Everything seems to be functioning so far but the problem is that relays that aren't being told to turn on sometimes are turning on.  The shift register is connceted with Qa to the master reset of the register so I can clear is quickly, but so far I have been just leaving it high.the other 7 outputs (Qb - Qh) connected to the base pins of the ULN2003 (B1 - B7).  The outputs of the ULN2003 connected to the relay coils, COM connected to 5v, emitter connected to ground.  I have tried pull down resistors on the base pins, I have tried tweaking the code which I tried to set up to just bit bang the shift register, make it as simple as possible just to test it and a sample is provided below for one iteration.  I have it looping through several of these to turn a single channel on each time to check to make sure all the channels work.  It however sometime make a channel just flicker, not turn on at all, or turns several channels on at the same time.  I am curious as to whether this is a hardware problem (pullup/down resistors, filtering caps, more clamping diodes then what is built into the ULN2003, whatever) or whether I am just an incompetent programmer.  I am fairly certain the problem lies somewhere between the driver seat and the steering wheel though.  One thought I had but do not want to try right away is it possible the shift register is bad?  Overheated from soldering?  I try to solder one pin on chips, then a pin on another component, then a pin on the opposite side of the chip, etc to keep chips cool when soldering them, but are the 74hc595 very heat sensitive maybe?  Would appreciate a fast answer, looking to build 5 more of these so I can control all my Christmas lights.

This was supposed to be a cheap and dirty project so I didn't get into Triacs and dimming, I just want to turn lights on and off as I see fit.

  i = 30000;
  P1OUT = 0x00;        //Channel 7 (unused)
  P1OUT |= 0x02;       //Clock in
  P1OUT &=~ 0x02;   //Clock low
  P1OUT = 0x01;        //Channel 6 (Green Wreath)
  P1OUT |= 0x02;       //Clock in
  P1OUT &=~ 0x02;   //Clock low
  P1OUT = 0x00;        //Channel 5 (Red Icicle)
  P1OUT |= 0x02;       //Clock in
  P1OUT &=~ 0x02;   //Clock low
  P1OUT = 0x00;        //Channel 4 (White North)
  P1OUT |= 0x02;       //Clock in
  P1OUT &=~ 0x02;   //Clock low
  P1OUT = 0x00;        //Channel 3 (White South)
  P1OUT |= 0x02;       //Clock in
  P1OUT &=~ 0x02;   //Clock low
  P1OUT = 0x00;        //Channel 2 (Blue North)
  P1OUT |= 0x02;       //Clock in
  P1OUT &=~ 0x02;   //Clock low
  P1OUT = 0x00;        //Channel 1 (Blue South)
  P1OUT |= 0x02;       //Clock in
  P1OUT &=~ 0x02;   //Clock low
  P1OUT = 0x01;        //Channel 0 (Clear All/Active Low)
  P1OUT |= 0x02;       //Clock in
  P1OUT &=~ 0x02;   //Clock low
  P1OUT |= 0x04;       //Latch outputs
  P1OUT &=~ 0x04;   //Latch low
  while(i > 0)
  {
        i--;
  }

sort by: active | newest | oldest
steveastrouk9 months ago

Try buffering the signals to your RJ11 with some proper line drivers.

Put big reservoir caps near each 595, and a 100nf ceramic across it. Its likely that voltage drops from the LEDs switching is introducing noise.

Run separate power grounds from your signal ground.

Try adding some delays. The 595 can be clocked statically, so don't worry about how long you wait.

Wesley666 (author)  steveastrouk9 months ago

0.1uF across latch pin to ground. Problem solved, after several frustrating hours! Haha! -_-

Now worry why it worked....

Wesley666 (author)  steveastrouk9 months ago

Never had a problem before with shift register latch bouncing, but since I have never used them with relays, I assumed the inductive nature of the coils was causing it? I only tried it out of curiosity, because I saw several posts in the Google search that said NOT to put a cap there, but the Arduino forum said to. Not really entirely sure what the division was on why to or not to use a cap there.

A lot depends on your layout. If you have big loops from the relay to the diodes on the ULN 2003, it will radiate crap all over the place. Insufficient bypass caps too. What you have done is slugged the latch line. If you weren't bit banging, then it would probably stop the SPI bus working properly.

Wesley666 (author)  steveastrouk9 months ago

Yeah, there are bigger loops to the relays, because of the layout, wanted good separation from mains. But its good for learning! Haha!

very good