Help with an 8 bit parallel in/serial out shift register

Thread Starter

w00tberrypie

Joined Jan 18, 2013
3
I am relatively familiar with shift registers and how they operate at a conceptual level but I am stuck on this one and need some more experienced help.

I am running a microcontroller that requires an 8 bit word input but I only have 4 digital i/o pins to work with. I decided on an 8 bit parallel in/serial out shift register, a TI SN74HC165. I have one of the D i/o pins running the parallel load, one clocking the register, and one reading the serial output after each clock. Each of the 8 parallel inputs will be either +3.3V or grounded. No hanging 1's, they goes straight to V+. Low's short straight to ground. If you look up the data sheet for the HC165 there is also a Clock Inhibit that I always have shorted to ground. Serial In on the HC165 is nc.

The problem I have is I can never get the proper output. Sometimes the serial output is always high, sometimes it is always low, and occasionally it is random. I have gotten the proper output twice but given how many tests I've run on the basic circuit, those can be assumed to have been random as well. Testing was done using a simple triple 5 monostable circuit for clocking.

The way I have everything connected is the same as it appears here:
http://blog.aztronics.com/wp-content/uploads/2011/03/Keypad_74HC165.gif

Thanks in advance for any help!
 

crutschow

Joined Mar 14, 2008
34,280
What is the 555 clocking? I though the microcontroller was doing the clocking? :confused:

Post the clock diagram of the clock, the parallel load, and the serial read.
 

ErnieM

Joined Apr 24, 2011
8,377
I think this would actually be easier to debug using the micro, assuming you can single step it thru the load code. Your basic approach looks fine, the devil is in the details.

One devil is you still need to debounce the key inputs... making sure they agree one read to the next is sufficient if you leave a few ms between reads. I use 25 mS for that.
 

takao21203

Joined Apr 28, 2012
3,702
Yes you need to debounce or your data likely will be garbage.

It is not difficult, you can find code for that on my webpage. (pic.hitechworld.org) Some day I should update it to C language. It is just a few lines.
 

tshuck

Joined Oct 18, 2012
3,534
Yes you need to debounce or your data likely will be garbage.

It is not difficult, you can find code for that on my webpage. (pic.hitechworld.org) Some day I should update it to C language. It is just a few lines.
What exactly are we debouncing? The only thing I can think of is adding some hysteresis to the 555 output, though this isn't debouncing...


I'm with crutschow, since you have enough I/O, clock the shift register from the microcontroller...
 

Thread Starter

w00tberrypie

Joined Jan 18, 2013
3
For all intents and purposes, the 555 clock can be ignored. I get the same results whether I'm clocking with the micro or not. Takao, I do assert parallel load before clocking. The sequence of the code in the micro is
-set parallel load to low
-set PL back to high
-read serial output
-clock shift
-read serial output
-...continues until the full word is read.

There is a 5ms delay between each action to give adequate time for propogation. When I'm clocking with the micro I put a scope on the read pin on the micro and get the same garbage results.

I'm on a phone right now but I'll try the debouncing suggestion when I get back to my bench.
 

KrisBlueNZ

Joined Oct 17, 2012
111
There is absolutely no need for a 555 or any kind of monostable. The micro needs to generate a rising edge and a falling edge on the clock. Each complete cycle will clock another bit through the 165.

This circuit is quite standard and there should be no problem with it. I have used it myself in many product designs.

There is also no need for any delay to handle propagation delay in the 165. This is less than a microsecond.

The micro has to drive shift/load and clock, and read the serial output from the 165.
The serial input to the 165 should be tied to something, not left floating. It is an input.

Debouncing, if required, can be done in firmware in the micro if you sample quickly enough.
 

Thread Starter

w00tberrypie

Joined Jan 18, 2013
3
KrisBlue, that was the problem. I was leaving the serial input floating. Pulled out a new IC, connected the serial input to ground and it works perfectly now. And actually now that you brought it up, I saw the appnote on the datasheet that said no inputs can be left floating :rolleyes:

Thanks for everyone's help.
 
Top