Pages: [1] 2   Go Down
Author Topic: Too many shift registers?  (Read 781 times)
0 Members and 1 Guest are viewing this topic.
Illinois, US
Offline Offline
Jr. Member
**
Karma: 2
Posts: 97
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello again everybody!

I have 6 74HC595 Shift Registers daisy chained...  Is that too many?  It seems to be acting screwy.  By "screwy" I mean it is not lighting the LEDs I would expect, when I would expect it to do so.  Perhaps I am missing something code-wise?  I have tested and verified the chips and connections individually, and all is well.  Additionally, when the arduino 1st loads I have noticed that the intended LEDs flicker for a split second, then never come on again.  OR after a reset the intended LEDs will come on if they are in registers 4, 5, or 6- but then they just stay on ignoring the ender(); function altogether.

Here is my debug code, to try to figure out what is going on:

Quote

const int data = 6;           
const int clock = 7;
const int latch = 8;
const int outputenable = 5; 
const int masterreset = 4;
const byte shiftoutarray[] = {0, 1, 2, 4, 8, 16, 32, 64, 128};  // NOTE: I only want to light one LED from any given register at a time, which is why these bytes are like this
const int ON = HIGH;
const int OFF = LOW


void setup()  {
 pinMode(data, OUTPUT);  //begin shift register pinmodes
  pinMode(clock, OUTPUT);
  pinMode(latch, OUTPUT);
  pinMode(outputenable, OUTPUT);
  pinMode(masterreset, OUTPUT);
  Serial.begin(9600);

 digitalWrite(masterreset, 0);
  digitalWrite(outputenable, 1);
delay(20);

  digitalWrite(masterreset, 1);
  digitalWrite(outputenable, 0);
  digitalWrite(latch, 0);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]); 
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]); 
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  digitalWrite(latch, 1);
  digitalWrite(outputenable, 1);
  
  delay(20); 
  digitalWrite(outputenable, 0);  // All of this was just to make sure the registers are clear at startup
  
}

void loop()  {
  
  light();
  delay(5000);
  
  ender();
  delay(1000);
  
}



void light()
{
      digitalWrite(latch, 0);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[1]); //This should light the 1st LED in my 3rd register
  shiftOut(data, clock, MSBFIRST, shiftoutarray[4]); //This should light the 4th LED in my 2nd register
  shiftOut(data, clock, MSBFIRST, shiftoutarray[5]); //This should light the 5th LED in my 1st register
      digitalWrite(latch, 1);
             Serial.println("should be lit");

}
  
  void ender()
{
      digitalWrite(latch, 0);  // This should turn off all lights on all registers... it doesn't for some reason- they just stay on...
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
  shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
      digitalWrite(latch, 1);
            Serial.println("should be off");


}
 


Any insight you can provide would be greatly appreciated!
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Tell us about what decoupling capacitors you are using and where they are installed. smiley

