Pages: [1]   Go Down
Author Topic: Cascading 74hc164  (Read 801 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to control 25 Led's for a 5*5*5 led cube. Using cascaded 74hc164
I have attached the schematic that I am following.

The main question would be on how to control each individual LED on the software part.  I know how to address the first 8 LED's but for the remaining I have no idea. If anyone knows how to, please let me know. Thanks.


* schema circuito definitivo_Vcc.jpg (1085.75 KB, 3092x3400 - viewed 117 times.)
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maintain a buffer for individual shift registers. Update the byte(s) for the ones you want to change and then resend the whole buffer.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I see how I would work with a buffer.

But what I still don't understand, is how can more LED's will be controlled with only one byte of data.
I'm basing my work of this code I found:
Code:
#define data 2
#define clock 3

// use binary notation to discribe our number layouts
byte zero  = B01111110;
byte one   = B00000110;
byte two   = B11011010;
byte three = B11010110;
byte four  = B10100110;
byte five  = B11110100;
byte six   = B11111100;
byte seven = B01000110;
byte eight = B11111110;
byte nine  = B11110110;

void setup()
{
  pinMode(clock, OUTPUT); // make the clock pin an output
  pinMode(data , OUTPUT); // make the data pin an output3
}

void loop()
{
    shiftOut(data, clock, LSBFIRST, zero);
    delay(500);
    shiftOut(data, clock, LSBFIRST, one);
    delay(500);
    shiftOut(data, clock, LSBFIRST, two);
    delay(500);
    shiftOut(data, clock, LSBFIRST, three);
    delay(500);
    shiftOut(data, clock, LSBFIRST, four);
    delay(500);
    shiftOut(data, clock, LSBFIRST, five);
    delay(500);
    shiftOut(data, clock, LSBFIRST, six);
    delay(500);
    shiftOut(data, clock, LSBFIRST, seven);
    delay(500);
    shiftOut(data, clock, LSBFIRST, eight);
    delay(500);
    shiftOut(data, clock, LSBFIRST, nine);
    delay(500);
}

As you can see, it addresses each LED (segment), encoded in the bits of the byte. i.e "byte three = B11010110;"
But since I want to control more that 8 bits, would I be able to send two bytes to the 74hc164?

Thanks
Logged

More Cowbell
Offline Offline
Edison Member
*
Karma: 11
Posts: 1028
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I see two shift registers, one that is one package and one that is eight packages (effectively this is a 64-bit shift register).  Both are controlled by 3 lines - data, clock, and clear.  The 8 bit shift register is controlling NPN transistors so that is the low side.  Obviously the 64-bit shift register is the high side.  So this can control an 8x64 array of LEDs at a 1/8 duty cycle.  Probably they are arranged such that there are 8 rows and 64 columns and one of the 8 rows is turned on by that single shift register at any given time with a 1 in the appropriate bit and zeros in the others.  Zero to 64 LEDs on that row are illuminated by putting a 1 into the corresponding bit on the x8 shift register.  It doesn't look like the most appropriate setup for a 5x5x5 cube but I bet it could be made to work.

Your code is sending 80 bits of information out to the 72 bits of shift registers that you actually have.  It doesn't seem to be set up either for a 5x5x5 cube or the 8x64 setup this schematic is implying.  Are you mixing and (mis)matching some sample code and sample schematics to your idea?  They are not an exact match but the general architecture can be made to work.

How about 4 8 bit shift registers which gives you 32 bits to work with, use only 25 of them to address the high side of 25 LEDs for each layer on your cube.  Drive that with 3 pins.  Use 5 pins to select NPN transistors as the low side, one for each layer, select one layer at a time and drive it with a 1/5 duty cycle?  That will work for you.
Logged

Vexatious Sampler

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, I am using 4 8 bit shift registers. The schematic I posted was only an example I found that I was using to wire the 4 shift registers that I am using. And yes, I am working with 32bits
My plan is to drive the high side with only three pins. (clock, clear serial).

The code I posted works with only 8 bits, and since I am a little programming impaired, I am having a hard time figuring out control the 25 individual LED's with 32bits, using 4 cascaded 74hc164's.

Thanks
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Something like this would work:

Code:
#define SRBUFFER_SIZE 8 //sr buffer size

unsigned char srBuffer[SRBUFFER_SIZE]; //sr buffer

void sr_send(unsigned char size, unsigned char *buffer) {
  unsigned char index=0;
  while (index<size) shiftOut(data, clock, LSBFIRST, buffer[index++]);
}

...
  //update your buffer here
  //send the buffer
  sr_send(SRBUFFER_SIZE, srBuffer);
...

Each revocation of sr_send will send the whole buffer.
Logged

More Cowbell
Offline Offline
Edison Member
*
Karma: 11
Posts: 1028
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, I am using 4 8 bit shift registers. The schematic I posted was only an example I found that I was using to wire the 4 shift registers that I am using. And yes, I am working with 32bits
My plan is to drive the high side with only three pins. (clock, clear serial).

The code I posted works with only 8 bits, and since I am a little programming impaired, I am having a hard time figuring out control the 25 individual LED's with 32bits, using 4 cascaded 74hc164's.

Thanks

Yeah, with 32 bits at your disposal you can connect 5 to the NPN transistors and use the other 25 as the top side drivers, leaving 2 unused.  Better idea.

So, if you send 4 bytes at your registers using shiftout, then that is all they need to be able to drive your setup.  For example, to light all the pins on layer 1 you might send this:

bit 31 ........................................... bit 0
xx111111 11111111 11111111 11100001

The idea being that bits 0-4 are connected to the NPN transistors which control your layers.  They are the common cathodes of all LEDs on that layer so each is connected to 25 LEDs.   All are off except bit 0 which is 1 and enables on your first layer by connecting it to ground.  Bits 5-29 are the common anodes of your LED "columns".  Each is connected to 5 LEDs.  Putting a bit 1 on a column enables it by connecting it to +V.  When a column in a layer is connected both ways, it illuminates (put resistors on the columns!)  Bits 30 and 31 do not matter and can go either way.

So, I am terrible and I would probably bitbang this instead of using shiftout.  But my understanding of shiftout is you send the bytes FF, FF, FF, and then C1 and it would have this effect.   I am choosing to represent the Xs as 1s.
  
To illuminate all 25 LEDs on the second layer using this scheme it would be FF FF FF C2, third layer FF FF FF C4, fourth layer FF FF FF C8, fifth layer FF FF FF D0.

To do this dynamically and pick and choose which columns you want to illuminate, you will have to use bitwise arithmetic to pick and choose the bits within those bytes to send.  You will have to do some reading on this subject.   This is a good start:

http://playground.arduino.cc/Code/BitMath

Also, remember to refresh the layers at about 100Hz, so 500 times per second through the cube.  This is easy to achieve.
« Last Edit: December 20, 2012, 09:22:50 pm by JoeN » Logged

Vexatious Sampler

Pages: [1]   Go Up
Jump to: