Page 1 of 1

Using a shift registe

Posted: Wed Aug 09, 2017 2:38 pm
by JPrograms
Not sure if this is the right place to put this I would like to use a shift register (possibly 74HC595) control some LEDs. I've read multiple tutorials on how to do this, but most are incomplete :( I understand how to wire the LEDs, but am not quite sure how the program works. What I've gathered is that to output a single digit, you set the input pin high or low, then pulse one of the clock pins ( sclk? ) to shift all the bits, and then, after writing all the data pulse another clock pin to write it to the pins.

Is this correct? What clock pins do I use and when?

I would like to program this in Python, using either RPi.GPIO or gpiozero.

Thanks in advance!

Re: Using a shift registe

Posted: Wed Aug 09, 2017 6:05 pm
by Burngate
Shift registers come in many flavours, sipo (serial in parallel out) & piso (parallel in serial out) being the most common.
If you want to use a 74HC595, have a look at its data sheet

74x595 is serial in, so it needs some method of entering the data a bit at a time.
As you say, you put the first bit on the input pin (pin 14) and tell it it's valid by raising the shift clock (pin 11) - that's edge-triggered, so as long as the data is held steady for long enough before and after that edge, it doesn't matter when you take the clock low again.
Then put bit 2 on the input, and raise the shift clock again.

Having clocked in all the bits, you need to do two things.
The 74x595 has a second register between the shift register and the output pins, so you need to transfer the data from the first to the second. That's where the latch clock, pin 11, comes in.
So raise pin 11 and all the data will be transfered to the outputs.
- Unless you haven't enabled the outputs by pulling output enable, pin 13, low.

Re: Using a shift registe

Posted: Wed Aug 09, 2017 6:22 pm
by JPrograms
Could you explain "raising the shift/latch clock"? is that just setting it low and then high again?

So if I want to connect 8 LEDs to the shift register, I could wire it up something like this:

Some GPIO pin connected to input (14)
Some GPIO pin connected to shift clock (11)
Some GPIO connected to output enable (13)
LED connected to each output pin on the register (15, 1-7)

And program it something like this:

Set input (14) to HIGH to transfer a digital 1 to the register, or LOW to transfer a digital 0.
Do this for all 8 bits I want to output, and raise the shift clock (11) after each bit.
Raise the latch clock, which will set all the LEDs to the transferred values.

Is that correct?
Other than raising the clocks I think I understand :)

Re: Using a shift registe

Posted: Thu Aug 10, 2017 10:29 am
by Burngate
That looks correct.

Regarding edge triggering, I can do no better than pointing to ... gered-mean
Edge Triggering: In edge triggering the circuit becomes active at negative or positive edge of the clock signal. For example if the circuit is positive edge triggered, it will take input at exactly the time in which the clock signal goes from low to high.
edge.png (9.26 KiB) Viewed 382 times
In reality, it takes some time for things to happen, so in this example, the input has to be held constant for some nanoseconds before and after the rising edge of the clock signal.
Also, the clock needs to be low for some nanoseconds before the edge and high for some nanoseconds after it.
According to the table on page 6 of the OnSemi data sheet, those times are around 20 ns if you're powering it from 5v; if you insist on using only 2v those times could be as long as 75ns.
But you're unlikely to be able to make your Pi drive the signals faster than the chip can handle them.