Program BS2 and more then three 74HC595's
KKDZ28
Posts: 10
I have a project I want to use many serial shift registers. I see the info in stamp works but Im getting confused one how to chain more then two together. Im still trying to learn the syntax of the coding. I have been trying to look at example code to see how its set. Can not find code that has more then 2 74HC595's. I want to use about 5 or 6 on one project and many many more on another. I cant get past doing two right now. The project I want to do for now to learn the basics is just a 32-64 LED sweep in one direction. I figured it would be easy and I would learn the code and how it works to move to bigger projects. I want to run about 5 chains of 32-64 LEDs in each chain. Im missing something and getting frustrated with myself. Can anyone help me out? How do I program more then two 595's? I have three hooked up now but the 3rd just does what the 1st one is doing. Im wiring the 3rd just like the 2nd one is off the 1st. I know Im missing something easy but I just need someone to bring it to light for me. How do I tell it I have that many 595's in the chain? How do you tell it about the other chains? Take 3 more pins and set clock2, SerData2 and latch2? Sorry for so many question but this as got me frustrated. I have serached the Forums and online but can not find the answers or example code to try to figure it out.
Thanks
Thanks
Comments
The reason why you see only two together, is the Basic Stamp can only do Word size variables. You, need to look at the Basic Stamp Editor help file for SHIFTOUT command it will tell you what size the variable can be.
You also need to get the data sheet for this shift register and it should show you how to connect more then two together.
I will do some research on this as well, because I have seen it somewhere and suggest you to do the same thing.
www.picaxeforum.co.uk/showthread.php?t=9116
You can attach more than two 74HC595s to a BS2. You just keep adding more on the end of the chain, just like the 2nd one. The SHIFTOUT statement can handle multiple variables, one for each 1 or 2 74HC595s. You can also have multiple chains of them. Now the caveats:
1) As the chains get longer, it takes more time to load them up. The Stamp Manual gives the approximate clock frequency used.
2) As you get much beyond 8 or 10 74HC595s in a chain, you may need buffering of the clock and load signals.
3) Each chain requires at least 3 I/O pins (data, clock, load). The reset and output enable signals are often not used and tied to Vdd or Vss as appropriate. There are only 16 I/O pins.
4) Remember that the Stamps have only 26 bytes of variables. You need somehow / somewhere to keep the data you're going to send out to the 74HC595s. You could compute it on-the-fly a byte at a time or read it in from some kind of external storage, but that does slow things down even further.
I know Im missing a lot but any help you can give to help would be great. Samples help me a lot to see how it works. I have over 60 of the 595 waiting to go into this project. Please help.
Quick video too.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Program Description ]
'
[ I/O Definitions ]
Clock PIN 0 ' shift clock (74HC595.11)
SerData PIN 1 ' serial data (74HC595.14)
Latch PIN 2 ' output latch (74HC595.12)
'
[ Constants ]
DelayTime CON 50
'
[ Variables ]
patt VAR Word
cycle VAR Nib
'
[ Initialization ]
Reset:
LOW Latch ' make output and low
'
[ Program Code ]
Main:
FOR cycle = 0 TO 5
GOSUB Chase:
NEXT
PAUSE DelayTime ' hold
GOTO Main
Chase:
patt = 1
DO
GOSUB Star ' put pattern on 74x595
PAUSE DelayTime ' hold
patt = patt << 1 ' shift pattern left
LOOP UNTIL (patt = 32768)
RETURN
'
[ Subroutines ]
Star:
SHIFTOUT SerData, Clock, mSBFIRST, [patt] ' send pattern to 595-1
SHIFTOUT SerData, Clock, MSBFIRST, [patt] ' send pattern to 595-2
SHIFTOUT SerData, Clock, MSBFIRST, [patt] ' send pattern to 595-3
PULSOUT Latch, 5 ' latch outputs
RETURN
This should get you going in the right direction
(Not having subscript as a 'button' just totally sux for me.)
Code was this:
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Program Description ]
'
[ I/O Definitions ]
Clock PIN 0 ' shift clock (74HC595.11) for LEDS 1 - 16
SerData PIN 1 ' serial data (74HC595.14) for LEDS 1 - 16
Latch PIN 2 ' output latch (74HC595.12) for LEDS 1 - 16
Clock1 PIN 3 ' shift clock (74HC595.11) for LEDS 17 - 32
SerData1 PIN 4 ' serial data (74HC595.14) for LEDS 17 - 32
Latch1 PIN 5 ' output latch (74HC595.12) for LEDS 17 - 32
Clock2 PIN 6 ' shift clock (74HC595.11) for LEDS 33 - 48
SerData2 PIN 7 ' serial data (74HC595.14) for LEDS 33 - 48
Latch2 PIN 8 ' output latch (74HC595.12) for LEDS 33 - 48
'
[ Constants ]
DelayTime CON 75
'
[ Variables ]
patt VAR Word
'
[ Initialization ]
Reset:
LOW Latch ' make output and low
LOW Latch1
LOW Latch2
'
[ Program Code ]
Main:
GOSUB Chase
GOSUB Chase1
GOSUB Chase2
PAUSE DelayTime ' hold
GOTO Main
Chase:
patt = 1
DO
patt = patt << 1 ' shift pattern left
GOSUB Star ' put pattern on 74x595
PAUSE DelayTime ' hold
LOOP UNTIL (patt = 16)
RETURN
Chase1:
patt = 1
DO
patt = patt << 1 ' shift pattern left
GOSUB Star1 ' put pattern on 74x595
PAUSE DelayTime ' hold
LOOP UNTIL (patt = 16)
RETURN
Chase2:
patt = 1
DO
patt = patt << 1 ' shift pattern left
GOSUB Star2 ' put pattern on 74x595
PAUSE DelayTime ' hold
LOOP UNTIL (patt = 16)
RETURN
'
[ Subroutines ]
Star:
SHIFTOUT SerData, Clock, MSBFIRST, [patt] ' send pattern to 595-1
PULSOUT Latch, 5 ' latch outputs for LEDS 1 - 16
Star1:
SHIFTOUT SerData1, Clock1, MSBFIRST, [patt] ' send pattern to 595-2
PULSOUT Latch1, 5 ' latch outputs for LEDS 17 - 32
Star2:
SHIFTOUT SerData2, Clock2, MSBFIRST, [patt] ' send pattern to 595-3
PULSOUT Latch2, 5 ' latch outputs for LEDS 33 - 48
RETURN
Any more code ideas?
This is from the Basic Stamp Editor Help file gives you idea about the SHIFTOUT command.
This what PJ Allen was talking about and it is done on one line.
Im stuck on the syntax of how to get it to transfer to each 74HC595 to chase one LED down the full length of LEDs. It could be 24 for one and maybe 48-64 for another one or even more. I cant get it over 16 right now. In my 1st video the 16 will chase but the 3rd 74HC595 mirrors the 1st one.
Can anyone show me the code for doing this many? Stampworks said I can chain dozens of 74HC595's to just 3 I/O pins. Yeah, I can but just cant figure how to trace one LED at a time down them all.
Baby is coming soon so I dont have much time left. Any help would be great on the code.
Thanks for the time you guys have given to help me so far.
I think StampWorks should have stayed with Bytes in the example, instead of going the \16 route, but you're black-boxing the PBASIC.
Well, I took a different tack from StampWorks's. I wrote modules to emphasize concepts, no shortcuts.
Do you see, programming-wise, what's going on?
PE - added pic
Stink-a-roo!!
Below is video and code.
Here's the code I wrote for it back in 2005 -
I tried with breaking into two different lines too. 595a-1, 595a-2 and 595b-1, 595b-2. Both work independent taking 3 pins each set. Now I can start building my boards with more 595's!
Thank you very much PJ Allen for the info. I think I will have some more questions later for everyone but you cleared up many things for me.
Doggiedoc thanks for that info as well. That will help for my 2nd stage of the project.
Thanks Mr Green and BSNut. Its nice to see code from other people.
Wealth of knowledge on this forum. This programming peon knows .0001% of it now, maybe less.
OH, how are you embedding code in those windows like that? So much clearer on the forum.
Thanks
Kris
You have to wrap the code in the code tags [noparse] [/noparse].
Can you post a schematic (just to double check it is ok) and post the latest code?
addit - 'tis ok with the delayed postings. I see things have been rather cold in your domicile.