Shift Registers - Page 1
Forum section: electronics / beginners

author: SmurfKiller
author_rank: Contributor
timestamp: January 04, 2017, 02:21:55 pm
content: Hi, Is there such a thing as a, for lack of a better word, reverse shift register?I am trying to build an Arcade console based around theI-PAC 2andRetroPiusing standard arcade buttons/joysticks.My problem is i would like to have a sort of head unit containing the I-Pac/RaspberryPi and then 2 controllers with the buttons/joysticks, which will mean i would have to have 15 wires + ground for each controller. which is just nuts.So my idea was to use some sort of "reverse shift register" which will check if a button is pressed as quickly as possible, send it down some sort of serial interface then split it back out again on the other side.which i would think that it would allow me to easy upgrade it to a wireless interface later on down the track.I hope that makes sense, I come from a computer science background, only just starting to get back into electronics well since i was a kid and this project seemed like a good way to get a toes wet.Any tips on how this could be done would be great.Thanks

author: plazma
author_rank: Frequent Contributor
timestamp: January 04, 2017, 02:28:01 pm
content: Build the controls with inexpensive zero delay encoders. Then the cable is USB only.

author: SmurfKiller
author_rank: Contributor
timestamp: January 04, 2017, 02:36:25 pm
content: Quote from: plazma on January 04, 2017, 02:28:01 pmafter doing some googleing, that looks similar to the I-Pac controller, which i don't think will really do the job as they do not allow me to easily modify the controllers to make them wireless.

author: Benta
author_rank: Super Contributor
timestamp: January 04, 2017, 03:04:02 pm
content: Search for SPI or serial peripheral interface, which is a standard feature on most microcontrollers.

author: darrellg
author_rank: Unknown
timestamp: January 04, 2017, 05:45:15 pm
content: Quote from: SmurfKiller on January 04, 2017, 02:21:55 pmYes. It's called a shift register. There is more than one type. The Wikipedia article may shed some light:https://en.wikipedia.org/wiki/Shift_register

author: SmurfKiller
author_rank: Contributor
timestamp: January 04, 2017, 05:57:22 pm
content: Ah Cool!So Parallel-in Serial-out on the controller, Serial-in parallel-out on the consoleI didn't know that shift registers could be used in that way.So i am guessing that i could use a 555 timer to drive the clock line.

author: David Hess
author_rank: Super Contributor
timestamp: January 04, 2017, 06:25:16 pm
content: Look for a shift register with parallel load capability. For serial controlled I/O expansion, the 74165 was commonly used for inputs and the 74164 or 74595 for outputs. The 74595 has a registered output so shifting can occur without disturbing the outputs.

author: SmurfKiller
author_rank: Contributor
timestamp: January 04, 2017, 07:14:32 pm
content: Quote from: David Hess on January 04, 2017, 06:25:16 pmThanks for that, searching on digikey was getting a little overwhelming.

author: Benta
author_rank: Super Contributor
timestamp: January 04, 2017, 09:18:38 pm
content: Intersil had a series of SPI interface ICs, don't know if they are still available.The CDP68HC68P1 was an 8-bit I/O port and will do what you want.http://www.alldatasheet.com/datasheet-pdf/pdf/87734/INTERSIL/CDP68HC68P1E.html

author: Kjelt
author_rank: Super Contributor
timestamp: January 04, 2017, 09:34:16 pm
content: Still you need some protocol: pre-amble, data, checksum ......

author: Benta
author_rank: Super Contributor
timestamp: January 04, 2017, 10:12:07 pm
content: Quote from: Kjelt on January 04, 2017, 09:34:16 pmNot really. SPI is super-simple, it's pure bit-banging in hardware.

author: mariush
author_rank: Super Contributor
timestamp: January 04, 2017, 10:15:31 pm
content: You can replace shift registers with a simple microcontroller ... you could get a PIC32 or something like that with lots of I/O pins.. you could read the state of the buttons a few hundred times a second and send the state through SPI or i2c or you could fake a USB keyboard and send the buttons as a series of key presses ...Some microcontrollers also have interrupt on i/o pin state change which means your code would be able to know right away when a button was pushed and send the data to other device, instead of the regular way where you code would wait for a particular amount of time, read the state of all buttons, send the states and then wait again (for example for 100 updates a second, the code would wait 10ms between each read)A microcontroller would be more expensive (maybe 2-4$) plus you'd need a programmer but it would be a great learning experience

author: pyroesp
author_rank: Regular Contributor
timestamp: January 04, 2017, 10:18:14 pm
content: Why not use a 16 bit GPIO expander like the MCP23017 (SPI) from microchip ?

