Pages: [1]   Go Down
Author Topic: SIPO shift registers vs. I/O expanders  (Read 1733 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Jr. Member
**
Karma: 1
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Cheers!
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: August 23, 2011, 09:32:31 am by dc42 » Logged

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.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26521
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

UK
Offline Offline
Jr. Member
**
Karma: 1
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-cool, 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!
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26521
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

UK
Offline Offline
Jr. Member
**
Karma: 1
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26521
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: