JPrograms
Posts: 76
Joined: Wed Mar 30, 2016 7:42 pm

Using a shift registe

Wed Aug 09, 2017 2:38 pm

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!

User avatar
Burngate
Posts: 4863
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
Contact: Website

Re: Using a shift registe

Wed Aug 09, 2017 6:05 pm

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 https://www.onsemi.com/pub/Collateral/MC74HC595-D.PDF

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.

JPrograms
Posts: 76
Joined: Wed Mar 30, 2016 7:42 pm

Re: Using a shift registe

Wed Aug 09, 2017 6:22 pm

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 :)

User avatar
Burngate
Posts: 4863
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
Contact: Website

Re: Using a shift registe

Thu Aug 10, 2017 10:29 am

That looks correct.

Regarding edge triggering, I can do no better than pointing to https://electronics.stackexchange.com/q ... 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
edge.png (9.26 KiB) Viewed 112 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.

Return to “Python”

Who is online

Users browsing this forum: No registered users and 18 guests