NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Basic Electronics » Daisy chaining MC74MC595 Shift Registers
August 14, 2011 by Ralphxyz |
I am needing to use 32 bit patterns for my Water Curtain. Or at least at the moment I am thinking that I need to use 32 bit patterns. But for now I am just trying to use 2 shift registers to light 16 leds. Anyway I finally was able to decipher my notes to get the pinout and using code based on Rick's Shift Register code I have a single Shift Register working passing in 8bit binary patterns. I "think" I have the pinout correct but lets start there. Anyone have a drawing or schematic of the mcu and multiple shift registers? Here are my single shift register pinout notes:
So you see I am using PB2, PB3 and PB5. The problem I am having is that with 16 leds:
Turns on led1 as expected but:
Turns on led 1 & 2 but also led 9 Here is the code I am using:
I "think" the problem probable has something to do with how I set the SPI ReadWrite function.
Thanks, Ralph |
---|---|
August 15, 2011 by Ralphxyz |
Well Paul (Noter) posted a excellant photo of 4 MC74HC595's daisy chained so I can use that to confirm the pinout. I have tried his simplified code with two shift registers, but only led 1 and 9 light (flickering). So I'll take it apart again, which I need to do anyway as I need to setup 4 shift registers like Paul has. I sure hope I can make mine look as good as his does. Once I have this operating I'll post it to the Library so there is a consolidated reference, but first I have to get it to work. Ralph |
August 15, 2011 by Rick_S |
Ralph, I'm at work and can't really verify this, but isn't SPDR an 8 bit register. I think if you want to used SPI to send to more than one 8 bit shift register, you'd need to split your 16 bits into an upper 8 and lower 8. It may be easier to do by just bit banging it. Look at my New LED Array project code for those displays we were all grabbing. I have code there for bit-banging the shift registers on those boards and there are 8 of them for a total of 40 bits. Rick |
August 15, 2011 by Ralphxyz |
Thanks Rick that would make sense, but I thought it was passing 8 bits at a time. Bit Banging we will go!! I set up a new breadboard with the full 32 leds (4 shift registers) to simulate my water curtain. I was hoping it was as Noter suggested in another thread a wiring error. But I guess not. Here is Paul's code from the other thread that I am also trying I believe he was using 4 shift registers.
Ralph |
August 16, 2011 by Ralphxyz |
Anybody have a clever scheme to break up a 32 bit number into it's 8bit components? If I were using strings I can see how to do it but storing 0b0001111111111111111111111110000 as a 32bit number takes up less space than storing it as a string. But breaking it up into:
Does it take more space to store a 32 bit number or 4 8bit numbers? I think I just need to change my thinking, if I use the 4 8bit numbers then I do not have to worry about breaking down the 32bit number into it's 8 bit components which might not be as efficient in storage does simplify my processing. Like Rick said the SPDR register is 8 bit so I might just as well leave everything 8 bit and not even think about the 32 bit number. It is just easier to associate the 32bit number with the pattern being generated for the Water Curtain. Now to see why I cannot get either code set to work! Ralph |
August 16, 2011 by bretm |
You can get at the four constituent bytes of a long by using a union of a long and a 4-byte array. A union is basically just like a struct except all the fields share the same memory. This thread shows a union called conver_ which shows how to do this. |
August 16, 2011 by Ralphxyz |
So what takes up more space a 32bit number or 4 8bit numbers? I'm wondering if I should take the time to process a 32 bit pattern breaking it down into it's 8bit components (thanks bretm, for that link the discussion is a"bit" over my head but I "think" I understood the 32bit number processing). This might happen 50 or more times a second. Eventually I am going to have a PlayList of all of the patterns I want to display for a session. The patterns will be stored in EEPROM or might come from a pc using UART or a serial communications. So dealing with the pattern coming from EEPROM first. I can store a 32bit number or store four 8bit numbers. There is a certain overhead no matter which method I use. I am favoring using the 4 8bit numbers unless someone can point out a simpler method or a compelling reason to use the 32bit method. Thanks for the help, I just got Noters 4 shift register code to run. So I have the daisy chain working!! Ralph |
August 18, 2011 by carlhako |
Hi Ralphxyz I have recently pulled out a couple of my 74HC595's for a new project I am starting for Christmas. I played around with the simulator here http://conductiveresistance.com/interactive-595-shift-register-simulator/ and worked out my own bit banging code that actually works. Currently I have 2 chained together controlling 16 leds but I will be chaining 30 of them together. Anyway I was just posting the simulator as it really helped me out. |
August 18, 2011 by Rick_S |
Why don't you set up an array like the NK guys did for the LED-Array project. That way, you create your code for the shift registers does nothing but output array data to the "display" while your other code manipulates the array as if it were a display. That seems to work quite well. Did you take a look at the code I had working with the 4 x 40 display? Rick |
August 18, 2011 by Ralphxyz |
carlhako, thanks that is a nice simulator I wish I had found it before I pulled my hair out, it might have helped. Now in looking at the simulator I just see the spec sheet, which I have had to read a lot of times. Rick, your 4 x 40 code was way over my head. As far as programing the 595, Noters code is absolutely the simplest I have found. Most of the code examples I found were either for an Arduino or just plain didn't work. I have a new thread about coming up with a schema to incorporate the I2C EEPROM with the Shift Registers to build my Water Curtain display. Ralph |
August 18, 2011 by Rick_S |
Ralph, I had hoped the code wouldn't be that hard to follow. I tried to comment it as best I could. Hopefully you'll get it working with Noter's code. Rick |
August 18, 2011 by carlhako |
Hi Ralyhxyz When i open the simulator I see a picture of the chip and on the left are some buttons you can click to pulse those buttons and toggle the SER line. Here is my code for something else to take a look at.
And here is a simple bit of code that simulates 2 leds (a snow flake) falling down the 16 leds. This is pretty much all i had in my main while loop.
|
August 18, 2011 by Ralphxyz |
Hi carlhako, thanks for the sample code. Yeah Rick your code is nicely commented, I just have so many things going on I easily confuse myself. I got Pauls' (Noter) code running. He had really simplified it. Paul's code is easy (so far) to be modify to pass in variable or array elements in place of the hardcoded 8bit numbers. So far bretm has given me a detail comment on my new Schema thread. I need to look at the Nerdkit's LED-Array project again to see how the display was handled. I sure appreciate any comments or suggestions. Ralph |
Please log in to post a reply.
Did you know that binary numbers use base 2 to represent numbers, and these are important for understanding microcontroller registers? Learn more...
|