author: CJay
author_rank: Super Contributor
timestamp: January 04, 2017, 10:35:41 pm
content: Quote from: pyroesp on January 04, 2017, 10:18:14 pmprecisely what I was thinking but the MCP23S017 for SPI, also has Interrupt on change facility IIRC.*additional info*(doesn't read quite how I meant it to, both the I2C and SPI versions of the chip have interrupt on change capability, not just the SPI version but the SPI version is capable of operation up to 10MHz)

author: David Hess
author_rank: Super Contributor
timestamp: January 05, 2017, 02:13:32 am
content: Quote from: CJay on January 04, 2017, 10:35:41 pmIf I was not using the 74164, 74165, and 74595, I would prefer mariush's suggestion of using a cheap microcontroller because of availability even if it took several. I have used PICs for this type of application and I regret that there is not an equally inexpensive ARM option for this.For a cascaded string of 74164, 74165, and 74595 shift registers, the chip select signal can be used to drive both load and latch on alternate edges so only 3 signals are needed and loads and latches happen with a minimum of dispersion which may be necessary in some applications whereas a microcontroller or I/O expander cannot do this.Several smaller expanders may be preferable to one large one to minimize the routing distance of the I/O signal lines. Socketed DIP packages may be preferred where the I/O extenders are exposed to hostile conditions.

author: Kjelt
author_rank: Super Contributor
timestamp: January 05, 2017, 09:46:54 am
content: Quote from: Benta on January 04, 2017, 10:12:07 pmYeah but the software doesn't know which bit is what if there is no start of frame (pre-amble) etc. in your protocol. But I think we are talking about different layers here.I would just use two simple 8 bit micros for this task one for encoding and sending, one for receiving and decoding. If you make it a "one wire" and ground protocol, you can simply replace it later on with any wireless solution even a cheap $2 433MHz Tx and Rx set.

author: David Hess
author_rank: Super Contributor
timestamp: January 05, 2017, 10:35:46 am
content: Quote from: Kjelt on January 05, 2017, 09:46:54 amIf microcontrollers are used on both ends, then an asynchronous interface will allow getting rid of the clock and possibly the chip select signals.

author: Benta
author_rank: Super Contributor
timestamp: January 05, 2017, 01:14:52 pm
content: QuoteSPI is simply:Assert CSSend 8 clock pulses with associated data bits (2 wires).Deassert CSDone, you've transferred a byte.

author: Kjelt
author_rank: Super Contributor
timestamp: January 05, 2017, 02:44:29 pm
content: Quote from: Benta on January 05, 2017, 01:14:52 pmI know what SPI isMy point is your receiving device powers up and receives a byte, which byte was this, which switches or joystick position does it represent? You don't know.It is even worse, there are slave implementations were you can clock all you want, if a transmitting spi device is powered down in the mid of the transmission and powers up and returns transmitting you end up with two nibbles from different bytes. You need a higher level protocol to check if you received the entire message (bytes/packets of data) and if the message was received correctly. Else you have a risk of running out of sync and ending up with loosing the mame game you are playing

author: Benta
author_rank: Super Contributor
timestamp: January 05, 2017, 05:01:08 pm
content: I think you are making a mountain out of a molehill.We are talking simple 74AC/HC type shift registers with a master and a number of slaves. It's not for downloading "Titanic".If your CS signal doesn't work, it's back to the drawing board.Let's leave it there. Cheers.

author: CJay
author_rank: Super Contributor
timestamp: January 05, 2017, 06:29:24 pm
content: Quote from: Benta on January 05, 2017, 05:01:08 pmThere is a tendency to go down a rabbit hole when this sort of discussion happens but my reasoning for suggesting the MCP23x017 was the simple fact that those chips are very well supported on Raspberry Pi (many, many 'extender' boards use either the SPI or I2C version of them) and there are many software libraries and guides which remove the burden of having to develop your own.

author: SmurfKiller
author_rank: Contributor
timestamp: January 16, 2017, 11:22:33 am
content: Thanks for all the useful information, I Have decided to go for a atmega328p-pu with some 74hc165n's and a NRF24L01 module in the controller. Found all the parts really cheep on ebay.I attached the schematic i came up with if anyone wants to look/ criticizeHopefully all the parts will arrive in a week or so, and i can start breadboard it all up and test it.

author: Benta
author_rank: Super Contributor
timestamp: January 16, 2017, 12:58:10 pm
content: Looks good. Remember to connect CLK/INH on the 'HC165s, don't leave them floating.