Go Down

Topic: Triple Shift Register question (Read 2 times) previous topic - next topic

Jim_Socks

Hello again everyone!

Quick question-

Is it possible to send info across three shift registers using only one "shiftout"?  It's not is it?

I have LEDs currently connected to each output on the 74HC595s for a total of 24 lights, and I need to light only single lights at a time, on command.  Currently, if I wanted to light only the 5th LED in the middle register I am doing something like this:

Code: [Select]

digitalWrite(latch, 0);
  shiftOut(data, clock, MSBFIRST, 0);
  shiftOut(data, clock, MSBFIRST, 16);
  shiftOut(data, clock, MSBFIRST, 0);
  digitalWrite(latch, 1);


and I suppose what I am hoping for is a solution more like this:

Code: [Select]

digitalWrite(latch, 0);
  shiftOut(data, clock, MSBFIRST, 0, 16, 0);
  digitalWrite(latch, 1);


Would it maybe work if I used an array?  So possibly...

Code: [Select]

byte shiftarray[] = {0, 16, 0};

for (byte i = 0, i < 3, i++) {

  digitalWrite(latch, 0);
  shiftOut(data, clock, MSBFIRST, shiftarray[i]);
  digitalWrite(latch, 1);

}



Quite honestly, I have only just begun to grasp arrays, so maybe I am way off base.  Thanks in advance for any help you are able to provide!

As a side note, a few of you have been helping me tremendously along my journey and I just wanted to let you all know I am making lots of progress with the BarBot!  I now have all of my pumps and check valves- and I already have had it take an order over wifi from the iPad, and pour precise amounts of liquid!  Granted, it was colored water and not actual booze yet...  but it works anyways!  I picked up some transistor arrays too (so cool they make these!  I was planning on having to individually diode/resistor/transistor each one separately... )  And I picked up a big jug of Ferric Chloride to etch my own PCB when the time comes- that sounds fun! (I'm sure it will take a bit of practice though lol)

I gotta hit the sack for now, but I'll check back in the morning!  Thanks Guys!

Nick Gammon

I think I need a BarBot!

Anyway, the nature of shift registers is that you basically have to update the lot.

http://gammon.com.au/forum/?id=11518

It only takes 3 x SPI.transfer to reload three shift registers, and they execute very quickly, so I wouldn't get too worried.

UKHeliBob

How about making your code into a function like this
Code: [Select]
void shiftThree(int reg1, int reg2, int reg3)
{
  digitalWrite(latch, 0);
  shiftOut(data, clock, MSBFIRST, 0);
  shiftOut(data, clock, MSBFIRST, 16);
  shiftOut(data, clock, MSBFIRST, 0);
  digitalWrite(latch, 1);
}

Then you could call it like this
Code: [Select]
shift3(0,16,0);
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

dhenry

Quote
BarBot


BarBot!

Just what you need at the SuperBowl party.

CrossRoads

If you have the shift registers daisy chained, then you need to update all three at once.
If you give each one its own latch line, you can address each one individually.

I have daisychained 20 of them with SPI transfers and sent the data out to them from an array. Very fast.
I have also used 4 MAX7219 for a scrolling message board, a 32 column panel of data. Each column there requires 2 SPI tranfers, address first and then data. So 64 SPI transfers to update the whole thing.  I was updating the entire display every 40mS while scrolling, made for good readability.

So 3 daisy chained is very quick, as Nick pointed out.
shiftout is a low slower, since the software has to create every clock pulse. The ATmega has dedicated hardware for SPI.
Make sure you have a 0.1uF cap from shift register Vcc pin to Gnd.
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.

Go Up