Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more than 4 registers (hw spi) #1

Open
mcer12 opened this issue Jan 21, 2020 · 4 comments
Open

Use more than 4 registers (hw spi) #1

mcer12 opened this issue Jan 21, 2020 · 4 comments
Assignees
Labels

Comments

@mcer12
Copy link

mcer12 commented Jan 21, 2020

Hi, @maxint-rd is there a reason that it's limited to just 4 registers? Any way to use more than 4? There are alternative libraries for 74HC595 but none of them utilizes HW SPI. Thanks in advance!

@maxint-rd
Copy link
Owner

Hi @mcer12,

Thanks for trying out my library.
The main reasons for this limitation are execution speed, memory usage, ease of implementation and expected use in projects.

To store the state of the added pins the library uses a 32-bit variable, which is fairly easy to handle when using bit-operations for setting and sending pins.
As each added shift register requires more bits to be shifted out, handling of digitalWrite() and shiftOut() calls will be slower.

I figured that adding 32 pins to a pin-limited MCU using four shift-registers would be sufficient for most cases. What is your use case? What is the project you have in mind? How many additional registers would you like to use in your project? BTW. What MCU are you using?

If you want to use multiple strings of shift-registers you could experiment with sharing the SPI MOSI/SCLK pins and having one SS (latch) pin per string. This would entail instantiating multiple
mxUnified74HC595 objects, using -1 for both MOSI and SCLK and a different SS pin for each string.
In my TM16xx library I've used that technique to minimize pins when combining LED-matrices. I haven't done such experiments with shift-registers though.
At the moment I don't have much spare time to do such experiments. If you do, please go ahead and let me know if you got it working.

@mcer12
Copy link
Author

mcer12 commented Jan 21, 2020

Thanks for the reply! 74HC595 are great for multiplexing and for more moderate resolution you could utilize many registers, I use ESP8266 + 5 registers to drive small 25x11 pixel led grid. I currently use soft library:
https://github.com/Simsso/ShiftRegister74HC595
which uses shiftOut and it is fast enough, but when there's something else going on (wifi comms etc) it can stutter a bit. HW SPI should be much faster and better for this. I'm not sure how difficult it would be for you scale this dynamically (32bit bariable for 1-4 registers, 64bit for 5-8 registers etc.). Or maybe you can point me where to start, I can try to implement it myself :)

@maxint-rd
Copy link
Owner

Do I understand correctly that you need 5 registers because you want to drive 25+11=36 lines?
(BTW: As you mention it's for a LED-grid, I'd also like to point you to my TM16xx library. In one of my YouTube video's I showed how I made a 24x16 pixel animated LED clock).

With my library it's probably easiest to first try experimenting with multiple strings. How about using one string with four registers for the columns and one with two for the rows? If that works, it will only require one additional pin for SS of the second string and not require any code changes.

Perhaps I could make a new version with compile-time option to allow 8 registers using a 64-bit variable, but at the moment I don't have much spare time. If you have the time, you can dive in. The essence of the libraries is not very complicated, but they do contain some extra code to support various MCUs and optimize speed. As I made them open source, you're free to use them as you please.

@mcer12
Copy link
Author

mcer12 commented Jan 21, 2020

Yes you're correct, 36 outputs. This project is already finished and in use (pcbs assembled), so any hardware changes are out of question. If you find time that would be great, I will try to take a look at it as well, having support for 8 (or even more) registers will be a huge step up. Either way, thanks for the hints, really appretiate it.

@maxint-rd maxint-rd self-assigned this Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants