Go Down

Topic: SIPO shift registers vs. I/O expanders (Read 2981 times) previous topic - next topic


Hello all,

I'm currently working on a small side project to convert a Namco NeGcon game pad to work with a Playstation 3, and I'm doing that by wiring the NeGcon's buttons to a PS3 pad's board in place of its own. Long story short: without using shift registers there are too many wires coming from the pad (11 without a shift register, 3 with), but with a shift register there's too much latency in the controls for it to be very useful. Currently it goes a little something like:

8 NeGcon buttons > 4021 shift register > Arduino shifts in and shifts straight out > 595 shift register > solid state relays replicate button presses (important because on the PS3 pad board there are three commons and I need to use all three and I couldn't think of another way to split the shift register's output between the commons). The Arduino is also being used to read the wipers of two potentiometers on the NeGcon controller then convert that into a BCD value for three digital potentiometers, which is slowing the shifting process down a bit, but my experience of the 4021 is that it's quite slow anyway.

Would an I/O expander be a faster solution (I'm not sure how, given it would still have to use the 595 to output what the I/O expander reads) or should I look in to getting the shift registers to work independently of the Arduino using a faster clock? I tried to do that before but I just couldn't get it to work, I might try again. Maybe there's an even better solution out there that I just know nothing of, I don't know, but any help would be massively appreciated.

Another post successfully made by neema_t!


Aug 23, 2011, 04:30 pm Last Edit: Aug 23, 2011, 04:32 pm by dc42 Reason: 1
I think you should be able to achieve a low enough latency with your shift register solution, so I suspect that something in your sketch is slowing it down. Can you post the sketch? Also, what SSRs are you using?
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.


Instead of using shift-in/shift-out, try using SPI instead. 8 clock cycles and your data is all transferred, vs faking the hardware transfer in software.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


Sorry, I completely forgot I posted this. There's definitely something in my sketch slowing it down; the fact that it has to shift in (taking 8 clock cycles) then shift back out (taking another 8), and that's after it's run the part of the sketch which reads potentiometer input from two pots and uses the values to set two digital pots, though I think I've worked out how I can avoid that part. I ideally want the 4021 and 595 to communicate directly, i.e. have the byte coming from the 4021 to go straight to the 595 instead of via the Arduino, surely that's doable? Also the SSR's I'm using are... Actually I can't remember right now but I used them in a similar project and there was very little latency with them, so they're not the problem. I can't post the sketch as I'm not home right now, but I know the stuff it's doing before it gets to the shifting process isn't helping.

CrossRoads, when you say use SPI, do you mean an SPI I/O expander or something similar? Is there much difference in speed/coding difficulty between I2C and SPI? As I said, I don't think I need the Arduino before, I'm just using it because I don't know how else to do it. I figured having a high-speed clock (faster than the Uno's, at least) wired to the 4021 and 595's clocks, the data out of the 4021 to the 595 and another, slower clock and maybe a NOT gate to set the latches of the two chips... I don't know, I figured that must be doable, but SPI sounds good. I've only just learnt about it with the digital pots (that I no longer need), I like it, it seems quite straightforward. It does require four wires, though, right? I suppose that's better than just 3 with too much latency or 8 with no latency, though!
Another post successfully made by neema_t!


Yes, SPI is quite fast.
Need a SS line low to latch the 4021, SCLK & MISO to read it. High to release it.
Then another SS line low the 595 for data, SCLK & MOSI to write it, ending wth taking its SS line high.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


Oh I see, I've never even thought of that! I'll try and work that out, the only thing I'm wondering about is if I can concurrently shift out and in at the same time (which is what you're saying, isn't it? I can't see how else I can do it in 8 clock pulses), but I'll work that out on my own, I'm doing this to learn, after all.

Thank you for your help, CrossRoads, that's given me something to think about.
Another post successfully made by neema_t!


SPI uses the same set of clock pulses to shift out or to shift in.

I don't know what the code does if  you command a shift out and the slave shifts out at the same time.
I guess try commanding a write and then reading the input register, see if anything valid is showing up.

Nick Gammon has been doing testing in the "Arduino as SPI slave" thread, try asking some questions over there regarding out & in at the same time.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131