Tip: use code tags, not quote tags. (Don't use the "copy for forum" feature in the IDE).

Also for digitalWrite, the arguments should be LOW and HIGH, not 0 or 1 (although they are the same at present).
Logged

Illinois, US
Offline Offline
Jr. Member
**
Karma: 2
Posts: 97
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have decoupling caps installed just before each registers incoming voltage, (0.1uF)

As for the "copy for forum" business, I'll make sure I do it the other way from now on.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 439
Posts: 23748
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have daisy chained 20, 6 should not be a problem.
Lack of decoupling caps on the Vcc pins would be a problem.

Code looks okay to me. Don't think I'd bother with flopping outputenable around, just make it low & leave it there.

Show us the schematic you are wiring to - maybe there is some error there.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Illinois, US
Offline Offline
Jr. Member
**
Karma: 2
Posts: 97
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I mess around with output enable because in my main project, should power loss occur this will help to keep my liquor pumps from arbitrarily spewing liquor when power returns.  I just snagged this code section from the main project, and my arduino is still wired for the main project, so since I have a pull-up resistor on it I at least have to control it or it won't let anything out.

As far as the wiring...  I don't have a diagram, it would take too long to create.  What I have done is make sure all the registers work properly.  I have went over their wiring 5 times now just to be extra sure they are wired up correctly.  When I was daisy-chaining 3 of them it worked like a charm, but as soon as I added 3 more it's miss-behaving.

If I send out six bytes of 0XFF it lights up the furthest FIVE registers, but not the 1st one (closest in the chain to the arduino) Which makes no sense to me either- six bytes should hit all six registers!  Even stranger still, if I send EIGHT bytes out, then all six registers light all of their LEDs to include register #1 (the one closest to the arduino)

Why would eight bytes be required to light up six registers?  Should I put a slight delay between ShiftOut commands you think, so it can keep up or something?
Logged

Illinois, US
Offline Offline
Jr. Member
**
Karma: 2
Posts: 97
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also, as noted above, I have decoupling 0.1uF capacitors plugged in just before each registers Vcc in.  The caps are bridging Vcc and Gnd.

Here are a few pic of the full setup- it's difficult to see exactly what my wiring is doing in a picture, but I think the BarBot is getting pretty awesome!

The LEDs on the far left are standing in for three transistor array chips.  I had to remove the chips once I discovered the shift registers acting funny- I put the LEDs in for ease of troubleshooting for now.  The LEDs you see on the far right are RGB LEDs- they will be for effect lighting in the finished project.  The switches will sit in the glass holsters to let the BarBot know if a glass is in place.  That way it won't just pour booze on the counter  smiley-eek  In addition, if there is more than one shot glass present it will turn the wheel to the next present glass and repeat the recipe- up to five shots at a time!







Here is a close up shot so you can see (kinda) where I have my decoupling caps.  The green leads (or in the case of register #1 and #3, yellow) right next to the caps are going to the chip's Vcc line.



And here is a mock-up of the wheel!
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16518
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Assume pictures. Here is a helpful hint, and for free, never and I mean never try and take this on a commercial aircraft flight. smiley-wink

Lefty
Logged

Illinois, US
Offline Offline
Jr. Member
**
Karma: 2
Posts: 97
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ha!  Yeah, that would be a bad idea.
Logged

Illinois, US
Offline Offline
Jr. Member
**
Karma: 2
Posts: 97
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Proof that when passed

Code:
      digitalWrite(latch, 0);
  shiftOut(data, clock, MSBFIRST, 255);
  shiftOut(data, clock, MSBFIRST, 255);
  shiftOut(data, clock, MSBFIRST, 255);
  shiftOut(data, clock, MSBFIRST, 255);
  shiftOut(data, clock, MSBFIRST, 255);
  shiftOut(data, clock, MSBFIRST, 255);
      digitalWrite(latch, 1);

All registers WILL work, but as stated before, not as expected. For example- this code WILL light all the register's LEDs, but not at first...  it first lights the last five registers, then a minute later the first will light up.  Also, if I then pass it

Code:
digitalWrite(latch, 0);  // This should turn off all lights on all registers... it doesn't for some reason- they just stay on...
  shiftOut(data, clock, MSBFIRST, 0);
  shiftOut(data, clock, MSBFIRST, 0);
  shiftOut(data, clock, MSBFIRST, 0);
  shiftOut(data, clock, MSBFIRST, 0);
  shiftOut(data, clock, MSBFIRST, 0);
  shiftOut(data, clock, MSBFIRST, 0);
      digitalWrite(latch, 1);

they won't turn off... they just stay on.  OR if I try to just turn on ONE LED somewhere- no dice.  It's weird, I'll see the correct one flicker for a split second right after loading the code, and again if I open the serial monitor, but thats it.  Sometimes if I reset the arduino then the correct single LED will light, but once again it will not respond to shiftOut commands designed to shut it off again. 

It's frustrating because with only 3 shift registers I had this thing running perfectly, and now I can't figure out whats wrong. 

Anyways, here is the proof that the shift register WILL light everything up when passed the code above- so they ARE wired correctly enough to address all their outputs at least...

Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 439
Posts: 23748
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Since you're not showing a schematic, and the code looks ok, I would suggest moving the decoupling caps closer - like the hole right next to the vcc pin in the same row, not way off to the side where you have them now.
Look at this board - I daisy chained two of them with 20 shift registers (open drain TPIC6B595 vs 74HC595) total and it worked perfectly.
And it uses much higher speed SPI.transfer commands.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

UK
Offline Offline
God Member
*****
Karma: 17
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Long, unshielded, leads everywhere. Let's see if we can pick-up/generate as much Noise/RFI as we can. ;-) hint hint.
« Last Edit: February 10, 2013, 05:42:23 am by tack » Logged

0
Offline Offline
Shannon Member
****
Karma: 161
Posts: 10438
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For LEDs which are relatively high current loads switched at logic speeds (5ns perhaps) I'd use 0.1uF + 10uF per chip,
and 100uF+ for the whole board.

Switching many LEDs simultaneously could be causing a rate-of-change of supply current of the order of 10^8 amps/second,
way beyond what a voltage regulator on a remote board can handle, so in a microsecond or so those 0.1uF capacitors are
drained and the circuit malfunctions - before the voltage regulator has time to adjust to the new load (which might take many
us).

The extra decoupling should hold the supply voltage up for long enough.
Logged

[ I won't respond to messages, use the forum please ]

Illinois, US
Offline Offline
Jr. Member
**
Karma: 2
Posts: 97
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I fixed it.

First I moved the caps much closer to the Vcc pins, and even shortened their leads since I read that is advisable.

That didn't fix it (although I'm sure it's good practice) but while doing it I noticed that when the arduino is reset, when it comes back online it shifts the last bit that it was given out to the registers.

This got me thinking...  the problem must be with my latch!  The fact that it shifts the last bit it had out means that the data and clock pins are doing what they should, but latch sure as hell isn't!

I started my 8th check of my connections, but this time I put special emphasis on checking the signal chain of latch- and I found it.

on the very last (6th) register, output enable was accidentally tied to latch  smiley-small

Apparently it just slipped into the wrong row as they are adjacent, and it can be difficult to see if you are not looking exactly for it.

I re-routed the OE to the row it should be in, and all is well again.  Thank you to all who helped me find it- as by examining my code and telling me it wasn't the issue, and by letting me know that 6 shift registers are NOT too many, you got my mind focusing on the real problem.

I'm back in business!!!
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm glad you got it working. Looking at your original photos, the most obvious problem to me is that each of your decoupling caps has quote a short path to the Vcc pin of the adjacent shift register but a *very* long path to the ground pin of that shift register. My suggestion would have been to add a short wire from each shift register ground pin to the ground side of the adjacent decoupling capacitor.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 439
Posts: 23748
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Woo hoo! User error overcome once again smiley-wink
You'd be surprised how often little things like that are the culprit.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1] 2   Go Up
Jump to: