need help with a shift register

dsvilko

Senior Member
Hi!
I am trying (and failing) to make my first shift register (74hc595) work. I've used a circuit on this page to connect it to my 20X2:
http://www.arduino.cc/en/Tutorial/ShiftOut
I think I've correctly connected it:
RCK to C.0 (clock)
RSCK to C.1 (latch)
SER to C.2 (data)
QA,QB and QC are connected to LEDs through 470 ohm resistors.
E is connected to ground and SRCLR (clear) to +5V.
Here is the code I am using:

Code:
output dataPin
output latchPin
output clockPin
setfreq m8

main:
	for b0=0 to 255
		low latchPin
		pause 10
		shiftout clockPin,dataPin,5,(b0)
		high latchPin
		pause 1000
	next b0
	pause 1000
	goto main
What am I doing wrong?
 

inglewoodpete

Senior Member
Things that come to mind:
-Do you have clock and data input lines reversed?
-By clocking more than 8 bits into the shift register, does q7' (the overflow output) start to toggle?
 

dsvilko

Senior Member
Things that come to mind:
-Do you have clock and data input lines reversed?
-By clocking more than 8 bits into the shift register, does q7' (the overflow output) start to toggle?
I have just checked and I don't think I have the pins reversed. Everything seems to be connected correctly. If I put two 8-bit shiftouts before the high latchPin and connect the led to QH', I can't see any blinking at all.
All I get is a short blink from QB immediately after turning the supply power on (before it enters the for loop). After that, nothing.

Am I using the shiftout command correctly? Am I supposed to use it to 'fill' the shift register?
 

westaust55

Moderator
Unless you are looking for inverted data at the 74HC595 outputs, I suggest that you might use 1 instead of 5 for the mode parameter.

Then try placing the line “low latchpin” before the line “For b0 . . . “

And instead of the line “high latchpin” use
pulsout latchpin, 100 ; = 50us pulse at 8MHz to latch data


Might also ask why not look/search on the PICAXE forum :) here as opposed to an Arduino :eek: website for information.
there are plenty of schematics, code and circuit layouts here as examples.

It can also make life easier for some (well maybe me at least :rolleyes:)
if you upload your schematic diagram and maybe even a photo of the circuit.
Membebs here have often found a problem by looking at a photo of the circuit provided it is clear and shows each wire end clearly.


EDIT:
You have the lines:
output dataPin
output latchPin
output clockPin​
what are your exact assignments (SYMBOL commands) to define which pin is for the clock, data and latch?
 
Last edited:

dsvilko

Senior Member
@westaust55
I have tried making the suggested changes but unfortunately with no effect.
This is the current code:
Code:
symbol dataPin =  C.2
symbol clockPin = C.1
symbol latchPin = C.0

output dataPin
output latchPin
output clockPin
setfreq m4

pause 1000
main:
	low latchPin
	for b0=0 to 255
		shiftout clockPin,dataPin,1,(b0)
		pulsout latchPin, 100
		pause 100
	next b0
	pause 1000
	goto main
Here is the relevant part of the circuit:
 

moxhamj

New Member
See my post two above. Comparing with your diagram, I think the hardware is all ok. So in these situations, I find the next thing to do is to put leds on each of those 3 lines, and write code that you can step through line by line. The shiftout ought to work but it isn't (or maybe it is but we don't know) so have a look at the code in that link, especially post #7 where hippy simplified it greatly. It ought to be possible to change the pin allocations for your chip, then put pause statements in so you can see each clock and data pulse go through say once per second.
 

westaust55

Moderator
Change the pin assignments as follows:

symbol dataPin = C.2
symbol clockPin = C.0 ; was C.1
symbol latchPin = C1 ; was C.0
 

westaust55

Moderator
By way of some extra explanation,

The RSClk is the clock pin to step the data through the front end shift registers
(RSClk = Shift Register CLock)

The RClk is the register clock pin that is used to shift the data from the front end shift register into the latch which drives the outputs. Data trsnsfers on a low to high state.
 

dsvilko

Senior Member
By way of some extra explanation,

The RSClk is the clock pin to step the data through the front end shift registers
(RSClk = Shift Register CLock)
Thanks westaust55! Didn't spot that. Still doesn't work, though. I have modified my code not to use the shiftout command:

Code:
symbol setdataPin = pinC.2

HC595out:
	low latchPin
	low clockPin
	for b2=0 to 7
		setdataPin=bit0
		pause 500
		pulsout clockPin,500
		pause 500
		b0=b0/2
	next b2
	pulsout latchPin,500
	pause 1000
	return
I have also put a separate set of 3 LEDs to the 20X2 pins and I believe they are blinking exactly as they should. The LED on SD input is lit/not lit depending on the bit value, the LED on SRCK blinks (normally off) for each bit and after 8 bits RCK LED blinks (normally off). The QX remain at or near 0V.
Are the rest of my 595 pins connected correctly?
 

inglewoodpete

Senior Member
Thanks westaust55! Didn't spot that. Still doesn't work, though. I have modified my code not to use the shiftout command:

Code:
symbol setdataPin = pinC.2

HC595out:
	low latchPin
	low clockPin
	for b2=0 to 7
		setdataPin=bit0
		pause 500
		pulsout clockPin,500
		pause 500
		b0=b0/2
	next b2
	pulsout latchPin,500
	pause 1000
	return
I have also put a separate set of 3 LEDs to the 20X2 pins and I believe they are blinking exactly as they should. The LED on SD input is lit/not lit depending on the bit value, the LED on SRCK blinks (normally off) for each bit and after 8 bits RCK LED blinks (normally off). The QX remain at or near 0V.
Are the rest of my 595 pins connected correctly?
Forgive me for asking the following questions, but many beginners have overlooked what more experienced members take for granted.

Is that all of your code or are you initialising b0 somewhere else? For your example to work, you need to initialise to something like b0=$55 before you enter the loop. If b0 is not initialised with a value, it will output all zeroes.

Are the 3 PICAXE outputs pulsing when the programme is running?

Finally, I presume you have the 22k + 10k minimum operating circuit connected to the PICAXE when you're trying to run it?

Peter
 

westaust55

Moderator
help with a shift register - cut and paste from working example

Cannot spot any further problems with "the relevant part" of your circuit.

While you are only using one 74HC595, have a look at this thread I posted a while back. It includes schematics, proto-board layouts and program code to use either 3 or 5 output signals to control the 74HC595’s
http://www.picaxeforum.co.uk/showthread.php?t=13687

You will, as you have already done, need to modify the assignment for the 20X2 pins you are using but if you cut and paste the working bit-bashed SHIFTOUT code as a starting point it may overcome some illusive bug.
 

dsvilko

Senior Member
Thank you all for your suggestions! I am constantly amazed at how many helpful people there are on this forum! Still don't know why my circuit doesn't work but there could be a number of reasons that would not be apparent from my circuit schematics or program code. It could be that I have managed to destroy the 595 while experimenting (don't know how but it's possible and don't have a spare). My breadboard is also very low-quality and maybe some contacts are not as good as they should be... I'll try to debug further on my own.
PS: On the same breadboard I also have a working 6-wire LCD interface connected to the same 20x2 (works perfectly) so I do have some experience at making picaxes work. I have also made a remote-power-adjust-thingy for my flash (08M-based). I am still a complete beginner, though, so wouldn't rule out some stupid beginners mistake. All suggestions are welcome, I certainly won't be offended :)
 

moxhamj

New Member
Getting married?

Congratulations!

Hmm - you might not have a huge amount of time spare for picaxe tomorrow. Who knows, take it along anyway, it might come in handy if the speeches get a bit boring.

Looking at the photo, you have the earth at the bottom and 5V at the top. But there also seems to be an earth rail at the very top - that goes to leds and the common of the resistor array. But I can't see that rail connected to earth anywhere. Three yellow leds, a jumper to join the gap and to the ressitor array.
 
Last edited:

westaust55

Moderator
again, congratulations on your wedding tomorrow.

In looking at the photos, the PICAXE 20X2 to 74HC595 signals are now correct.

Agree with Dr_A that lack of an earth wire seems to be a major issue.
But then you also say a couple of posts back that:
I have also put a separate set of 3 LEDs to the 20X2 pins and I believe they are blinking exactly as they should. The LED on SD input is lit/not lit depending on the bit value, the LED on SRCK blinks (normally off) for each bit and after 8 bits RCK LED blinks (normally off). The QX remain at or near 0V.
Are the rest of my 595 pins connected correctly?
Those being the yellow LEDs.

That suggests a feedback for 0V for the three yellow LED's but I cannot see how/where.

You might need something to take you mind off pre-wedding jitters in the morning so . . .
try a wire from the common side of all those LED's across to the 0V line on the other side of the breadboard.

Also, looking again at the RED LED's the one furtherest from the '595 is the other way to your schematic - the flat edge is towards the '595 outputs. If the resistor common goes to 0V then that LED will never illuminate
 

moxhamj

New Member
westy might be on to something there. Zooming in on the red leds, if one is indeed round the other way, that could be the reverse current path for the unconnected earth. Out one red led, round the earth (unconnected), in through a yellow led. Or vice versa.

Usually the bride is fashionably late. That is 5 or 10 minutes of time that could be used productively to debug a picaxe circuit.
 

dsvilko

Senior Member
It's a very small wedding so not (that) much to do :)
Of course the upper pathway is connected to earth (there is a wire beneath a battery). The yellow leds are happily blinking away, as ordered. The red leds (to be precise just the leds 1,2 and 4) momentarily turn on when the power supply is connected (before and data is sent to the register). The 4th led was put in the wrong way around (well spotted!) just for this photosession (was correctly connected while testing, double checked). That leaves a burned 595 or maybe faulty breadboard (wires go in far too easily in some spots).
Anyway, thanks for your help! Will probably continue with the debugging sometime next week.
 

westaust55

Moderator
@dsvilko,
out of curiosity, where did you get or how did you create those IC labels.
They look much clearer and more data available than my efforts.
 
Top